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. 推送分支和标签 diff --git a/package-lock.json b/package-lock.json index 73aa397..ac7e716 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@maplezzk/mcps", - "version": "1.5.0", + "version": "1.6.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@maplezzk/mcps", - "version": "1.5.0", + "version": "1.6.2", "license": "ISC", "dependencies": { "@modelcontextprotocol/sdk": "^1.25.3", diff --git a/package.json b/package.json index 2488d2a..085b340 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@maplezzk/mcps", - "version": "1.5.0", + "version": "1.6.2", "description": "A CLI to manage and use MCP servers", "publishConfig": { "access": "public" diff --git a/src/core/client.ts b/src/core/client.ts index 6e0ff0e..99137e4 100644 --- a/src/core/client.ts +++ b/src/core/client.ts @@ -225,10 +225,19 @@ export class McpClientService { async callTool(toolName: string, args: any) { if (!this.client) throw new Error('Client not connected'); - return this.client.callTool({ + + // 记录工具调用请求 + log(`[Tool Request] Server: ${this.serverName}, Tool: ${toolName}, Args: ${JSON.stringify(args)}`); + + const result = await this.client.callTool({ name: toolName, arguments: args, }); + + // 记录工具调用响应 + 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..cffdda4 --- /dev/null +++ b/src/tests/unit/call-logging.test.ts @@ -0,0 +1,73 @@ +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'); + }); + + it('should log by default without MCPS_VERBOSE environment variable', () => { + // 确保 MCPS_VERBOSE 未设置时也默认记录日志 + delete process.env.MCPS_VERBOSE; + + // 日志记录不依赖 MCPS_VERBOSE 环境变量 + const serverName = 'test-server'; + const toolName = 'test_tool'; + const args = { test: 'value' }; + + // 无论 MCPS_VERBOSE 是否设置,都应该记录日志 + const message = `[Tool Request] Server: ${serverName}, Tool: ${toolName}, Args: ${JSON.stringify(args)}`; + + expect(message).toBeDefined(); + }); + }); +});