Skip to content

Commit 2798f60

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

File tree

5 files changed

+177
-0
lines changed

5 files changed

+177
-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/lib
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/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Vitepress-theme-async MCP Server
2+
3+
使用 Vitepress-theme-async MCP Server,可以将主题配置说明信息当做数据源提供给 Cursor 等支持 AI 编程的 IDE 工具以便让 AI 能够直接根据你的需求修改配置。
4+
5+
通过 MCP 可以免去了你需要去查阅文档,或者去查看主题源码的麻烦,直接让 AI 帮你修改主题配置。
6+
7+
## 🎯 如何使用
8+
9+
安装配置好 MCP 后,AI 可以通过 MCP 读取主题配置说明信息。
10+
11+
你只要告诉 AI 你想要通过 修改主题配置信息,示例:
12+
13+
- “主题 vitepress-theme-async 有哪些配置信息”
14+
- “帮我修改 banner 配置, 将背景图换成 xxxx ”
15+
- “帮我修改 关于我 页面配置”
16+
- “.......”
17+
18+
## 🚀 安装方法
19+
20+
### 前置条件
21+
22+
- 已安装 Node.js 环境(版本号 >= 18,推荐最新的 LTS 版本)
23+
- 任意一个支持 MCP 的 IDE:
24+
- Cursor
25+
- VSCode + Cline 插件
26+
- ......
27+
28+
### 安装
29+
30+
将下面 JSON 配置添加到 IDE 对应的 MCP 配置文件里:
31+
32+
``` json
33+
{
34+
"mcpServers": {
35+
"async配置": {
36+
"command": "npx",
37+
"args": [
38+
"-y",
39+
"vitepress-theme-async-mcp-server@latest",
40+
]
41+
}
42+
}
43+
}
44+
```
45+
46+
目前 MCP Server 仅提供 AI 配置文件详细说明,更细致化自定义功能还不支持。

packages/mcp-server/lib/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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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": "lib/index.js",
13+
"bin": {
14+
"apifox-mcp-server": "lib/index.js"
15+
},
16+
"files": [
17+
"lib",
18+
"README.md"
19+
],
20+
"keywords": [
21+
"vitepress-theme",
22+
"blog-theme"
23+
],
24+
"scripts": {
25+
"test": "ec"
26+
},
27+
"dependencies": {
28+
"@modelcontextprotocol/sdk": "^0.5.0"
29+
}
30+
}

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)