Skip to content

Commit 544b2ea

Browse files
authored
feat: --rule args (#5)
1 parent 24f39f6 commit 544b2ea

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

README.zh-CN.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,25 @@ MasterGo Magic MCP 是一个独立的 MCP(Model Context Protocol)服务,
2222
4. 找到个人访问令牌
2323
5. 点击生成令牌
2424

25+
### 命令行选项
26+
27+
```
28+
npx @mastergo/magic-mcp --token=YOUR_TOKEN [--url=API_URL] [--rule=RULE_NAME] [--debug]
29+
```
30+
31+
#### 参数:
32+
33+
- `--token=YOUR_TOKEN` (必需): MasterGo API 认证令牌
34+
- `--url=API_URL` (可选): API 基础 URL,默认为 http://localhost:3000
35+
- `--rule=RULE_NAME` (可选): 添加要应用的设计规则,可多次使用
36+
- `--debug` (可选): 启用调试模式,提供详细错误信息
37+
38+
你也可以使用空格分隔的参数格式:
39+
40+
```
41+
npx @mastergo/magic-mcp --token YOUR_TOKEN --url API_URL --rule RULE_NAME --debug
42+
```
43+
2544
### Cursor 使用方法
2645

2746
Cursor Mcp 使用指南参考:https://docs.cursor.com/context/model-context-protocol#using-mcp-tools-in-agent
@@ -64,4 +83,4 @@ Cursor Mcp 使用指南参考:https://docs.cursor.com/context/model-context-pr
6483

6584
## 许可证
6685

67-
ISC
86+
ISC

bin/cli.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const args = process.argv.slice(2);
99
let token = "";
1010
let baseUrl = "http://localhost:3000";
1111
let debug = false;
12+
// Array to collect rules
13+
let rules = [];
1214

1315
// Parse arguments
1416
for (let i = 0; i < args.length; i++) {
@@ -24,14 +26,20 @@ for (let i = 0; i < args.length; i++) {
2426
baseUrl = args[i].split("=")[1];
2527
} else if (args[i] === "--debug") {
2628
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]);
2735
}
2836
}
2937

3038
// Check required arguments
3139
if (!token) {
3240
console.error("Error: Missing MasterGo API Token");
3341
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]"
3543
);
3644
console.error("Use --help or -h for more information");
3745
process.exit(1);
@@ -43,6 +51,8 @@ const env = {
4351
MASTERGO_API_TOKEN: token,
4452
API_BASE_URL: baseUrl,
4553
DEBUG: debug ? "true" : "false",
54+
// Add RULES environment variable as stringified array
55+
RULES: JSON.stringify(rules),
4656
};
4757

4858
// Get package path
@@ -51,7 +61,9 @@ const indexPath = path.join(packageDir, "index.js");
5161

5262
// Check if file exists
5363
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+
);
5567
process.exit(1);
5668
}
5769

@@ -60,6 +72,7 @@ if (debug) {
6072
console.log(`Package path: ${indexPath}`);
6173
console.log(`Token: ${token ? "set" : "not set"}`);
6274
console.log(`API URL: ${baseUrl}`);
75+
console.log(`Rules: ${rules.length > 0 ? rules.join(", ") : "none"}`);
6376
console.log(`Debug mode: ${debug ? "enabled" : "disabled"}`);
6477
}
6578

readme.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,25 @@ MasterGo Magic MCP is a standalone MCP (Model Context Protocol) service designed
2222
4. Find the personal access token
2323
5. Click to generate the token
2424

25+
### Command Line Options
26+
27+
```
28+
npx @mastergo/magic-mcp --token=YOUR_TOKEN [--url=API_URL] [--rule=RULE_NAME] [--debug]
29+
```
30+
31+
#### Parameters:
32+
33+
- `--token=YOUR_TOKEN` (required): MasterGo API token for authentication
34+
- `--url=API_URL` (optional): API base URL, defaults to http://localhost:3000
35+
- `--rule=RULE_NAME` (optional): Add design rules to apply, can be used multiple times
36+
- `--debug` (optional): Enable debug mode for detailed error information
37+
38+
You can also use space-separated format for parameters:
39+
40+
```
41+
npx @mastergo/magic-mcp --token YOUR_TOKEN --url API_URL --rule RULE_NAME --debug
42+
```
43+
2544
### cursor Usage
2645

2746
Cursor Mcp usage guide reference: https://docs.cursor.com/context/model-context-protocol#using-mcp-tools-in-agent

src/http-util.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export class HttpUtil {
111111
}
112112
\`\`\`
113113
`,
114+
...(JSON.parse(process.env.RULES ?? "[]") as string[]),
114115
],
115116
};
116117
return result;

0 commit comments

Comments
 (0)