@mastergo/magic-mcp 0.0.4-beta.1 → 0.0.4-beta.11

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 ADDED
@@ -0,0 +1,162 @@
1
+ # MasterGo Magic MCP
2
+
3
+ [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/mastergo-design/mastergo-magic-mcp)
4
+
5
+ MasterGo Magic MCP is a standalone MCP (Model Context Protocol) service designed to connect MasterGo design tools with AI models. It enables AI models to directly retrieve DSL data from MasterGo design files.
6
+
7
+ ## Key Features
8
+
9
+ - Retrieves DSL data from MasterGo design files
10
+ - Runs directly with npx
11
+ - No external dependencies required, only Node.js environment needed
12
+
13
+ ## Tutorial
14
+
15
+ - https://mastergo.com/file/155675508499265?page_id=158:0002
16
+
17
+ ## Usage
18
+
19
+ ### Obtaining MG_MCP_TOKEN
20
+
21
+ 1. Visit https://mastergo.com
22
+ 2. Enter personal settings
23
+ 3. Click the Security Settings tab
24
+ 4. Find the personal access token
25
+ 5. Click to generate the token
26
+
27
+ ### Command Line Options
28
+
29
+ ```
30
+ npx @mastergo/magic-mcp --token=YOUR_TOKEN [--url=API_URL] [--rule=RULE_NAME] [--debug]
31
+ ```
32
+
33
+ #### Parameters:
34
+
35
+ - `--token=YOUR_TOKEN` (required): MasterGo API token for authentication
36
+ - `--url=API_URL` (optional): API base URL, defaults to http://localhost:3000
37
+ - `--rule=RULE_NAME` (optional): Add design rules to apply, can be used multiple times
38
+ - `--debug` (optional): Enable debug mode for detailed error information
39
+
40
+ You can also use space-separated format for parameters:
41
+
42
+ ```
43
+ npx @mastergo/magic-mcp --token YOUR_TOKEN --url API_URL --rule RULE_NAME --debug
44
+ ```
45
+
46
+ ### LINGMA Usage
47
+
48
+ Search for LINGMA in the VSCode extension marketplace and install it.
49
+
50
+ <img src="https://github.com/mastergo-design/mastergo-magic-mcp/blob/main/images/image-20250507174245589.png" alt="image-20250507174245589" style="zoom:25%;" />
51
+
52
+ After logging in, click on [MCP tools] in the chat box.
53
+
54
+ <img src="https://github.com/mastergo-design/mastergo-magic-mcp/blob/main/images/image-20250507174511910.png" alt="image-20250507174511910" style="zoom:25%;" />
55
+
56
+ Click on [MCP Square] at the top to enter the MCP marketplace, find the MasterGo design collaboration tool and install it.
57
+
58
+ <img src="https://github.com/mastergo-design/mastergo-magic-mcp/blob/main/images/image-20250507174840456.png" alt="image-20250507174840456" style="zoom:25%;" />
59
+
60
+ After installation, go back to [MCP Servers], and edit our MCP service to replace it with your own MasterGo token.
61
+
62
+ <img src="https://github.com/mastergo-design/mastergo-magic-mcp/blob/main/images/image-20250507175005364.png" alt="image-20250507175005364" style="zoom:25%;" />
63
+
64
+ Finally, switch the chat mode to agent mode in the chat interface.
65
+
66
+ <img src="https://github.com/mastergo-design/mastergo-magic-mcp/blob/main/images/image-20250507175107044.png" alt="image-20250507175107044" style="zoom:25%;" />
67
+
68
+ ### cursor Usage
69
+
70
+ Cursor Mcp usage guide reference: https://docs.cursor.com/context/model-context-protocol#using-mcp-tools-in-agent
71
+
72
+ ```json
73
+ {
74
+ "mcpServers": {
75
+ "mastergo-magic-mcp": {
76
+ "command": "npx",
77
+ "args": [
78
+ "-y",
79
+ "@mastergo/magic-mcp",
80
+ "--token=<MG_MCP_TOKEN>",
81
+ "--url=https://mastergo.com"
82
+ ],
83
+ "env": {}
84
+ }
85
+ }
86
+ }
87
+ ```
88
+
89
+ ### cline Usage
90
+
91
+ ```json
92
+ {
93
+ "mcpServers": {
94
+ "@master/mastergo-magic-mcp": {
95
+ "command": "npx",
96
+ "args": [
97
+ "-y",
98
+ "@mastergo/magic-mcp",
99
+ "--token=<MG_MCP_TOKEN>",
100
+ "--url=https://mastergo.com"
101
+ ],
102
+ "env": {}
103
+ }
104
+ }
105
+ }
106
+ ```
107
+
108
+ ## Project Structure
109
+
110
+ ### src Directory
111
+
112
+ The `src` directory contains the core implementation of the MasterGo Magic MCP service:
113
+
114
+ - `index.ts`: Entry point of the application that initializes the MCP server and registers all tools
115
+ - `http-util.ts`: Utility for handling HTTP requests to the MasterGo API
116
+ - `types.d.ts`: TypeScript type definitions for the project
117
+
118
+ #### src/tools
119
+
120
+ Contains implementations of MCP tools:
121
+
122
+ - `base-tool.ts`: Base class for all MCP tools
123
+ - `get-dsl.ts`: Tool for retrieving DSL (Domain Specific Language) data from MasterGo design files
124
+ - `get-component-link.ts`: Tool for retrieving component documentation from links
125
+ - `get-meta.ts`: Tool for retrieving metadata information
126
+ - `get-component-workflow.ts`: Tool providing structured component development workflow for Vue and React components, generating workflow files and component specifications
127
+
128
+ #### src/markdown
129
+
130
+ Contains markdown files with additional documentation:
131
+
132
+ - `meta.md`: Documentation about metadata structure and usage
133
+ - `component-workflow.md`: Component development workflow documentation guiding structured component development process
134
+
135
+ ## Local Development
136
+
137
+ 1. Run `yarn` and `yarn build` to install dependencies and build the code
138
+ 2. Find the absolute path of `bin/cli.js`
139
+ 3. Add local MCP configuration with your token
140
+
141
+ ```json
142
+ "mastergo-mcp-local": {
143
+ "command": "node",
144
+ "args": [
145
+ "absolute/path/to/bin/cli.js",
146
+ "--token=mg_xxxxxx",
147
+ "--url=https://mastergo.com",
148
+ "--debug"
149
+ ],
150
+ "env": {}
151
+ },
152
+ ```
153
+
154
+ 4. Restart your editor to ensure the local MCP is enabled
155
+
156
+ After successful execution, you can debug based on the local running results. You can build your own MCP service based on your modifications.
157
+
158
+ We welcome your code contributions and look forward to building MasterGo's MCP service together.
159
+
160
+ ## License
161
+
162
+ ISC
package/README.zh-CN.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # MasterGo Magic MCP
2
2
 
