@liangshanli/mcp-server-project-standards 2.0.0 → 2.0.2
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/package.json +1 -1
- package/src/server-final.js +87 -10
- package/src/utils/api_debug.js +16 -1
- package/src/utils/api_help.js +169 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liangshanli/mcp-server-project-standards",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "MCP Project Standards server with project info, structure, API standards, development standards, API debugging, login authentication and configuration management tools",
|
|
5
5
|
"main": "bin/cli.js",
|
|
6
6
|
"bin": {
|
package/src/server-final.js
CHANGED
|
@@ -10,6 +10,7 @@ const database_standards = require('./utils/database_standards');
|
|
|
10
10
|
const api_login = require('./utils/api_login');
|
|
11
11
|
const api_debug = require('./utils/api_debug');
|
|
12
12
|
const api_config = require('./utils/api_config');
|
|
13
|
+
const api_help = require('./utils/api_help');
|
|
13
14
|
|
|
14
15
|
// Get configuration from file or environment
|
|
15
16
|
const getConfig = () => {
|
|
@@ -179,6 +180,12 @@ class ProjectStandardsMCPServer {
|
|
|
179
180
|
return result;
|
|
180
181
|
}
|
|
181
182
|
|
|
183
|
+
// API help tool
|
|
184
|
+
async api_help(params) {
|
|
185
|
+
const result = await api_help(params, this.config, saveConfig);
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
|
|
182
189
|
|
|
183
190
|
|
|
184
191
|
|
|
@@ -522,7 +529,7 @@ class ProjectStandardsMCPServer {
|
|
|
522
529
|
// API Login Tool
|
|
523
530
|
tools.push({
|
|
524
531
|
name: 'api_login',
|
|
525
|
-
description: 'API login authentication tool that uses environment variables for login credentials',
|
|
532
|
+
description: 'API login authentication tool that uses environment variables for login credentials. Automatically extracts token from response and updates Authorization headers. Example: Call with optional baseUrl parameter to override default base URL',
|
|
526
533
|
inputSchema: {
|
|
527
534
|
type: 'object',
|
|
528
535
|
properties: {
|
|
@@ -537,43 +544,113 @@ class ProjectStandardsMCPServer {
|
|
|
537
544
|
// API Debug Tool
|
|
538
545
|
tools.push({
|
|
539
546
|
name: 'api_debug',
|
|
540
|
-
description: 'API debugging tool for directly executing API requests',
|
|
547
|
+
description: 'API debugging tool for directly executing API requests with automatic content-type detection and flexible body format support. Examples: GET /api/users with query params, POST /api/login with JSON body {"username":"admin","password":"123456"}, PUT /api/users/123 with form data "name=John&email=john@example.com"',
|
|
541
548
|
inputSchema: {
|
|
542
549
|
type: 'object',
|
|
543
550
|
properties: {
|
|
544
551
|
url: {
|
|
545
552
|
type: 'string',
|
|
546
|
-
description: 'API URL to execute (required)'
|
|
553
|
+
description: 'API URL to execute (required)',
|
|
554
|
+
examples: ['/api/users', 'https://api.example.com/users', '/api/login']
|
|
547
555
|
},
|
|
548
556
|
method: {
|
|
549
557
|
type: 'string',
|
|
550
558
|
enum: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
|
|
551
|
-
description: 'HTTP method (optional, defaults to GET)'
|
|
559
|
+
description: 'HTTP method (optional, defaults to GET)',
|
|
560
|
+
examples: ['GET', 'POST', 'PUT']
|
|
552
561
|
},
|
|
553
562
|
headers: {
|
|
554
563
|
type: 'object',
|
|
555
|
-
description: 'Additional headers for the request (optional)'
|
|
564
|
+
description: 'Additional headers for the request (optional)',
|
|
565
|
+
examples: [
|
|
566
|
+
{'Authorization': 'Bearer token123'},
|
|
567
|
+
{'Content-Type': 'application/json'},
|
|
568
|
+
{'X-API-Key': 'your-api-key'}
|
|
569
|
+
]
|
|
556
570
|
},
|
|
557
571
|
query: {
|
|
558
572
|
type: 'object',
|
|
559
|
-
description: 'Query parameters (optional)'
|
|
573
|
+
description: 'Query parameters (optional)',
|
|
574
|
+
examples: [
|
|
575
|
+
{'page': 1, 'limit': 10},
|
|
576
|
+
{'search': 'keyword', 'sort': 'name'},
|
|
577
|
+
{'id': 123, 'status': 'active'}
|
|
578
|
+
]
|
|
560
579
|
},
|
|
561
580
|
body: {
|
|
562
|
-
description: 'Request body (optional)'
|
|
581
|
+
description: 'Request body (optional) - Supports multiple formats: JSON object, form data, or plain text',
|
|
582
|
+
examples: [
|
|
583
|
+
'JSON Object: {"username": "admin", "password": "123456"}',
|
|
584
|
+
'Form Data: "username=admin&password=123456"',
|
|
585
|
+
'Plain Text: "Hello World"',
|
|
586
|
+
'XML: "<user><name>John</name><email>john@example.com</email></user>"'
|
|
587
|
+
]
|
|
563
588
|
},
|
|
564
589
|
contentType: {
|
|
565
590
|
type: 'string',
|
|
566
|
-
description: 'Content-Type for request body (optional, will auto-detect if not specified)'
|
|
591
|
+
description: 'Content-Type for request body (optional, will auto-detect if not specified)',
|
|
592
|
+
examples: [
|
|
593
|
+
'application/json',
|
|
594
|
+
'application/x-www-form-urlencoded',
|
|
595
|
+
'text/plain',
|
|
596
|
+
'application/xml',
|
|
597
|
+
'text/html'
|
|
598
|
+
]
|
|
567
599
|
}
|
|
568
600
|
},
|
|
569
|
-
required: ['url']
|
|
601
|
+
required: ['url'],
|
|
602
|
+
examples: [
|
|
603
|
+
{
|
|
604
|
+
description: 'Simple GET request',
|
|
605
|
+
url: '/api/users',
|
|
606
|
+
method: 'GET',
|
|
607
|
+
query: {'page': 1, 'limit': 10}
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
description: 'POST request with JSON body',
|
|
611
|
+
url: '/api/login',
|
|
612
|
+
method: 'POST',
|
|
613
|
+
body: {'username': 'admin', 'password': '123456'},
|
|
614
|
+
headers: {'Content-Type': 'application/json'}
|
|
615
|
+
},
|
|
616
|
+
{
|
|
617
|
+
description: 'PUT request with form data',
|
|
618
|
+
url: '/api/users/123',
|
|
619
|
+
method: 'PUT',
|
|
620
|
+
body: 'name=John&email=john@example.com',
|
|
621
|
+
contentType: 'application/x-www-form-urlencoded'
|
|
622
|
+
},
|
|
623
|
+
{
|
|
624
|
+
description: 'POST request with XML body',
|
|
625
|
+
url: '/api/data',
|
|
626
|
+
method: 'POST',
|
|
627
|
+
body: '<data><item>value</item></data>',
|
|
628
|
+
contentType: 'application/xml'
|
|
629
|
+
}
|
|
630
|
+
]
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
// API Help Tool
|
|
635
|
+
tools.push({
|
|
636
|
+
name: 'api_help',
|
|
637
|
+
description: 'API help tool that provides detailed documentation and examples for all API debugging tools. Use this to understand how to use api_debug, api_login, and api_config tools effectively',
|
|
638
|
+
inputSchema: {
|
|
639
|
+
type: 'object',
|
|
640
|
+
properties: {
|
|
641
|
+
tool: {
|
|
642
|
+
type: 'string',
|
|
643
|
+
description: 'Specific tool name to get help for (optional: api_debug, api_login, api_config)',
|
|
644
|
+
examples: ['api_debug', 'api_login', 'api_config']
|
|
645
|
+
}
|
|
646
|
+
}
|
|
570
647
|
}
|
|
571
648
|
});
|
|
572
649
|
|
|
573
650
|
// API Config Tool
|
|
574
651
|
tools.push({
|
|
575
652
|
name: 'api_config',
|
|
576
|
-
description: 'API configuration management tool for managing API settings, endpoints, and configurations',
|
|
653
|
+
description: 'API configuration management tool for managing API settings, endpoints, and configurations. Examples: get config, set baseUrl to "https://api.example.com", updateHeaders with {"Authorization":"Bearer token"}, search APIs by keyword, list all configured APIs',
|
|
577
654
|
inputSchema: {
|
|
578
655
|
type: 'object',
|
|
579
656
|
properties: {
|
package/src/utils/api_debug.js
CHANGED
|
@@ -2,12 +2,27 @@ const { getAllowedMethods, loadApiConfig, saveApiConfig, detectContentType } = r
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* API 调试工具 - 直接执行API请求
|
|
5
|
+
*
|
|
6
|
+
* 支持的请求体格式:
|
|
7
|
+
* 1. JSON对象: {"username": "admin", "password": "123456"}
|
|
8
|
+
* 2. 表单数据: "username=admin&password=123456"
|
|
9
|
+
* 3. 纯文本: "Hello World"
|
|
10
|
+
* 4. XML: "<user><name>John</name><email>john@example.com</email></user>"
|
|
11
|
+
* 5. HTML: "<html><body>Content</body></html>"
|
|
12
|
+
*
|
|
13
|
+
* 自动内容类型检测:
|
|
14
|
+
* - JSON对象 → application/json
|
|
15
|
+
* - 表单数据 → application/x-www-form-urlencoded
|
|
16
|
+
* - XML → application/xml
|
|
17
|
+
* - HTML → text/html
|
|
18
|
+
* - 纯文本 → text/plain
|
|
19
|
+
*
|
|
5
20
|
* @param {Object} params - 参数
|
|
6
21
|
* @param {string} params.url - 要执行的接口URL(必需)
|
|
7
22
|
* @param {string} params.method - HTTP方法(可选,默认GET)
|
|
8
23
|
* @param {Object} params.headers - 额外请求头(可选)
|
|
9
24
|
* @param {Object} params.query - 查询参数(可选)
|
|
10
|
-
* @param {*} params.body -
|
|
25
|
+
* @param {*} params.body - 请求体(可选,支持多种格式)
|
|
11
26
|
* @param {string} params.contentType - 内容类型(可选,会自动检测)
|
|
12
27
|
* @param {Object} config - 服务器配置
|
|
13
28
|
* @param {Function} saveConfig - 保存配置函数
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API 帮助工具 - 返回API调试工具的详细说明和示例
|
|
3
|
+
* @param {Object} params - 参数
|
|
4
|
+
* @param {string} params.tool - 要查看的工具名称(可选,默认返回所有工具)
|
|
5
|
+
* @param {Object} config - 服务器配置
|
|
6
|
+
* @param {Function} saveConfig - 保存配置函数
|
|
7
|
+
* @returns {Object} 工具说明和示例
|
|
8
|
+
*/
|
|
9
|
+
async function api_help(params, config, saveConfig) {
|
|
10
|
+
const { tool } = params || {};
|
|
11
|
+
|
|
12
|
+
const helpContent = {
|
|
13
|
+
api_debug: {
|
|
14
|
+
name: 'api_debug',
|
|
15
|
+
description: 'API调试工具 - 直接执行API请求',
|
|
16
|
+
usage: '直接传入URL和参数即可执行API请求,无需复杂的action参数',
|
|
17
|
+
supportedFormats: [
|
|
18
|
+
'JSON对象: {"username": "admin", "password": "123456"}',
|
|
19
|
+
'表单数据: "username=admin&password=123456"',
|
|
20
|
+
'纯文本: "Hello World"',
|
|
21
|
+
'XML: "<user><name>John</name><email>john@example.com</email></user>"',
|
|
22
|
+
'HTML: "<html><body>Content</body></html>"'
|
|
23
|
+
],
|
|
24
|
+
autoContentTypeDetection: {
|
|
25
|
+
'JSON对象': 'application/json',
|
|
26
|
+
'表单数据': 'application/x-www-form-urlencoded',
|
|
27
|
+
'XML': 'application/xml',
|
|
28
|
+
'HTML': 'text/html',
|
|
29
|
+
'纯文本': 'text/plain'
|
|
30
|
+
},
|
|
31
|
+
examples: [
|
|
32
|
+
{
|
|
33
|
+
description: '简单GET请求',
|
|
34
|
+
request: {
|
|
35
|
+
url: '/api/users',
|
|
36
|
+
method: 'GET',
|
|
37
|
+
query: { page: 1, limit: 10 }
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
description: 'POST请求带JSON体',
|
|
42
|
+
request: {
|
|
43
|
+
url: '/api/login',
|
|
44
|
+
method: 'POST',
|
|
45
|
+
body: { username: 'admin', password: '123456' },
|
|
46
|
+
headers: { 'Content-Type': 'application/json' }
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
description: 'PUT请求带表单数据',
|
|
51
|
+
request: {
|
|
52
|
+
url: '/api/users/123',
|
|
53
|
+
method: 'PUT',
|
|
54
|
+
body: 'name=John&email=john@example.com',
|
|
55
|
+
contentType: 'application/x-www-form-urlencoded'
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
description: 'DELETE请求带认证',
|
|
60
|
+
request: {
|
|
61
|
+
url: '/api/users/123',
|
|
62
|
+
method: 'DELETE',
|
|
63
|
+
headers: { 'Authorization': 'Bearer token123' }
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
bestPractices: [
|
|
68
|
+
'使用相对URL: /api/endpoint 而不是完整URL',
|
|
69
|
+
'通过api_config工具设置baseUrl',
|
|
70
|
+
'让工具自动检测内容类型,除非有特殊需求',
|
|
71
|
+
'GET请求使用query参数而不是body',
|
|
72
|
+
'通过headers参数设置认证信息'
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
api_login: {
|
|
76
|
+
name: 'api_login',
|
|
77
|
+
description: 'API登录工具 - 使用环境变量进行登录认证',
|
|
78
|
+
usage: '无需参数,直接从环境变量获取登录信息',
|
|
79
|
+
environmentVariables: {
|
|
80
|
+
'API_DEBUG_LOGIN_URL': '登录接口URL(默认: /api/login)',
|
|
81
|
+
'API_DEBUG_LOGIN_METHOD': '登录请求方法(默认: POST)',
|
|
82
|
+
'API_DEBUG_LOGIN_BODY': '登录请求体模板(支持JSON和字符串格式)',
|
|
83
|
+
'API_DEBUG_LOGIN_DESCRIPTION': '登录接口描述'
|
|
84
|
+
},
|
|
85
|
+
features: [
|
|
86
|
+
'自动从环境变量获取登录配置',
|
|
87
|
+
'支持JSON和字符串格式的登录体',
|
|
88
|
+
'自动提取token并更新Authorization头',
|
|
89
|
+
'支持自定义baseUrl参数'
|
|
90
|
+
],
|
|
91
|
+
examples: [
|
|
92
|
+
{
|
|
93
|
+
description: '基本登录(使用环境变量配置)',
|
|
94
|
+
request: {}
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
description: '指定baseUrl的登录',
|
|
98
|
+
request: {
|
|
99
|
+
baseUrl: 'https://api.example.com'
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
api_config: {
|
|
105
|
+
name: 'api_config',
|
|
106
|
+
description: 'API配置管理工具 - 管理全局API配置',
|
|
107
|
+
usage: '使用action参数指定操作类型',
|
|
108
|
+
actions: {
|
|
109
|
+
'get': '获取当前配置',
|
|
110
|
+
'set': '设置完整配置',
|
|
111
|
+
'updateBaseUrl': '更新基础URL',
|
|
112
|
+
'updateHeaders': '更新请求头',
|
|
113
|
+
'deleteHeader': '删除指定请求头',
|
|
114
|
+
'search': '搜索API',
|
|
115
|
+
'list': '列出所有API'
|
|
116
|
+
},
|
|
117
|
+
examples: [
|
|
118
|
+
{
|
|
119
|
+
description: '获取配置',
|
|
120
|
+
request: { action: 'get' }
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
description: '更新基础URL',
|
|
124
|
+
request: {
|
|
125
|
+
action: 'updateBaseUrl',
|
|
126
|
+
baseUrl: 'https://api.example.com'
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
description: '更新请求头',
|
|
131
|
+
request: {
|
|
132
|
+
action: 'updateHeaders',
|
|
133
|
+
headers: { 'Authorization': 'Bearer token123' }
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
description: '搜索API',
|
|
138
|
+
request: {
|
|
139
|
+
action: 'search',
|
|
140
|
+
keyword: 'user'
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
]
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
if (tool && helpContent[tool]) {
|
|
148
|
+
return {
|
|
149
|
+
success: true,
|
|
150
|
+
tool: helpContent[tool],
|
|
151
|
+
timestamp: new Date().toISOString()
|
|
152
|
+
};
|
|
153
|
+
} else {
|
|
154
|
+
return {
|
|
155
|
+
success: true,
|
|
156
|
+
message: 'API调试工具帮助文档',
|
|
157
|
+
tools: helpContent,
|
|
158
|
+
quickStart: {
|
|
159
|
+
'1. 设置配置': '使用 api_config 工具设置 baseUrl 和 headers',
|
|
160
|
+
'2. 登录认证': '使用 api_login 工具进行登录(如果需要)',
|
|
161
|
+
'3. 调试API': '使用 api_debug 工具执行API请求',
|
|
162
|
+
'4. 查看帮助': '使用 api_help 工具查看详细说明'
|
|
163
|
+
},
|
|
164
|
+
timestamp: new Date().toISOString()
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
module.exports = api_help;
|