该项目提供了一系列针对神道岛引擎的OpenAPI MCP(模型上下文协议)工具,帮助AI更高效地调用引擎接口。
此工具包提供了以下核心功能:
| 工具名称 | 描述 | 必需参数 |
|---|---|---|
script.saveOrUpdate | 保存或更新神道岛引擎脚本 | mapId, name, type, file |
script.rename | 重命名神道岛引擎脚本 | mapId, name, newName |
| 提示名称 | 描述 | 必需参数 |
|---|---|---|
script.review | 审查神道岛引擎脚本代码,提供改进建议和潜在问题分析 | code |
script.generate | 根据描述和需求生成神道岛引擎脚本代码 | description |
script.optimize | 优化神道岛引擎脚本代码以提高性能或可读性 | code |
| 工具名称 | 描述 | 必需参数 |
|---|---|---|
storage.get | 查询存储空间单个键值 | key, mapId, storageName |
storage.set | 写入/更新存储空间单个键值 | key, mapId, storageName, value |
storage.remove | 删除存储空间单个键值 | key, mapId, storageName |
storage.page | 分页查询存储空间 | mapId, storageName |
| 提示名称 | 描述 | 必需参数 |
|---|---|---|
storage.designSchema | 设计游戏功能所需的数据存储结构 | gameFeatures |
storage.migrationPlan | 设计存储数据迁移计划 | currentSchema, targetSchema |
storage.optimizeQuery | 优化键值对数据查询方案 | queryDescription |
// 上传脚本文件
const scriptResult = await mcpClient.callTool("script.saveOrUpdate", {
mapId: "your-map-id",
name: "example.js",
type: "0", // 0-服务器脚本、1-客户端脚本
file: "console.log('hi')",
token: "your-auth-token",
userAgent: "your-user-agent",
});
// 使用代码审查提示
const codeReview = await m_客户端.prompt("script.review", {
code: "function example() { console.log('Hello'); }",
});
// 生成脚本代码
const generatedCode = await mcpClient.prompt("script.generate", {
description: "实现一个计算玩家得分的系统",
requirements: "支持多种得分方式,保存历史最高分,支持排行榜",
});
// 读取存储值
const storageData = await mcpClient.callTool("storage.get", {
key: "player_stats",
mapId: "your-map-id",
storageName: "gameData",
token: "your-auth-token",
userAgent: "your-user-agent",
});
// 写入存储值
const writeResult = await mcpClient.callTool("storage.set", {
key: "player_stats",
mapId: "your-map-id",
storageName: "gameData",
value: JSON.stringify({ score: 100, level: 5 }),
token: "your-auth-token",
userAgent: "your-user-agent",
});
// 使用数据结构设计提示
const schemaDesign = await mcpClient.prompt("storage.designSchema", {
gameFeatures: "一个RPG游戏,需要存储玩家装备、背包物品、任务进度和成就",
dataRequirements: "支持多人同时在线,支持离线进度保存,支持物品交易历史",
});
import { McpClient } from "@modelcontextprotocol/sdk/client/index.js";
// 初始化客户端
const mcpClient = new McpClient({
serverUrl: "https://your-mcp-server.com",
headers: {
"Content-Type": "application/json",
},
});
// 使用工具
async function useTools() {
const result = await mcpClient.callTool("storage.get", {
// 参数...
});
// 处理结果
console.log(result);
}
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { WebSocketClientTransport } from "@modelcontextprotocol/sdk/client/websocket.js";
// 创建传输通道
const transport = new WebSocketClientTransport({
url: "ws://localhost:3000",
});
// 初始化客户端
const client = new Client(
{ name: "dao3-client", version: "1.0.0" },
{ capabilities: { tools: {} } }
);
// 连接到服务器
await client.connect(transport);
// 使用工具
const result = await client.callTool({
name: "script.list",
arguments: {
mapId: "your-map-id",
token: "your-token",
userAgent: "your-agent",
},
});
所有API调用都需要认证信息,包括:
token:授权令牌userAgent:用户代理字符串这些参数需要在每次调用工具时提供。
如果请求超时,可能是由于:
尝试减少请求数据量或稍后重试。
确保按照文档中指定的类型传递参数,特别是:
欢迎提交问题报告或拉取请求来帮助改进这个项目。
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)