mcp-server-iehub-proxy 1.0.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 (2) hide show
  1. package/package.json +1 -0
  2. package/proxy.mjs +98 -0
package/package.json ADDED
@@ -0,0 +1 @@
1
+ {"name": "mcp-server-iehub-proxy", "version": "1.0.0", "description": "IE-Hub MCP 远程代理 - 通过公网访问本地数据库", "main": "proxy.mjs", "bin": {"mcp-iehub-proxy": "./proxy.mjs"}, "scripts": {"start": "node proxy.mjs"}, "keywords": ["mcp", "iehub", "proxy", "产教融合"], "author": "", "license": "MIT", "dependencies": {"@modelcontextprotocol/sdk": "^1.0.0", "zod": "^3.23.0"}}
package/proxy.mjs ADDED
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
+ import { z } from 'zod';
5
+
6
+ const VERSION = '1.0.0';
7
+ const REMOTE_URL = process.env.REMOTE_MCP_URL || 'https://consequence-pushing-peer-exist.trycloudflare.com';
8
+
9
+ console.error(`[IEHub-Proxy] 🚀 远程代理 v${VERSION}`);
10
+ console.error(`[IEHub-Proxy] 🔗 目标: ${REMOTE_URL}`);
11
+
12
+ async function callRemoteTool(toolName, args = {}) {
13
+ const url = `${REMOTE_URL}/mcp/tools/${toolName}`;
14
+ const response = await fetch(url, {
15
+ method: 'POST',
16
+ headers: { 'Content-Type': 'application/json' },
17
+ body: JSON.stringify({ arguments: args })
18
+ });
19
+
20
+ if (!response.ok) {
21
+ throw new Error(`HTTP ${response.status}: ${await response.text()}`);
22
+ }
23
+
24
+ const data = await response.json();
25
+ if (data.error) throw new Error(data.error.message);
26
+ return data.result;
27
+ }
28
+
29
+ const tools = [
30
+ ['ping', '测试MCP远程代理连接状态', { message: z.string().optional().default('hello') }],
31
+ ['submit_form', '提交产教融合项目表单', {
32
+ formType: z.string().describe('表单类型'),
33
+ college: z.string().describe('学院名称'),
34
+ submitterName: z.string().describe('提交人姓名'),
35
+ submitterId: z.string().describe('提交人ID'),
36
+ formData: z.record(z.unknown()).describe('表单数据')
37
+ }],
38
+ ['get_pending_reviews', '获取待审核列表', {
39
+ college: z.string().optional(), formType: z.string().optional(),
40
+ page: z.number().optional().default(1), pageSize: z.number().optional().default(10)
41
+ }],
42
+ ['approve_submission', '审核通过提交', {
43
+ submissionId: z.string(), reviewerId: z.string(),
44
+ recognizedScore: z.number().optional(), comments: z.string().optional()
45
+ }],
46
+ ['reject_submission', '驳回提交', {
47
+ submissionId: z.string(), reviewerId: z.string(), comments: z.string()
48
+ }],
49
+ ['get_submission_detail', '获取提交详情', { submissionId: z.string() }],
50
+ ['search_submissions', '搜索提交记录', {
51
+ college: z.string().optional(), formType: z.string().optional(),
52
+ status: z.string().optional(), page: z.number().optional().default(1), pageSize: z.number().optional().default(10)
53
+ }],
54
+ ['get_statistics', '获取统计数据', { college: z.string().optional() }],
55
+ ['get_college_leaderboard', '获取学院排行榜', { limit: z.number().optional().default(10) }],
56
+ ['get_project_type_leaderboard', '获取项目类型排行榜', { limit: z.number().optional().default(14) }],
57
+ ['get_all_colleges', '获取所有学院列表', {}],
58
+ ['get_review_history', '获取审核历史', {
59
+ reviewerId: z.string().optional(), college: z.string().optional(),
60
+ page: z.number().optional().default(1), pageSize: z.number().optional().default(10)
61
+ }]
62
+ ];
63
+
64
+ async function start() {
65
+ const server = new McpServer({
66
+ name: 'iehub-mcp-proxy',
67
+ version: VERSION
68
+ });
69
+
70
+ for (const [name, description, schema] of tools) {
71
+ server.tool(name, description, schema, async (args) => {
72
+ try {
73
+ const result = await callRemoteTool(name, args);
74
+ return { content: result.content || [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
75
+ } catch (error) {
76
+ return {
77
+ content: [{ type: 'text', text: JSON.stringify({
78
+ error: error.message,
79
+ tool: name,
80
+ hint: '请确保本地MCP服务已启动且Cloudflare Tunnel正在运行'
81
+ }, null, 2) }],
82
+ isError: true
83
+ };
84
+ }
85
+ });
86
+ }
87
+
88
+ console.error(`[IEHub-Proxy] ✅ 已注册 ${tools.length} 个工具`);
89
+ console.error('[IEHub-Proxy] 等待客户端连接...');
90
+
91
+ const transport = new StdioServerTransport();
92
+ await server.connect(transport);
93
+ }
94
+
95
+ start().catch((err) => {
96
+ console.error('[IEHub-Proxy] 💥 启动失败:', err.message);
97
+ process.exit(1);
98
+ });