3
+ [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/mastergo-design/mastergo-magic-mcp)
4
+
3
5
  MasterGo Magic MCP 是一个独立的 MCP(Model Context Protocol)服务,旨在连接 MasterGo 设计工具与 AI 模型。它使 AI 模型能够直接从 MasterGo 设计文件中获取 DSL 数据。
4
6
 
5
7
  ## 主要特性
@@ -8,7 +10,7 @@ MasterGo Magic MCP 是一个独立的 MCP(Model Context Protocol)服务,
8
10
  - 可直接通过 npx 运行
9
11
  - 仅需 Node.js 环境,无需其他外部依赖
10
12
 
11
- ### 教程
13
+ ## 教程
12
14
 
13
15
  - https://mastergo.com/file/155675508499265?page_id=158:0002
14
16
 
@@ -22,6 +24,47 @@ MasterGo Magic MCP 是一个独立的 MCP(Model Context Protocol)服务,
22
24
  4. 找到个人访问令牌
23
25
  5. 点击生成令牌
24
26
 
27
+ ### 命令行选项
28
+
29
+ ```
30
+ npx @mastergo/magic-mcp --token=YOUR_TOKEN [--url=API_URL] [--rule=RULE_NAME] [--debug]
31
+ ```
32
+
33
+ #### 参数:
34
+
35
+ - `--token=YOUR_TOKEN` (必需): MasterGo API 认证令牌
36
+ - `--url=API_URL` (可选): API 基础 URL,默认为 http://localhost:3000
37
+ - `--rule=RULE_NAME` (可选): 添加要应用的设计规则,可多次使用
38
+ - `--debug` (可选): 启用调试模式,提供详细错误信息
39
+
40
+ 你也可以使用空格分隔的参数格式:
41
+
42
+ ```
43
+ npx @mastergo/magic-mcp --token YOUR_TOKEN --url API_URL --rule RULE_NAME --debug
44
+ ```
45
+
46
+ ### LINGMA 使用方法
47
+
48
+ 在 vscode 拓展市场中搜索 LINGMA -> 然后安装该拓展
49
+
50
+ <img src="https://github.com/mastergo-design/mastergo-magic-mcp/blob/main/images/image-20250507174245589.png" alt="image-20250507174245589" style="zoom:25%;" />
51
+
52
+ 登录后 -> 在聊天框中点击 [MCP tools]
53
+
54
+ <img src="https://github.com/mastergo-design/mastergo-magic-mcp/blob/main/images/image-20250507174511910.png" alt="image-20250507174511910" style="zoom:25%;" />
55
+
56
+ 点击顶部 [MCP Sqaure] 进入mcp市场,在市场中找到 Mastergo设计协作工具并安装
57
+
58
+ <img src="https://github.com/mastergo-design/mastergo-magic-mcp/blob/main/images/image-20250507174840456.png" alt="image-20250507174840456" style="zoom:25%;" />
59
+
60
+ 安装完成后,需要回到 [MCP Servers], 并编辑我们的mcp服务,将自己的mastergo token 替换上去
61
+
62
+ <img src="https://github.com/mastergo-design/mastergo-magic-mcp/blob/main/images/image-20250507175005364.png" alt="image-20250507175005364" style="zoom:25%;" />
63
+
64
+ 最后在聊天界面中将聊天模式切换为agent模式。
65
+
66
+ <img src="https://github.com/mastergo-design/mastergo-magic-mcp/blob/main/images/image-20250507175107044.png" alt="image-20250507175107044" style="zoom:25%;" />
67
+
25
68
  ### Cursor 使用方法
