@mastergo/magic-mcp 0.0.2-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -0
- package/bin/cli.js +129 -0
- package/dist/index.js +44 -0
- package/package.json +61 -0
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# MasterGo Magic MCP
|
|
2
|
+
|
|
3
|
+
MasterGo Magic MCP 是一个独立的 MCP (Model Context Protocol) 服务,用于连接 MasterGo 设计工具与 AI 模型。它允许 AI 模型直接从 MasterGo 设计文件中获取 DSL 数据和生成代码。目前处于 demo 测试阶段,仅支持访问示例文件 [@mastergo.com/file/154777906063854](https://mastergo.com/file/154777906063854?fileOpenFrom=home&page_id=M)。
|
|
4
|
+
|
|
5
|
+
## 功能特点
|
|
6
|
+
|
|
7
|
+
- 获取 MasterGo 设计文件的 DSL 数据
|
|
8
|
+
- 直接 npx 运行
|
|
9
|
+
- 无需安装外部依赖,只需 Node.js 环境
|
|
10
|
+
|
|
11
|
+
## 使用
|
|
12
|
+
|
|
13
|
+
### cursor 使用
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx -y @mastergo/magic-mcp --token=test --url=https://mcp-demo.mastergo.com
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### cline 使用
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"mcpServers": {
|
|
24
|
+
"@master/mastergo-magic-mcp": {
|
|
25
|
+
"command": "npx",
|
|
26
|
+
"args": [
|
|
27
|
+
"-y",
|
|
28
|
+
"@mastergo/magic-mcp",
|
|
29
|
+
"--token=test",
|
|
30
|
+
"--url=https://mcp-demo.mastergo.com"
|
|
31
|
+
],
|
|
32
|
+
"env": {}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## 许可证
|
|
39
|
+
|
|
40
|
+
ISC
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn } = require("child_process");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
|
|
7
|
+
// 获取参数
|
|
8
|
+
const args = process.argv.slice(2);
|
|
9
|
+
let token = "";
|
|
10
|
+
let baseUrl = "http://localhost:3000";
|
|
11
|
+
let defaultFramework = "";
|
|
12
|
+
let showHelp = false;
|
|
13
|
+
let debug = false;
|
|
14
|
+
|
|
15
|
+
// 解析参数
|
|
16
|
+
for (let i = 0; i < args.length; i++) {
|
|
17
|
+
if (args[i] === "--token" && i + 1 < args.length) {
|
|
18
|
+
token = args[i + 1];
|
|
19
|
+
i++;
|
|
20
|
+
} else if (args[i] === "--url" && i + 1 < args.length) {
|
|
21
|
+
baseUrl = args[i + 1];
|
|
22
|
+
i++;
|
|
23
|
+
} else if (args[i] === "--framework" && i + 1 < args.length) {
|
|
24
|
+
defaultFramework = args[i + 1];
|
|
25
|
+
i++;
|
|
26
|
+
} else if (args[i].startsWith("--token=")) {
|
|
27
|
+
token = args[i].split("=")[1];
|
|
28
|
+
} else if (args[i].startsWith("--url=")) {
|
|
29
|
+
baseUrl = args[i].split("=")[1];
|
|
30
|
+
} else if (args[i].startsWith("--framework=")) {
|
|
31
|
+
defaultFramework = args[i].split("=")[1];
|
|
32
|
+
} else if (args[i] === "--help" || args[i] === "-h") {
|
|
33
|
+
showHelp = true;
|
|
34
|
+
} else if (args[i] === "--debug") {
|
|
35
|
+
debug = true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 显示帮助信息
|
|
40
|
+
if (showHelp) {
|
|
41
|
+
console.log("MasterGo Magic MCP - MasterGo 设计工具与 AI 模型的桥梁");
|
|
42
|
+
console.log("");
|
|
43
|
+
console.log("用法: npx mastergo-magic-mcp [选项]");
|
|
44
|
+
console.log("");
|
|
45
|
+
console.log("选项:");
|
|
46
|
+
console.log(" --token, --token=VALUE MasterGo API Token (必需)");
|
|
47
|
+
console.log(
|
|
48
|
+
" --url, --url=VALUE API 服务器 URL (可选,默认为 http://localhost:3000)"
|
|
49
|
+
);
|
|
50
|
+
console.log(" --framework, --framework=VALUE 默认使用的框架 (可选)");
|
|
51
|
+
console.log(" --help, -h 显示帮助信息");
|
|
52
|
+
console.log(" --debug 启用调试模式,显示更多日志");
|
|
53
|
+
console.log("");
|
|
54
|
+
console.log("示例:");
|
|
55
|
+
console.log(" npx mastergo-magic-mcp --token=abc123");
|
|
56
|
+
console.log(
|
|
57
|
+
" npx mastergo-magic-mcp --token=abc123 --url=https://example.com"
|
|
58
|
+
);
|
|
59
|
+
process.exit(0);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 检查必要参数
|
|
63
|
+
if (!token) {
|
|
64
|
+
console.error("错误: 缺少 MasterGo API Token");
|
|
65
|
+
console.error(
|
|
66
|
+
"用法: npx mastergo-magic-mcp --token=YOUR_TOKEN [--url=API_URL] [--framework=FRAMEWORK]"
|
|
67
|
+
);
|
|
68
|
+
console.error("使用 --help 或 -h 查看更多信息");
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 设置环境变量
|
|
73
|
+
const env = {
|
|
74
|
+
...process.env,
|
|
75
|
+
MASTERGO_API_TOKEN: token,
|
|
76
|
+
API_BASE_URL: baseUrl,
|
|
77
|
+
DEFAULT_FRAMEWORK: defaultFramework,
|
|
78
|
+
DEBUG: debug ? "true" : "false",
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// 获取包的路径
|
|
82
|
+
const packageDir = path.resolve(__dirname, "../dist");
|
|
83
|
+
const indexPath = path.join(packageDir, "index.js");
|
|
84
|
+
|
|
85
|
+
// 检查文件是否存在
|
|
86
|
+
if (!fs.existsSync(indexPath)) {
|
|
87
|
+
console.error("错误: 找不到可执行文件。请确保包已正确安装。");
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (debug) {
|
|
92
|
+
console.log("调试信息:");
|
|
93
|
+
console.log(`包路径: ${indexPath}`);
|
|
94
|
+
console.log(`Token: ${token ? "已设置" : "未设置"}`);
|
|
95
|
+
console.log(`API URL: ${baseUrl}`);
|
|
96
|
+
console.log(`默认框架: ${defaultFramework || "未设置"}`);
|
|
97
|
+
console.log(`调试模式: ${debug ? "开启" : "关闭"}`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
// 直接运行编译后的文件
|
|
102
|
+
if (debug) {
|
|
103
|
+
console.log("使用 node 运行编译后的代码...");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// 直接使用 node 运行文件,并传递环境变量
|
|
107
|
+
const child = spawn("node", [indexPath], {
|
|
108
|
+
env: env,
|
|
109
|
+
stdio: "inherit",
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
child.on("error", (error) => {
|
|
113
|
+
console.error("启动错误:", error);
|
|
114
|
+
if (debug) {
|
|
115
|
+
console.error("详细错误信息:", error.stack);
|
|
116
|
+
}
|
|
117
|
+
process.exit(1);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
child.on("exit", (code) => {
|
|
121
|
+
process.exit(code || 0);
|
|
122
|
+
});
|
|
123
|
+
} catch (error) {
|
|
124
|
+
console.error("运行时错误:", error);
|
|
125
|
+
if (debug) {
|
|
126
|
+
console.error("详细错误信息:", error.stack);
|
|
127
|
+
}
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|