Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,11 @@ git commit -m "feat: 你的功能描述"
# git cherry-pick <commit-hash> # 将提交移到新分支
```

### 3. 更新版本号(如需要)
### 3. 更新版本号(必须)

```bash
# ⚠️ 必须使用 npm version 命令,禁止手动修改 package.json
# ⚠️ 每次修改都必须更新版本号,无论功能大小!

# Patch 版本(bug 修复)
npm version patch
Expand Down Expand Up @@ -210,7 +211,7 @@ gh pr create --title "feat: 功能标题" --body "PR 描述"
- ✅ 从最新 `main` 分支创建的功能分支
- ✅ 代码已提交到功能分支(非 main 分支)
- ✅ **新功能包含对应的单元测试**
- ✅ **版本号已使用 `npm version` 更新(如需要发布)**
- ✅ **版本号已使用 `npm version` 更新(每次修改都必须更新!)**
- ✅ **`npm run build` TypeScript 编译成功**
- ✅ `npm test` 所有测试通过
- ✅ 提交信息符合规范
Expand Down Expand Up @@ -268,7 +269,7 @@ git commit -m "feat: 新增 xxx 功能

Co-Authored-By: xxx"

# 6. 更新版本号(如需要发布)
# 6. ⚠️ 必须更新版本号(每次修改都要更新!)
npm version minor # 或 patch / major

# 7. 推送分支和标签
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
11 changes: 10 additions & 1 deletion src/core/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
73 changes: 73 additions & 0 deletions src/tests/unit/call-logging.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
});