26
69
 
27
70
  Cursor Mcp 使用指南参考:https://docs.cursor.com/context/model-context-protocol#using-mcp-tools-in-agent
@@ -62,6 +105,58 @@ Cursor Mcp 使用指南参考:https://docs.cursor.com/context/model-context-pr
62
105
  }
63
106
  ```
64
107
 
108
+ ## 项目结构
109
+
110
+ ### src 目录
111
+
112
+ `src` 目录包含 MasterGo Magic MCP 服务的核心实现:
113
+
114
+ - `index.ts`:应用程序入口点,初始化 MCP 服务器并注册所有工具
115
+ - `http-util.ts`:处理与 MasterGo API 通信的 HTTP 请求工具
116
+ - `types.d.ts`:项目的 TypeScript 类型定义
117
+
118
+ #### src/tools
119
+
120
+ 包含 MCP 工具的实现:
121
+
122
+ - `base-tool.ts`:所有 MCP 工具的基类
123
+ - `get-dsl.ts`:从 MasterGo 设计文件中获取 DSL(领域特定语言)数据的工具
124
+ - `get-component-link.ts`:从链接中获取组件文档的工具
125
+ - `get-meta.ts`:获取元数据信息的工具
126
+ - `get-component-workflow.ts`:提供结构化的组件开发工作流工具,支持 Vue 和 React 组件开发,生成所需的工作流文件和组件规范
127
+
128
+ #### src/markdown
129
+
130
+ 包含附加文档的 markdown 文件:
131
+
132
+ - `meta.md`:关于元数据结构和用法的文档
133
+ - `component-workflow.md`:组件开发工作流程文档,指导结构化组件开发过程
134
+
135
+ ## 本地开发
136
+
137
+ 1. 运行 `yarn` 和 `yarn build`,安装依赖并构建代码
138
+ 2. 查看 `bin/cli.js` 的绝对路径
139
+ 3. 在 MCP 配置中添加本地 MCP 配置,其中 token 为您获取的 token
140
+
141
+ ```json
142
+ "mastergo-mcp-local": {
143
+ "command": "node",
144
+ "args": [
145
+ "bin/cli.js绝对路径地址",
146
+ "--token=mg_xxxxxx",
147
+ "--url=https://mastergo.com",
148
+ "--debug"
149
+ ],
150
+ "env": {}
151
+ },
152
+ ```
153
+
154
+ 4. 重启编辑器,确认本地 MCP 已开启
155
+
156
+ 运行成功后,就可以基于本地运行的结果进行调试。您可以基于自己的修改构建自己的 MCP 服务。
157
+
158
+ 欢迎您为我们提供代码贡献,并期待大家一起共建 MasterGo 的 MCP 服务。
159
+
65
160
  ## 许可证
66
161
 
67
- ISC
162
+ ISC
package/bin/cli.js CHANGED
@@ -9,6 +9,8 @@ const args = process.argv.slice(2);
9
9
  let token = "";
10
10
  let baseUrl = "http://localhost:3000";
11
11
  let debug = false;
12
+ // Array to collect rules
13
+ let rules = [];
12
14
 
13
15
  // Parse arguments
14
16
  for (let i = 0; i < args.length; i++) {
@@ -24,14 +26,20 @@ for (let i = 0; i < args.length; i++) {
24
26
  baseUrl = args[i].split("=")[1];
25
27
  } else if (args[i] === "--debug") {
26
28
  debug = true;
29
+ // Add support for --rule parameter
30
+ } else if (args[i] === "--rule" && i + 1 < args.length) {
31
+ rules.push(args[i + 1]);
32
+ i++;
33
+ } else if (args[i].startsWith("--rule=")) {
34
+ rules.push(args[i].split("=")[1]);
27
35
  }
28
36
  }
29
37
 
30
38
  // Check required arguments
31
- if (!token) {
39
+ if (!token && !process.env.MASTERGO_API_TOKEN) {
32
40
  console.error("Error: Missing MasterGo API Token");
33
41
  console.error(
34
- "Usage: npx mastergo-magic-mcp --token=YOUR_TOKEN [--url=API_URL]"
42
+ "Usage: npx mastergo-magic-mcp --token=YOUR_TOKEN [--url=API_URL] [--rule=RULE_NAME]"
35
43
  );
36
44
  console.error("Use --help or -h for more information");
37
45
  process.exit(1);
@@ -39,10 +47,12 @@ if (!token) {
39
47
 
40
48
  // Set environment variables
41
49
  const env = {
42
- ...process.env,
43
50
  MASTERGO_API_TOKEN: token,
51
+ ...process.env,
44
52
  API_BASE_URL: baseUrl,
45
53
  DEBUG: debug ? "true" : "false",
54
+ // Add RULES environment variable as stringified array
55
+ RULES: JSON.stringify(rules),
46
56
  };
47
57
 
48
58
  // Get package path
@@ -51,7 +61,9 @@ const indexPath = path.join(packageDir, "index.js");
51
61
 
52
62
  // Check if file exists
53
63
  if (!fs.existsSync(indexPath)) {
54
- console.error("Error: Executable file not found. Please ensure the package is correctly installed.");
64
+ console.error(
65
+ "Error: Executable file not found. Please ensure the package is correctly installed."
66
+ );
55
67
  process.exit(1);
56
68
  }
57
69
 
@@ -60,6 +72,7 @@ if (debug) {
60
72
  console.log(`Package path: ${indexPath}`);
61
73
  console.log(`Token: ${token ? "set" : "not set"}`);
62
74
  console.log(`API URL: ${baseUrl}`);
75
+ console.log(`Rules: ${rules.length > 0 ? rules.join(", ") : "none"}`);
63
76
  console.log(`Debug mode: ${debug ? "enabled" : "disabled"}`);
64
77
  }
65
78