Skip to content

Commit cd0c577

Browse files
committed
fix: run lint:fix
1 parent fbd180f commit cd0c577

File tree

44 files changed

+452
-482
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+452
-482
lines changed

app/agent/mcpHttpHandler.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const url = require('url');
21
const { MCPProxy } = require('../mcp/mcpProxy');
32
const getRawBody = require('raw-body');
43
const contentType = require('content-type');
@@ -19,8 +18,14 @@ class MCPHttpHandler {
1918
*/
2019
async handleRequest(req, res) {
2120
try {
22-
const parsedUrl = url.parse(req.url, true);
23-
const { pathname, query } = parsedUrl;
21+
const parsedUrl = new URL(req.url, 'http://localhost');
22+
const pathname = parsedUrl.pathname;
23+
24+
// 将查询参数转换为对象
25+
const query = {};
26+
parsedUrl.searchParams.forEach((value, key) => {
27+
query[key] = value;
28+
});
2429
req.query = query;
2530

2631
// 处理/mcp-endpoint/:serverId/*路径 - MCP代理端点

app/agent/mcpInspector.js

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const ip = require('ip');
2-
const { spawn } = require('child_process')
3-
const env = require('../../env.json')
2+
const { spawn } = require('child_process');
3+
const env = require('../../env.json');
44

5-
const { mcpInspectorWebPort, mcpInspectorServerPort, mcpInspectorDomainWhiteList } = env
5+
const { mcpInspectorWebPort, mcpInspectorServerPort, mcpInspectorDomainWhiteList } = env;
66

77
const startMcpInspector = (agent) => {
88
const localIP = ip.address();
@@ -11,28 +11,32 @@ const startMcpInspector = (agent) => {
1111
domainWhiteList.push(`http://localhost:${port}`);
1212
domainWhiteList.push(`http://127.0.0.1:${port}`);
1313
domainWhiteList.push(`http://${localIP}:${port}`);
14-
domainWhiteList.push(...mcpInspectorDomainWhiteList.map(domain => `${domain}:${port}`));
15-
});
16-
17-
const child = spawn('npx', [
18-
// 如果fetch failed, 可以尝试切换到国内镜像
19-
'--registry=https://registry.npmjs.org',
20-
'-y',
21-
'@modelcontextprotocol/[email protected]',
22-
], {
23-
stdio: ['pipe', 'pipe', 'pipe'],
24-
cwd: process.cwd(),
25-
env: {
26-
...process.env,
27-
CLIENT_PORT: mcpInspectorWebPort,
28-
SERVER_PORT: mcpInspectorServerPort,
29-
MCP_AUTO_OPEN_ENABLED: false,
30-
HOST: '0.0.0.0',
31-
DANGEROUSLY_OMIT_AUTH: true,
32-
ALLOWED_ORIGINS: domainWhiteList.join(','),
33-
},
14+
domainWhiteList.push(...mcpInspectorDomainWhiteList.map((domain) => `${domain}:${port}`));
3415
});
3516

17+
const child = spawn(
18+
'npx',
19+
[
20+
// 如果fetch failed, 可以尝试切换到国内镜像
21+
'--registry=https://registry.npmjs.org',
22+
'-y',
23+
'@modelcontextprotocol/[email protected]',
24+
],
25+
{
26+
stdio: ['pipe', 'pipe', 'pipe'],
27+
cwd: process.cwd(),
28+
env: {
29+
...process.env,
30+
CLIENT_PORT: mcpInspectorWebPort,
31+
SERVER_PORT: mcpInspectorServerPort,
32+
MCP_AUTO_OPEN_ENABLED: false,
33+
HOST: '0.0.0.0',
34+
DANGEROUSLY_OMIT_AUTH: true,
35+
ALLOWED_ORIGINS: domainWhiteList.join(','),
36+
},
37+
}
38+
);
39+
3640
agent.logger.info('\n *** MCP INSPECTOR STARTED ***');
3741

3842
child.stdout.on('data', (data) => {
@@ -52,9 +56,8 @@ const startMcpInspector = (agent) => {
5256
});
5357

5458
return child;
55-
}
56-
59+
};
5760

5861
module.exports = {
59-
startMcpInspector
60-
}
62+
startMcpInspector,
63+
};

app/controller/mcp.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,6 @@ class MCPController extends Controller {
175175
ctx.body = app.utils.response(true, data);
176176
}
177177

178-
async checkMCPServerHealth() {
179-
const { app, ctx } = this;
180-
const { serverId } = ctx.query;
181-
182-
try {
183-
const isHealthy = await ctx.service.mcp.checkMCPServerHealth(serverId);
184-
ctx.body = app.utils.response(true, { serverId, healthy: isHealthy });
185-
} catch (error) {
186-
ctx.logger.error('MCP服务器健康检查失败:', error);
187-
ctx.body = app.utils.response(false, null, error.message);
188-
}
189-
}
190-
191178
async startMCPServer() {
192179
const { app, ctx } = this;
193180
const { serverId } = ctx.request.body;

app/mcp/mcpClient.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const { Client } = require('@modelcontextprotocol/sdk/client/index.js');
22
const { StdioClientTransport } = require('@modelcontextprotocol/sdk/client/stdio.js');
3-
const { StreamableHTTPClientTransport } = require('@modelcontextprotocol/sdk/client/streamableHttp.js');
3+
const {
4+
StreamableHTTPClientTransport,
5+
} = require('@modelcontextprotocol/sdk/client/streamableHttp.js');
46
const { SSEClientTransport } = require('@modelcontextprotocol/sdk/client/sse.js');
57

68
/**
@@ -22,7 +24,7 @@ class MCPClient {
2224
async connect(server) {
2325
try {
2426
this.transport = await this.createTransport(server);
25-
27+
2628
this.client = new Client(
2729
{
2830
name: `doraemon-client-${server.server_id}`,
@@ -38,7 +40,7 @@ class MCPClient {
3840
);
3941

4042
await this.client.connect(this.transport);
41-
43+
4244
return true;
4345
} catch (error) {
4446
this.logger?.error(`MCP客户端连接失败 [${server.server_id}]:`, error);
@@ -54,12 +56,12 @@ class MCPClient {
5456
*/
5557
async createTransport(server) {
5658
let transport;
57-
59+
5860
if (server.transport === 'stdio') {
5961
transport = new StdioClientTransport({
6062
command: server.command,
6163
args: server.args || [],
62-
env: { ...process.env, ...server.env || {} },
64+
env: { ...process.env, ...(server.env || {}) },
6365
cwd: server.deploy_path,
6466
});
6567
} else if (server.transport === 'streamable-http') {
@@ -88,15 +90,15 @@ class MCPClient {
8890
const request = {
8991
jsonrpc: '2.0',
9092
id: pingId,
91-
method: 'ping'
93+
method: 'ping',
9294
};
9395

9496
await this.sendRequest(request, timeout);
9597
return { healthy: true };
9698
} catch (error) {
97-
return {
98-
healthy: false,
99-
error: `Ping失败: ${error.message}`
99+
return {
100+
healthy: false,
101+
error: `Ping失败: ${error.message}`,
100102
};
101103
}
102104
}
@@ -191,7 +193,7 @@ class MCPClient {
191193
this.listTools(),
192194
this.listPrompts(),
193195
this.listResources(),
194-
this.getServerCapabilities()
196+
this.getServerCapabilities(),
195197
]);
196198

197199
if (tools.status === 'fulfilled') {
@@ -237,7 +239,7 @@ class MCPClient {
237239
const messageHandler = (message) => {
238240
if (message.id === request.id) {
239241
clearTimeout(timeoutHandle);
240-
242+
241243
if (message.error) {
242244
reject(new Error(message.error.message || '服务器返回错误'));
243245
} else {

app/mcp/mcpProcessManager.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class MCPProcessManager {
6262

6363
// 使用MCP客户端发送请求
6464
await transport.send(messageObject);
65-
65+
6666
return true;
6767
} catch (error) {
6868
this.logger?.error(`向MCP服务器发送消息失败 [${serverId}]:`, error);
@@ -111,11 +111,11 @@ class MCPProcessManager {
111111
async cleanup() {
112112
const serverIds = Array.from(this.mcpTransports.keys());
113113
const count = serverIds.length;
114-
114+
115115
if (count === 0) {
116116
return;
117117
}
118-
118+
119119
try {
120120
await Promise.all(serverIds.map((serverId) => this.stopStdioProcess(serverId)));
121121
} catch (error) {

app/mcp/mcpProxy.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ class MCPProxy {
1818
this.transportHandlers = new Map();
1919

2020
// 传输处理器实例
21-
this.stdioHandler = new StdioTransportHandler(this.processManager, this.requestManager, logger);
21+
this.stdioHandler = new StdioTransportHandler(
22+
this.processManager,
23+
this.requestManager,
24+
logger
25+
);
2226
this.sseHandler = new SSETransportHandler(logger);
2327
this.httpHandler = new StreamableHttpTransportHandler(logger);
2428

@@ -151,7 +155,7 @@ class MCPProxy {
151155

152156
async cleanup() {
153157
const serverIds = Array.from(this.transportHandlers.keys());
154-
158+
155159
if (serverIds.length === 0) {
156160
return;
157161
}

app/mcp/transportHandlers.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ class BaseTransportHandler {
2121
* @param {string} serverId - 服务器ID
2222
* @param {object} config - 配置
2323
*/
24-
start(serverId, config) {
24+
// @ts-ignore
25+
start() {
2526
throw new Error('Start Method Not Implemented');
2627
}
2728

2829
/**
2930
* 关闭传输
3031
* @param {string} serverId - 服务器ID
3132
*/
32-
stop(serverId) {
33+
// @ts-ignore
34+
stop() {
3335
throw new Error('Stop Method Not Implemented');
3436
}
3537

@@ -39,7 +41,8 @@ class BaseTransportHandler {
3941
* @param {any} req - 请求对象
4042
* @param {object} res - 响应对象
4143
*/
42-
forward(serverId, req, res) {
44+
// @ts-ignore
45+
forward() {
4346
throw new Error('Forward Method Not Implemented');
4447
}
4548

@@ -375,7 +378,8 @@ class SSETransportHandler extends BaseTransportHandler {
375378
};
376379

377380
// 获取原请求的协议和主机名
378-
const protocol = req.headers['x-forwarded-proto'] || (req.socket.encrypted ? 'https' : 'http');
381+
const protocol =
382+
req.headers['x-forwarded-proto'] || (req.socket.encrypted ? 'https' : 'http');
379383
const hostname = (req.headers.host || 'localhost').split(':')[0];
380384

381385
try {

app/model/mcp_server.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,5 @@ module.exports = (app) => {
233233
return values;
234234
};
235235

236-
237236
return McpServer;
238237
};

app/router.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,17 @@ module.exports = (app) => {
135135
app.post('/api/mcp-servers/use', app.controller.mcp.incrementUseCount);
136136
app.get('/api/mcp-servers/tags/popular', app.controller.mcp.getPopularTags);
137137
app.get('/api/mcp-servers/health', app.controller.mcp.checkMCPServerHealth);
138-
138+
139139
// MCP服务器生命周期管理
140140
app.post('/api/mcp-servers/start', app.controller.mcp.startMCPServer);
141141
app.post('/api/mcp-servers/stop', app.controller.mcp.stopMCPServer);
142142
app.post('/api/mcp-servers/restart', app.controller.mcp.restartMCPServer);
143143
app.post('/api/mcp-servers/sync-info', app.controller.mcp.syncMCPServerInfo);
144-
144+
145145
// MCP服务器健康检查路由
146146
app.post('/api/mcp-servers/health/:serverId', app.controller.mcp.checkMCPServerHealth);
147147
app.post('/api/mcp-servers/health/all', app.controller.mcp.checkAllMCPServersHealth);
148148

149-
150149
// io.of('/').route('getShellCommand', io.controller.home.getShellCommand)
151150
// 暂时close Terminal相关功能
152151
// io.of('/').route('loginServer', io.controller.home.loginServer)

app/schedule/mcpHealthCheck.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ class MCPHealthCheck extends Subscription {
2222
*/
2323
async subscribe() {
2424
const { ctx } = this;
25-
25+
2626
try {
2727
ctx.logger.info('开始执行MCP服务器健康检查定时任务');
28-
28+
2929
// 调用服务方法检查所有服务器健康状态
3030
await ctx.service.mcp.checkAllServersHealth();
31-
31+
3232
ctx.logger.info('MCP服务器健康检查定时任务执行完成');
3333
} catch (error) {
3434
ctx.logger.error('MCP服务器健康检查定时任务执行失败:', error);

0 commit comments

Comments
 (0)