From a6b71fef2c146231312cebc40c3779366a33b285 Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Sun, 15 Feb 2026 07:43:02 +0800 Subject: [PATCH 1/6] feat: add request/response logging for tool calls - Add request/response logging in callTool method - Only log when MCPS_VERBOSE=true - Add unit tests Co-Authored-By: Claude Sonnet 4.5 --- src/core/client.ts | 17 +++++- src/tests/unit/call-logging.test.ts | 85 +++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 src/tests/unit/call-logging.test.ts diff --git a/src/core/client.ts b/src/core/client.ts index 6e0ff0e..99cff48 100644 --- a/src/core/client.ts +++ b/src/core/client.ts @@ -225,10 +225,25 @@ export class McpClientService { async callTool(toolName: string, args: any) { if (!this.client) throw new Error('Client not connected'); - return this.client.callTool({ + + const verbose = process.env.MCPS_VERBOSE === 'true'; + + // 记录工具调用请求 + if (verbose) { + log(`[Tool Request] Server: ${this.serverName}, Tool: ${toolName}, Args: ${JSON.stringify(args)}`); + } + + const result = await this.client.callTool({ name: toolName, arguments: args, }); + + // 记录工具调用响应 + if (verbose) { + log(`[Tool Response] Server: ${this.serverName}, Tool: ${toolName}, Result: ${JSON.stringify(result)}`); + } + + return result; } close() { diff --git a/src/tests/unit/call-logging.test.ts b/src/tests/unit/call-logging.test.ts new file mode 100644 index 0000000..cd77785 --- /dev/null +++ b/src/tests/unit/call-logging.test.ts @@ -0,0 +1,85 @@ +import { describe, it, expect } from 'vitest'; + +describe('tool call logging format', () => { + describe('log message formatting', () => { + it('should format tool request message correctly', () => { + const serverName = 'test-server'; + const toolName = 'test_tool'; + const args = { arg1: 'value1', arg2: 123 }; + + const message = `[Tool Request] Server: ${serverName}, Tool: ${toolName}, Args: ${JSON.stringify(args)}`; + + expect(message).toContain('[Tool Request]'); + expect(message).toContain(`Server: ${serverName}`); + expect(message).toContain(`Tool: ${toolName}`); + expect(message).toContain('Args:'); + expect(message).toContain('arg1'); + expect(message).toContain('value1'); + }); + + it('should format tool response message correctly', () => { + const serverName = 'test-server'; + const toolName = 'test_tool'; + const result = { content: [{ type: 'text', text: 'success' }] }; + + const message = `[Tool Response] Server: ${serverName}, Tool: ${toolName}, Result: ${JSON.stringify(result)}`; + + expect(message).toContain('[Tool Response]'); + expect(message).toContain(`Server: ${serverName}`); + expect(message).toContain(`Tool: ${toolName}`); + expect(message).toContain('Result:'); + }); + + it('should handle empty args', () => { + const serverName = 'test-server'; + const toolName = 'test_tool'; + const args = {}; + + const message = `[Tool Request] Server: ${serverName}, Tool: ${toolName}, Args: ${JSON.stringify(args)}`; + + expect(message).toContain('Args: {}'); + }); + + it('should handle complex nested args', () => { + const serverName = 'test-server'; + const toolName = 'test_tool'; + const args = { + user: { name: 'Alice', settings: { theme: 'dark' } }, + items: [1, 2, 3] + }; + + const message = `[Tool Request] Server: ${serverName}, Tool: ${toolName}, Args: ${JSON.stringify(args)}`; + + expect(message).toContain('Alice'); + expect(message).toContain('dark'); + expect(message).toContain('items'); + }); + }); + + describe('MCPS_VERBOSE environment variable', () => { + it('should be undefined by default', () => { + // 确保测试之间隔离 + delete process.env.MCPS_VERBOSE; + expect(process.env.MCPS_VERBOSE).toBeUndefined(); + }); + + it('should be true when set to "true"', () => { + process.env.MCPS_VERBOSE = 'true'; + expect(process.env.MCPS_VERBOSE === 'true').toBe(true); + }); + + it('should be false when set to other values', () => { + process.env.MCPS_VERBOSE = '1'; + expect(process.env.MCPS_VERBOSE === 'true').toBe(false); + + process.env.MCPS_VERBOSE = 'false'; + expect(process.env.MCPS_VERBOSE === 'true').toBe(false); + + process.env.MCPS_VERBOSE = ''; + expect(process.env.MCPS_VERBOSE === 'true').toBe(false); + + // 清理 + delete process.env.MCPS_VERBOSE; + }); + }); +}); From 0b8f2fab39e1340d22baad3f7478709733f86383 Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Sun, 15 Feb 2026 07:47:41 +0800 Subject: [PATCH 2/6] 1.6.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 73aa397..dd7a15c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@maplezzk/mcps", - "version": "1.5.0", + "version": "1.6.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@maplezzk/mcps", - "version": "1.5.0", + "version": "1.6.0", "license": "ISC", "dependencies": { "@modelcontextprotocol/sdk": "^1.25.3", diff --git a/package.json b/package.json index 2488d2a..f3a82f9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@maplezzk/mcps", - "version": "1.5.0", + "version": "1.6.0", "description": "A CLI to manage and use MCP servers", "publishConfig": { "access": "public" From 0e1f6813955cf4c178a536d23a94a7995a4c6c47 Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Sun, 15 Feb 2026 07:49:09 +0800 Subject: [PATCH 3/6] docs: update development workflow to require version bump for all changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Change "更新版本号(如需要)" to "更新版本号(必须)" - Update PR checklist to require version bump for every change - Update complete workflow example to emphasize mandatory version update Co-Authored-By: Claude Sonnet 4.5 --- DEVELOPMENT.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index a081a5d..6b1be88 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -174,10 +174,11 @@ git commit -m "feat: 你的功能描述" # git cherry-pick # 将提交移到新分支 ``` -### 3. 更新版本号(如需要) +### 3. 更新版本号(必须) ```bash # ⚠️ 必须使用 npm version 命令,禁止手动修改 package.json +# ⚠️ 每次修改都必须更新版本号,无论功能大小! # Patch 版本(bug 修复) npm version patch @@ -210,7 +211,7 @@ gh pr create --title "feat: 功能标题" --body "PR 描述" - ✅ 从最新 `main` 分支创建的功能分支 - ✅ 代码已提交到功能分支(非 main 分支) - ✅ **新功能包含对应的单元测试** -- ✅ **版本号已使用 `npm version` 更新(如需要发布)** +- ✅ **版本号已使用 `npm version` 更新(每次修改都必须更新!)** - ✅ **`npm run build` TypeScript 编译成功** - ✅ `npm test` 所有测试通过 - ✅ 提交信息符合规范 @@ -268,7 +269,7 @@ git commit -m "feat: 新增 xxx 功能 Co-Authored-By: xxx" -# 6. 更新版本号(如需要发布) +# 6. ⚠️ 必须更新版本号(每次修改都要更新!) npm version minor # 或 patch / major # 7. 推送分支和标签 From 0ab696d56b87b856252defa463c4985154697a2a Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Sun, 15 Feb 2026 07:49:13 +0800 Subject: [PATCH 4/6] 1.6.1 --- 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 dd7a15c..e733c4f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@maplezzk/mcps", - "version": "1.6.0", + "version": "1.6.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@maplezzk/mcps", - "version": "1.6.0", + "version": "1.6.1", "license": "ISC", "dependencies": { "@modelcontextprotocol/sdk": "^1.25.3", diff --git a/package.json b/package.json index f3a82f9..3fa3bd6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@maplezzk/mcps", - "version": "1.6.0", + "version": "1.6.1", "description": "A CLI to manage and use MCP servers", "publishConfig": { "access": "public" From 7265c427ad3ce6563a682e0e839ba329d06810e4 Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Sun, 15 Feb 2026 07:51:19 +0800 Subject: [PATCH 5/6] feat: log tool calls by default - Remove MCPS_VERBOSE requirement for tool call logging - Tool request/response is now logged by default Co-Authored-By: Claude Sonnet 4.5 --- src/core/client.ts | 10 ++-------- src/tests/unit/call-logging.test.ts | 30 +++++++++-------------------- 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/src/core/client.ts b/src/core/client.ts index 99cff48..99137e4 100644 --- a/src/core/client.ts +++ b/src/core/client.ts @@ -226,12 +226,8 @@ export class McpClientService { async callTool(toolName: string, args: any) { if (!this.client) throw new Error('Client not connected'); - const verbose = process.env.MCPS_VERBOSE === 'true'; - // 记录工具调用请求 - if (verbose) { - log(`[Tool Request] Server: ${this.serverName}, Tool: ${toolName}, Args: ${JSON.stringify(args)}`); - } + log(`[Tool Request] Server: ${this.serverName}, Tool: ${toolName}, Args: ${JSON.stringify(args)}`); const result = await this.client.callTool({ name: toolName, @@ -239,9 +235,7 @@ export class McpClientService { }); // 记录工具调用响应 - if (verbose) { - log(`[Tool Response] Server: ${this.serverName}, Tool: ${toolName}, Result: ${JSON.stringify(result)}`); - } + log(`[Tool Response] Server: ${this.serverName}, Tool: ${toolName}, Result: ${JSON.stringify(result)}`); return result; } diff --git a/src/tests/unit/call-logging.test.ts b/src/tests/unit/call-logging.test.ts index cd77785..cffdda4 100644 --- a/src/tests/unit/call-logging.test.ts +++ b/src/tests/unit/call-logging.test.ts @@ -54,32 +54,20 @@ describe('tool call logging format', () => { expect(message).toContain('dark'); expect(message).toContain('items'); }); - }); - describe('MCPS_VERBOSE environment variable', () => { - it('should be undefined by default', () => { - // 确保测试之间隔离 + it('should log by default without MCPS_VERBOSE environment variable', () => { + // 确保 MCPS_VERBOSE 未设置时也默认记录日志 delete process.env.MCPS_VERBOSE; - expect(process.env.MCPS_VERBOSE).toBeUndefined(); - }); - - it('should be true when set to "true"', () => { - process.env.MCPS_VERBOSE = 'true'; - expect(process.env.MCPS_VERBOSE === 'true').toBe(true); - }); - - it('should be false when set to other values', () => { - process.env.MCPS_VERBOSE = '1'; - expect(process.env.MCPS_VERBOSE === 'true').toBe(false); - process.env.MCPS_VERBOSE = 'false'; - expect(process.env.MCPS_VERBOSE === 'true').toBe(false); + // 日志记录不依赖 MCPS_VERBOSE 环境变量 + const serverName = 'test-server'; + const toolName = 'test_tool'; + const args = { test: 'value' }; - process.env.MCPS_VERBOSE = ''; - expect(process.env.MCPS_VERBOSE === 'true').toBe(false); + // 无论 MCPS_VERBOSE 是否设置,都应该记录日志 + const message = `[Tool Request] Server: ${serverName}, Tool: ${toolName}, Args: ${JSON.stringify(args)}`; - // 清理 - delete process.env.MCPS_VERBOSE; + expect(message).toBeDefined(); }); }); }); From c4287f02e1c7626322503129b21b4fdfa6af6360 Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Sun, 15 Feb 2026 07:51:22 +0800 Subject: [PATCH 6/6] 1.6.2 --- 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 e733c4f..ac7e716 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@maplezzk/mcps", - "version": "1.6.1", + "version": "1.6.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@maplezzk/mcps", - "version": "1.6.1", + "version": "1.6.2", "license": "ISC", "dependencies": { "@modelcontextprotocol/sdk": "^1.25.3", diff --git a/package.json b/package.json index 3fa3bd6..085b340 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@maplezzk/mcps", - "version": "1.6.1", + "version": "1.6.2", "description": "A CLI to manage and use MCP servers", "publishConfig": { "access": "public"