@baitong-dev/skills-mcp 0.0.2 → 0.0.3
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/dist/index.js +23 -120
- package/package.json +5 -2
package/dist/index.js
CHANGED
|
@@ -5,38 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
7
7
|
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
8
|
-
const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
9
8
|
const fs_1 = __importDefault(require("fs"));
|
|
10
|
-
const http_1 = require("http");
|
|
11
9
|
const path_1 = __importDefault(require("path"));
|
|
12
10
|
const zod_1 = __importDefault(require("zod"));
|
|
13
|
-
const commander_1 = require("commander");
|
|
14
11
|
const mcp_helpers_1 = require("@baitong-dev/mcp-helpers");
|
|
15
12
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
16
13
|
const yamlFront = require('yaml-front-matter');
|
|
17
|
-
// 命令行参数处理
|
|
18
|
-
const program = new commander_1.Command()
|
|
19
|
-
.option('--transport <stdio|http|sse>', 'transport type', 'stdio')
|
|
20
|
-
.option('--port <number>', 'port for HTTP/SSE transport', '3000')
|
|
21
|
-
.parse(process.argv);
|
|
22
|
-
const cliOptions = program.opts();
|
|
23
|
-
const allowedTransports = ['stdio', 'http'];
|
|
24
|
-
if (!allowedTransports.includes(cliOptions.transport)) {
|
|
25
|
-
console.error(`Invalid --transport value: '${cliOptions.transport}'. Must be one of: stdio, http, sse.`);
|
|
26
|
-
process.exit(1);
|
|
27
|
-
}
|
|
28
14
|
const MCP_NAME = 'Skills MCP';
|
|
29
|
-
const MCP_VERSION = '0.0.
|
|
30
|
-
const PORT = parseInt(cliOptions.port, 10);
|
|
31
|
-
const TRANSPORT_TYPE = (cliOptions.transport || 'stdio');
|
|
32
|
-
const logInfo = (...args) => {
|
|
33
|
-
if (TRANSPORT_TYPE === 'stdio') {
|
|
34
|
-
console.error(...args);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
console.log(...args);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
15
|
+
const MCP_VERSION = '0.0.3';
|
|
40
16
|
function getSkillsRootDir() {
|
|
41
17
|
const dir = path_1.default.join(mcp_helpers_1.MCP_HOME_DIR, 'skills');
|
|
42
18
|
if (!fs_1.default.existsSync(dir)) {
|
|
@@ -54,7 +30,7 @@ function loadSkillsMetadata() {
|
|
|
54
30
|
JSON.parse(fs_1.default.readFileSync(path_1.default.join(mcp_helpers_1.MCP_HOME_DIR, 'config', 'skills_config.json'), 'utf-8'))
|
|
55
31
|
.skills || [];
|
|
56
32
|
}
|
|
57
|
-
catch (
|
|
33
|
+
catch (_) {
|
|
58
34
|
skillConfigs = [];
|
|
59
35
|
}
|
|
60
36
|
return skillsRootDirs
|
|
@@ -114,7 +90,8 @@ Available skills:
|
|
|
114
90
|
|
|
115
91
|
${metadata.map(skill => `- ${skill.name}: ${skill.description}`).join('\n')}`,
|
|
116
92
|
inputSchema: zod_1.default.object({
|
|
117
|
-
skillName: zod_1.default.string().describe(`The name of the skill from available skills${hint}`)
|
|
93
|
+
skillName: zod_1.default.string().describe(`The name of the skill from available skills${hint}`),
|
|
94
|
+
toolInfo: mcp_helpers_1.Tool.Info
|
|
118
95
|
})
|
|
119
96
|
}, async ({ skillName }) => {
|
|
120
97
|
if (metadata.length === 0) {
|
|
@@ -157,7 +134,10 @@ ${json.__content}`
|
|
|
157
134
|
}
|
|
158
135
|
function registerRefreshSkills(server) {
|
|
159
136
|
server.registerTool('reload_skills', {
|
|
160
|
-
description: `Reload skills metadata. Especially after creating a new skill
|
|
137
|
+
description: `Reload skills metadata. Especially after creating a new skill.`, // 尤其在创建技能后要调用下重新加载技能
|
|
138
|
+
inputSchema: zod_1.default.object({
|
|
139
|
+
toolInfo: mcp_helpers_1.Tool.Info
|
|
140
|
+
})
|
|
161
141
|
}, async () => {
|
|
162
142
|
return {
|
|
163
143
|
content: [
|
|
@@ -170,100 +150,23 @@ function registerRefreshSkills(server) {
|
|
|
170
150
|
});
|
|
171
151
|
}
|
|
172
152
|
// 创建MCP服务器实例
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
logging: {}
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
// 注册所有工具
|
|
183
|
-
registerLoadSkill(server);
|
|
184
|
-
registerRefreshSkills(server);
|
|
185
|
-
return server;
|
|
186
|
-
}
|
|
187
|
-
async function main() {
|
|
188
|
-
if (TRANSPORT_TYPE === 'http') {
|
|
189
|
-
const httpServer = (0, http_1.createServer)(async (req, res) => {
|
|
190
|
-
const url = new URL(req.url || '', `http://${req.headers.host}`).pathname;
|
|
191
|
-
// 设置 CORS 头
|
|
192
|
-
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
193
|
-
res.setHeader('Access-Control-Allow-Methods', 'GET,POST,OPTIONS,DELETE');
|
|
194
|
-
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, MCP-Session-Id, mcp-session-id');
|
|
195
|
-
// 处理预检请求
|
|
196
|
-
if (req.method === 'OPTIONS') {
|
|
197
|
-
res.writeHead(200);
|
|
198
|
-
res.end();
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
try {
|
|
202
|
-
// 为每个请求创建新的服务器实例
|
|
203
|
-
const requestServer = createServerInstance();
|
|
204
|
-
if (url === '/mcp') {
|
|
205
|
-
const transport = new streamableHttp_js_1.StreamableHTTPServerTransport({
|
|
206
|
-
sessionIdGenerator: undefined
|
|
207
|
-
});
|
|
208
|
-
await requestServer.connect(transport);
|
|
209
|
-
await transport.handleRequest(req, res);
|
|
210
|
-
}
|
|
211
|
-
else if (url === '/health') {
|
|
212
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
213
|
-
res.end(JSON.stringify({ status: 'ok', transport: TRANSPORT_TYPE }));
|
|
214
|
-
}
|
|
215
|
-
else if (url === '/info') {
|
|
216
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
217
|
-
res.end(JSON.stringify({
|
|
218
|
-
name: `${MCP_NAME} Server`,
|
|
219
|
-
version: MCP_VERSION,
|
|
220
|
-
transport: TRANSPORT_TYPE,
|
|
221
|
-
endpoints: {
|
|
222
|
-
mcp: '/mcp',
|
|
223
|
-
health: '/health',
|
|
224
|
-
info: '/info'
|
|
225
|
-
}
|
|
226
|
-
}));
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
res.writeHead(404);
|
|
230
|
-
res.end('Not found');
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
catch (error) {
|
|
234
|
-
console.error('Error handling request: ', error);
|
|
235
|
-
if (!res.headersSent) {
|
|
236
|
-
res.writeHead(500);
|
|
237
|
-
res.end('Internal Server Error');
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
httpServer.listen(PORT, () => {
|
|
242
|
-
logInfo(`${MCP_NAME} ${TRANSPORT_TYPE.toUpperCase()} server started.`);
|
|
243
|
-
logInfo(`MCP endpoint: http://localhost:${PORT}/mcp`);
|
|
244
|
-
logInfo(`Health: http://localhost:${PORT}/health`);
|
|
245
|
-
logInfo(`Info: http://localhost:${PORT}/info`);
|
|
246
|
-
});
|
|
153
|
+
const server = new mcp_js_1.McpServer({
|
|
154
|
+
name: MCP_NAME,
|
|
155
|
+
version: MCP_VERSION
|
|
156
|
+
}, {
|
|
157
|
+
capabilities: {
|
|
158
|
+
logging: {}
|
|
247
159
|
}
|
|
248
|
-
else {
|
|
249
|
-
// stdio 模式
|
|
250
|
-
const server = createServerInstance();
|
|
251
|
-
const transport = new stdio_js_1.StdioServerTransport();
|
|
252
|
-
await server.connect(transport);
|
|
253
|
-
logInfo(`${MCP_NAME} ${TRANSPORT_TYPE.toUpperCase()} server started.`);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
// 优雅关闭
|
|
257
|
-
process.on('SIGINT', async () => {
|
|
258
|
-
logInfo(`\nShutting down ${MCP_NAME} server...`);
|
|
259
|
-
process.exit(0);
|
|
260
|
-
});
|
|
261
|
-
process.on('SIGTERM', async () => {
|
|
262
|
-
logInfo(`\nReceived termination signal, shutting down ${MCP_NAME} server...`);
|
|
263
|
-
process.exit(0);
|
|
264
160
|
});
|
|
265
|
-
//
|
|
161
|
+
// 注册所有工具
|
|
162
|
+
registerLoadSkill(server);
|
|
163
|
+
registerRefreshSkills(server);
|
|
164
|
+
async function main() {
|
|
165
|
+
const transport = new stdio_js_1.StdioServerTransport();
|
|
166
|
+
await server.connect(transport);
|
|
167
|
+
console.error(`${MCP_NAME} Server v${MCP_VERSION} running`);
|
|
168
|
+
}
|
|
266
169
|
main().catch(error => {
|
|
267
|
-
|
|
170
|
+
console.error('Fatal error in main():', error);
|
|
268
171
|
process.exit(1);
|
|
269
172
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baitong-dev/skills-mcp",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"bin": {
|
|
6
6
|
"@baitong-dev/skills-mcp": "./dist/index.js"
|
|
@@ -19,7 +19,10 @@
|
|
|
19
19
|
"commander": "^14.0.3",
|
|
20
20
|
"yaml-front-matter": "^4.1.1",
|
|
21
21
|
"zod": "^4.3.4",
|
|
22
|
-
"@baitong-dev/mcp-helpers": "0.0.
|
|
22
|
+
"@baitong-dev/mcp-helpers": "0.0.5"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"typescript": "^5.9.2"
|
|
23
26
|
},
|
|
24
27
|
"publishConfig": {
|
|
25
28
|
"access": "public",
|