miniprogram-mcp 0.0.0-stage → 0.2.0

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.
Files changed (3) hide show
  1. package/README.md +80 -2
  2. package/index.mjs +90 -0
  3. package/package.json +23 -3
package/README.md CHANGED
@@ -1,3 +1,81 @@
1
- # Temporary Holding Version
1
+ # miniprogram-mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 轻用市场 MCP 的 stdio 桥接包:把远程 HTTP MCP(`market.qyyapp.com`)接入本地 AI 客户端(Claude Code、Cursor、Claude Desktop、Qoder 等)。
4
+
5
+ 与直接配置远程 HTTP 地址相比:
6
+
7
+ - **配置一次,所有对话生效**:客户端的 MCP 配置是持久的,不会换个对话框就丢。
8
+ - **个人访问令牌认证**:不依赖浏览器 OAuth 弹窗,令牌在平台「MCP 接入」页生成,可随时吊销。
9
+ - **永不过时**:本包只做 stdio ↔ HTTP 转发,工具定义与使用说明全部实时来自服务端,服务端新增工具后无需更新本包。
10
+
11
+ ## 获取令牌
12
+
13
+ 1. 登录 [market.qyyapp.com](https://market.qyyapp.com),打开「MCP 接入」页。
14
+ 2. 在「个人访问令牌」中创建令牌(可设置有效期、必须选择绑定的商户应用),**明文只显示一次**,立即复制保存;创建成功后页面会把令牌自动填入安装配置示例(--token 与 QYYAPP_MCP_TOKEN)。
15
+ 3. 令牌泄露时在同一页面删除即可立即失效。
16
+
17
+ ## 注册到 AI 客户端
18
+
19
+ 第 1 步:在任意本地项目目录安装:
20
+
21
+ ```bash
22
+ npm install miniprogram-mcp
23
+ # 或 pnpm add miniprogram-mcp / yarn add miniprogram-mcp
24
+ ```
25
+
26
+ 第 2 步:在该项目的 `package.json` 中加入启动脚本,把令牌替换为上面创建的令牌:
27
+
28
+ ```json
29
+ {
30
+ "scripts": {
31
+ "mcp": "miniprogram-mcp --token mcp_你的令牌"
32
+ }
33
+ }
34
+ ```
35
+
36
+ 第 3 步:在客户端 MCP 配置(Cursor `~/.cursor/mcp.json`、Claude Desktop `claude_desktop_config.json`、Qoder 等)中合并以下内容,把路径替换为第 1 步的项目目录:
37
+
38
+ ```json
39
+ {
40
+ "mcpServers": {
41
+ "qyyapp-market": {
42
+ "command": "npm",
43
+ "args": ["--prefix", "/你的项目路径", "run", "mcp"]
44
+ }
45
+ }
46
+ }
47
+ ```
48
+
49
+ Claude Code 命令行:
50
+
51
+ ```bash
52
+ claude mcp add qyyapp-market -- npm --prefix /你的项目路径 run mcp
53
+ ```
54
+
55
+ 入口同时包含商户工具(market_*)与开发者工具(developer_*:代码包上传、域名与隐私配置等),无需区分角色。
56
+
57
+ 令牌明文保存在 package.json 中,请勿将该项目提交到公开仓库。令牌创建时必须绑定商户应用,MCP 工具未指定 appId/appName 时默认操作该应用及其代码模版。
58
+
59
+ ## 配置项
60
+
61
+ 启动参数与环境变量二选一,参数优先:
62
+
63
+ | 参数 | 环境变量 | 默认值 | 说明 |
64
+ | --- | --- | --- | --- |
65
+ | `--token` | `QYYAPP_MCP_TOKEN` | 无(必填) | 个人访问令牌,`mcp_` 开头 |
66
+ | `--url` | `QYYAPP_MCP_URL` | `https://market.qyyapp.com` | 服务地址,本地调试可指到 `http://127.0.0.1:7001` |
67
+
68
+ ## 本地调试
69
+
70
+ ```bash
71
+ npm install
72
+ QYYAPP_MCP_TOKEN=mcp_你的令牌 QYYAPP_MCP_URL=http://127.0.0.1:7001 node index.mjs
73
+ ```
74
+
75
+ ## 发布
76
+
77
+ ```bash
78
+ npm publish --registry=https://registry.npmjs.org
79
+ ```
80
+
81
+ 要求 Node.js >= 18。
package/index.mjs ADDED
@@ -0,0 +1,90 @@
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, PingRequestSchema } from '@modelcontextprotocol/sdk/types.js';
5
+
6
+ const VERSION = '0.2.0';
7
+
8
+ function readOption(name, envKeys, fallback) {
9
+ const index = process.argv.indexOf(`--${name}`);
10
+ if (index > -1 && process.argv[index + 1]) return process.argv[index + 1];
11
+ for (const key of envKeys) {
12
+ if (process.env[key]) return process.env[key];
13
+ }
14
+ return fallback;
15
+ }
16
+
17
+ const token = readOption('token', ['QYYAPP_MCP_TOKEN', 'MARKET_MCP_TOKEN'], '');
18
+ const base = readOption('url', ['QYYAPP_MCP_URL', 'MARKET_API_BASE'], 'https://market.qyyapp.com').replace(/\/+$/, '');
19
+
20
+ function fail(message) {
21
+ console.error(`[miniprogram-mcp] ${message}`);
22
+ process.exit(1);
23
+ }
24
+
25
+ if (!token) {
26
+ fail(
27
+ '缺少个人访问令牌。请先登录平台,在「MCP 接入」页创建令牌,然后配置环境变量 QYYAPP_MCP_TOKEN 或启动参数 --token。\n' +
28
+ '示例:npx -y miniprogram-mcp --token mcp_xxxxxxxx'
29
+ );
30
+ }
31
+
32
+ const endpoint = `${base}/app/mcp/market`;
33
+ let seq = 0;
34
+
35
+ async function rpc(method, params) {
36
+ let res;
37
+ try {
38
+ res = await fetch(endpoint, {
39
+ method: 'POST',
40
+ headers: { 'Content-Type': 'application/json', Accept: 'application/json', Authorization: `Bearer ${token}` },
41
+ body: JSON.stringify({ jsonrpc: '2.0', id: ++seq, method, params }),
42
+ signal: AbortSignal.timeout(180000),
43
+ });
44
+ } catch (error) {
45
+ throw new Error(`无法连接 MCP 服务 ${endpoint}:${error?.message || error}`);
46
+ }
47
+ if (res.status === 401) throw new Error('访问令牌无效或已过期,请在平台「MCP 接入」页重新生成令牌并更新客户端配置');
48
+ const text = await res.text();
49
+ let json;
50
+ try {
51
+ json = text ? JSON.parse(text) : {};
52
+ } catch {
53
+ throw new Error(`MCP 服务返回非 JSON(HTTP ${res.status}):${text.slice(0, 200)}`);
54
+ }
55
+ if (json.error) throw new Error(json.error.message || `MCP 调用失败(${json.error.code})`);
56
+ return json.result;
57
+ }
58
+
59
+ // 工具定义与使用说明全部来自服务端,本包只做 stdio ↔ HTTP 转发,服务端升级后无需更新本包
60
+ const init = await rpc('initialize', {
61
+ protocolVersion: '2025-06-18',
62
+ capabilities: {},
63
+ clientInfo: { name: 'miniprogram-mcp-bridge', version: VERSION },
64
+ }).catch(error => fail(error.message));
65
+
66
+ await fetch(endpoint, {
67
+ method: 'POST',
68
+ headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
69
+ body: JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized' }),
70
+ }).catch(() => {});
71
+
72
+ const server = new Server(
73
+ { name: init?.serverInfo?.name || 'miniprogram-market', version: init?.serverInfo?.version || VERSION },
74
+ { capabilities: { tools: {} }, instructions: init?.instructions }
75
+ );
76
+
77
+ server.setRequestHandler(ListToolsRequestSchema, async () => rpc('tools/list', {}));
78
+
79
+ server.setRequestHandler(CallToolRequestSchema, async request => {
80
+ try {
81
+ return await rpc('tools/call', { name: request.params.name, arguments: request.params.arguments || {} });
82
+ } catch (error) {
83
+ return { content: [{ type: 'text', text: `失败:${error?.message || String(error)}` }], isError: true };
84
+ }
85
+ });
86
+
87
+ server.setRequestHandler(PingRequestSchema, async () => ({}));
88
+
89
+ await server.connect(new StdioServerTransport());
90
+ console.error(`[miniprogram-mcp] 已连接 ${endpoint}`);
package/package.json CHANGED
@@ -1,6 +1,26 @@
1
1
  {
2
2
  "name": "miniprogram-mcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "轻用市场 MCP stdio 桥接:把 market.qyyapp.com 的远程 HTTP MCP 接入本地 AI 客户端,个人访问令牌认证,工具定义始终来自服务端",
5
+ "type": "module",
6
+ "bin": {
7
+ "miniprogram-mcp": "./index.mjs"
8
+ },
9
+ "files": [
10
+ "index.mjs",
11
+ "README.md"
12
+ ],
13
+ "engines": {
14
+ "node": ">=18"
15
+ },
16
+ "keywords": [
17
+ "mcp",
18
+ "qyyapp",
19
+ "miniprogram",
20
+ "weixin"
21
+ ],
22
+ "license": "MIT",
23
+ "dependencies": {
24
+ "@modelcontextprotocol/sdk": "^1.32.2"
25
+ }
6
26
  }