Skip to content

Commit 29ce15f

Browse files
committed
✨ feat: 配置增加 MCP 支持
1 parent 41a1784 commit 29ce15f

File tree

4 files changed

+129
-0
lines changed

4 files changed

+129
-0
lines changed

.github/workflows/publish-mcp.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: NPM Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- "mcp-v*"
7+
jobs:
8+
build:
9+
permissions:
10+
contents: write
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: actions/setup-node@v3
16+
with:
17+
node-version: 18
18+
registry-url: "https://registry.npmjs.org"
19+
cache: yarn
20+
- run: yarn install --frozen-lockfile
21+
22+
- name: Build
23+
run: |
24+
cp ./packages/vitepress-theme-async/types/theme.d.ts ./packages/mcp-server
25+
node ./scripts/publish.mjs
26+
cd ./packages/mcp-server
27+
npm publish
28+
env:
29+
RELEASE_VERSION: ${{ github.ref }}
30+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

packages/mcp-server/index.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env node
2+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
3+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4+
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
5+
import { readFileSync } from 'fs'
6+
import { resolve } from 'path';
7+
8+
const text = readFileSync(resolve(__dirname, 'theme.d.ts'), {
9+
encoding: 'utf-8'
10+
});
11+
12+
class AsyncConfigServer {
13+
server;
14+
constructor() {
15+
this.server = new Server({
16+
name: 'vitepress-theme-async-server',
17+
version: '1.0.0',
18+
}, {
19+
capabilities: {
20+
tools: {},
21+
},
22+
});
23+
this.setupToolHandlers();
24+
}
25+
setupToolHandlers() {
26+
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
27+
return {
28+
tools: [
29+
{
30+
name: 'async_config_doc',
31+
description: 'vitepress-theme-async 主题配置的描述文件,当用户询问主题配置时,可以调用此工具获取参考配置信息,采用的是 .d.ts 详细描述了主题配置格式',
32+
inputSchema: {
33+
type: 'object',
34+
properties: {},
35+
},
36+
},
37+
],
38+
};
39+
});
40+
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
41+
const { name } = request.params;
42+
switch (name) {
43+
case 'async_config_doc':
44+
return {
45+
content: [
46+
{
47+
type: 'text',
48+
text: text,
49+
},
50+
],
51+
};
52+
default:
53+
throw new Error(`未知工具: ${name}`);
54+
}
55+
});
56+
}
57+
async run() {
58+
const transport = new StdioServerTransport();
59+
await this.server.connect(transport);
60+
console.error('Example MCP Server 已启动');
61+
}
62+
}
63+
64+
const server = new AsyncConfigServer();
65+
server.run().catch((error) => {
66+
console.error('服务器启动失败:', error);
67+
process.exit(1);
68+
});

packages/mcp-server/package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "vitepress-theme-async-mcp-server",
3+
"version": "0.0.0",
4+
"repository": "git@github.com:MaLuns/vitepress-theme-async.git",
5+
"author": "白云苍狗 <admin@imalun.com>",
6+
"homepage": "https://vitepress-theme-async.imalun.com",
7+
"bugs": {
8+
"url": "https://github.com/MaLuns/vitepress-theme-async/issues"
9+
},
10+
"license": "MIT",
11+
"type": "module",
12+
"main": "./index.js",
13+
"files": [
14+
"theme.d.ts",
15+
"index.js",
16+
"README.md"
17+
],
18+
"keywords": [
19+
"vitepress-theme",
20+
"blog-theme"
21+
],
22+
"scripts": {
23+
"test": "ec"
24+
},
25+
"dependencies": {
26+
"@modelcontextprotocol/sdk": "^0.5.0"
27+
}
28+
}

scripts/publish.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import { resolve } from "path";
33
import { fileURLToPath } from "url";
44
import themepkg from "../packages/vitepress-theme-async/package.json" assert { type: "json" };
55
import clipkg from "../packages/create-theme/package.json" assert { type: "json" };
6+
import mcppkg from "../packages/mcp-server/package.json" assert { type: "json" };
67

78

89
if (process.env.RELEASE_VERSION) {
910
const version = process.env.RELEASE_VERSION.split("/").reverse()[0];
1011
console.log("当前版本:", version);
1112
themepkg.version = version.replace("v", "");
1213
clipkg.version = version.replace("cli-v", "");
14+
mcppkg.version = version.replace("mcp-v", "");
1315
writeFileSync(resolve(fileURLToPath(import.meta.url), "../../packages/vitepress-theme-async/package.json"), JSON.stringify(themepkg, null, 4), "utf-8");
1416
writeFileSync(resolve(fileURLToPath(import.meta.url), "../../packages/create-theme/package.json"), JSON.stringify(clipkg, null, 4), "utf-8");
17+
writeFileSync(resolve(fileURLToPath(import.meta.url), "../../packages/mcp-server/package.json"), JSON.stringify(mcppkg, null, 4), "utf-8");
1518
}

0 commit comments

Comments
 (0)