From 884efd87aab5070e12be226c275ecaff0d0266f5 Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Fri, 8 May 2026 20:05:20 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20mcps=20call=20?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 --timeout 选项,以秒为单位覆盖 SDK 默认 60s 超时。 变更文件: - src/commands/call.ts: 添加 --timeout CLI 选项 - src/commands/daemon.ts: /call handler 透传 timeout - src/core/client.ts: callTool() 接收 timeout 参数 - src/core/daemon-client.ts: executeTool() 透传 timeout 用法:mcps call args... --timeout 180 Co-Authored-By: Claude Sonnet 4.5 --- src/commands/call.ts | 10 +++++++++- src/commands/daemon.ts | 4 ++-- src/core/client.ts | 5 +++-- src/core/daemon-client.ts | 4 ++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/commands/call.ts b/src/commands/call.ts index d29ff4c..25be236 100644 --- a/src/commands/call.ts +++ b/src/commands/call.ts @@ -76,6 +76,7 @@ export const registerCallCommand = (program: Command) => { .description('Call a tool on a server. Arguments format: key=value') .option('-r, --raw', 'Treat all values as raw strings (no JSON parsing)') .option('-j, --json ', 'Load parameters from a JSON file') + .option('-t, --timeout ', 'Request timeout in seconds (default: 60)') .addHelpText('after', ` Examples: $ mcps call my-server echo message="Hello World" @@ -89,11 +90,15 @@ Examples: # Use --json to load parameters from a file $ mcps call my-server createUser --json params.json + # Use --timeout to set custom request timeout (in seconds) + $ mcps call my-server download_label order_id="123" --timeout 180 + Notes: - Arguments are parsed as key=value pairs. - By default, values are automatically parsed as JSON if possible (numbers, booleans, objects). - Use --raw to disable JSON parsing and treat all values as strings. - Use --json to load parameters from a JSON file or JSON string. + - Use --timeout to override the default 60s request timeout. - For strings with spaces, wrap the value in quotes (e.g., msg="hello world"). `) .action(async (serverName, toolName, args, options) => { @@ -122,8 +127,11 @@ Notes: // Auto-start daemon if needed await DaemonClient.ensureDaemon(); + // Parse timeout option (convert seconds to ms for SDK) + const timeout = options.timeout ? parseInt(options.timeout as string, 10) * 1000 : undefined; + // Execute via daemon - const result = await DaemonClient.executeTool(serverName, toolName, params); + const result = await DaemonClient.executeTool(serverName, toolName, params, timeout); console.log(chalk.green('Tool execution successful:')); printResult(result); diff --git a/src/commands/daemon.ts b/src/commands/daemon.ts index 13fdb56..f594816 100644 --- a/src/commands/daemon.ts +++ b/src/commands/daemon.ts @@ -600,7 +600,7 @@ const startDaemon = (port: number) => { req.on('data', chunk => { body += chunk.toString(); }); req.on('end', async () => { try { - const { server: serverName, tool, args } = JSON.parse(body); + const { server: serverName, tool, args, timeout } = JSON.parse(body); if (!serverName || !tool) { res.writeHead(400, { 'Content-Type': 'application/json' }); @@ -609,7 +609,7 @@ const startDaemon = (port: number) => { } const client = await connectionPool.getClient(serverName); - const result = await client.callTool(tool, args || {}); + const result = await client.callTool(tool, args || {}, timeout); res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ result })); diff --git a/src/core/client.ts b/src/core/client.ts index da14516..80420da 100644 --- a/src/core/client.ts +++ b/src/core/client.ts @@ -241,16 +241,17 @@ export class McpClientService { return this.client.listTools(); } - async callTool(toolName: string, args: any) { + async callTool(toolName: string, args: any, timeout?: number) { if (!this.client) throw new Error('Client not connected'); // 记录工具调用请求 log(`[Tool Request] Server: ${this.serverName}, Tool: ${toolName}, Args: ${JSON.stringify(args)}`); + const options = timeout !== undefined ? { timeout } : undefined; const result = await this.client.callTool({ name: toolName, arguments: args, - }); + }, undefined, options); // 记录工具调用响应 log(`[Tool Response] Server: ${this.serverName}, Tool: ${toolName}, Result: ${JSON.stringify(result)}`); diff --git a/src/core/daemon-client.ts b/src/core/daemon-client.ts index 98b5f35..faa21fc 100644 --- a/src/core/daemon-client.ts +++ b/src/core/daemon-client.ts @@ -48,11 +48,11 @@ export class DaemonClient { await this.startDaemon(timeout); } - static async executeTool(serverName: string, toolName: string, args: any) { + static async executeTool(serverName: string, toolName: string, args: any, timeout?: number) { const response = await fetch(`${DAEMON_BASE_URL}/call`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ server: serverName, tool: toolName, args }), + body: JSON.stringify({ server: serverName, tool: toolName, args, timeout }), }); if (!response.ok) { From cf250c931a81c55fd1d37e76cad5f481637ab04e Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Fri, 8 May 2026 20:05:24 +0800 Subject: [PATCH 2/4] 1.7.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index b26e559..870d424 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@maplezzk/mcps", - "version": "1.6.7", + "version": "1.7.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@maplezzk/mcps", - "version": "1.6.7", + "version": "1.7.0", "license": "ISC", "dependencies": { "@modelcontextprotocol/sdk": "^1.25.3", diff --git a/package.json b/package.json index a02b148..511e20f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@maplezzk/mcps", - "version": "1.6.7", + "version": "1.7.0", "description": "A CLI to manage and use MCP servers", "publishConfig": { "access": "public" From 9617bd2095e38372a098e01e29627766d38e88a3 Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Fri, 8 May 2026 20:12:25 +0800 Subject: [PATCH 3/4] =?UTF-8?q?docs:=20=E8=A1=A5=E5=85=85=20--timeout=20?= =?UTF-8?q?=E9=80=89=E9=A1=B9=E4=BD=BF=E7=94=A8=E8=AF=B4=E6=98=8E=E5=88=B0?= =?UTF-8?q?=20README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.5 --- README.md | 11 ++++++++++- README.zh.md | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c1f48f5..2d10e57 100644 --- a/README.md +++ b/README.md @@ -218,7 +218,7 @@ mcps call [options] [arguments...] - ``: Name of the configured MCP server - ``: Name of the tool to call -- `[options]`: Optional flags (`--raw`, `--json`) +- `[options]`: Optional flags (`--raw`, `--json`, `--timeout`) - `[arguments...]`: Arguments passed as `key=value` pairs **Options:** @@ -227,6 +227,7 @@ mcps call [options] [arguments...] |--------|-------------| | `-r, --raw` | Treat all values as raw strings (disable JSON parsing) | | `-j, --json ` | Load parameters from JSON string or file | +| `-t, --timeout ` | Request timeout in seconds (default: 60) | **Default Mode (Auto JSON Parsing):** @@ -262,6 +263,14 @@ mcps call alibaba-dms createDataChangeOrder --raw \ # Sends: { "database_id": "36005357", "script": "...", "logic": "true" } ``` +**--timeout Mode (Custom Timeout):** + +Use `--timeout` to override the default 60-second request timeout for long-running tools: +```bash +# Set a 3-minute timeout for a slow tool +mcps call my-server download_label order_id="123" --timeout 180 +``` + **--json Mode (Complex Parameters):** For complex parameters, use `--json` to load from a JSON string or file: diff --git a/README.zh.md b/README.zh.md index 8a43b75..64dd0d6 100644 --- a/README.zh.md +++ b/README.zh.md @@ -219,7 +219,7 @@ mcps call [options] [arguments...] - ``: 已配置的 MCP 服务名称 - ``: 要调用的工具名称 -- `[options]`: 可选参数(`--raw`, `--json`) +- `[options]`: 可选参数(`--raw`, `--json`, `--timeout`) - `[arguments...]`: 以 `key=value` 形式传递的参数 **选项:** @@ -228,6 +228,7 @@ mcps call [options] [arguments...] |------|------| | `-r, --raw` | 将所有值作为原始字符串处理(禁用 JSON 解析) | | `-j, --json ` | 从 JSON 字符串或文件加载参数 | +| `-t, --timeout ` | 请求超时时间(秒),默认 60 | **默认模式(自动 JSON 解析):** @@ -263,6 +264,14 @@ mcps call alibaba-dms createDataChangeOrder --raw \ # 实际发送: { "database_id": "36005357", "script": "...", "logic": "true" } ``` +**--timeout 模式(自定义超时):** + +使用 `--timeout` 覆盖默认的 60 秒请求超时,适用于长时间运行的工具: +```bash +# 设 3 分钟超时 +mcps call my-server download_label order_id="123" --timeout 180 +``` + **--json 模式(复杂参数):** 对于复杂参数,使用 `--json` 从 JSON 字符串或文件加载: From ff8a3f11513ba144ac3575db84b05c68d22ffcad Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Fri, 8 May 2026 20:18:43 +0800 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20=E9=BB=98=E8=AE=A4=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E6=94=B9=E4=B8=BA=20300=20=E7=A7=92=EF=BC=885=20?= =?UTF-8?q?=E5=88=86=E9=92=9F=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - --timeout 不传时默认 300s 而非 SDK 的 60s - 更新 README 文档 Co-Authored-By: Claude Sonnet 4.5 --- README.md | 4 ++-- README.zh.md | 4 ++-- src/commands/call.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2d10e57..7157339 100644 --- a/README.md +++ b/README.md @@ -227,7 +227,7 @@ mcps call [options] [arguments...] |--------|-------------| | `-r, --raw` | Treat all values as raw strings (disable JSON parsing) | | `-j, --json ` | Load parameters from JSON string or file | -| `-t, --timeout ` | Request timeout in seconds (default: 60) | +| `-t, --timeout ` | Request timeout in seconds (default: 300) | **Default Mode (Auto JSON Parsing):** @@ -265,7 +265,7 @@ mcps call alibaba-dms createDataChangeOrder --raw \ **--timeout Mode (Custom Timeout):** -Use `--timeout` to override the default 60-second request timeout for long-running tools: +Use `--timeout` to override the default 300-second (5-minute) request timeout for long-running tools: ```bash # Set a 3-minute timeout for a slow tool mcps call my-server download_label order_id="123" --timeout 180 diff --git a/README.zh.md b/README.zh.md index 64dd0d6..5159931 100644 --- a/README.zh.md +++ b/README.zh.md @@ -228,7 +228,7 @@ mcps call [options] [arguments...] |------|------| | `-r, --raw` | 将所有值作为原始字符串处理(禁用 JSON 解析) | | `-j, --json ` | 从 JSON 字符串或文件加载参数 | -| `-t, --timeout ` | 请求超时时间(秒),默认 60 | +| `-t, --timeout ` | 请求超时时间(秒),默认 300(5分钟) | **默认模式(自动 JSON 解析):** @@ -266,7 +266,7 @@ mcps call alibaba-dms createDataChangeOrder --raw \ **--timeout 模式(自定义超时):** -使用 `--timeout` 覆盖默认的 60 秒请求超时,适用于长时间运行的工具: +使用 `--timeout` 覆盖默认的 300 秒(5分钟)请求超时,适用于长时间运行的工具: ```bash # 设 3 分钟超时 mcps call my-server download_label order_id="123" --timeout 180 diff --git a/src/commands/call.ts b/src/commands/call.ts index 25be236..11e73ce 100644 --- a/src/commands/call.ts +++ b/src/commands/call.ts @@ -127,8 +127,8 @@ Notes: // Auto-start daemon if needed await DaemonClient.ensureDaemon(); - // Parse timeout option (convert seconds to ms for SDK) - const timeout = options.timeout ? parseInt(options.timeout as string, 10) * 1000 : undefined; + // Parse timeout option (convert seconds to ms for SDK, default 5min = 300s) + const timeout = (options.timeout ? parseInt(options.timeout as string, 10) : 300) * 1000; // Execute via daemon const result = await DaemonClient.executeTool(serverName, toolName, params, timeout);