-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathmcp-tool-args.test.ts
More file actions
89 lines (79 loc) · 2.49 KB
/
Copy pathmcp-tool-args.test.ts
File metadata and controls
89 lines (79 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { describe, expect, it } from "bun:test";
import type { CustomToolContext } from "@oh-my-pi/pi-coding-agent/extensibility/custom-tools";
import { DeferredMCPTool, MCPTool, type MCPToolDefinition } from "@oh-my-pi/pi-coding-agent/mcp";
import type { MCPServerConnection } from "@oh-my-pi/pi-coding-agent/mcp/types";
import { createMockConnection, createMockTransport } from "./mcp-test-utils";
type CapturedRequest = {
method: string;
params: Record<string, unknown> | undefined;
};
const unusedContext = {} as CustomToolContext;
function createSearchToolDefinition(): MCPToolDefinition {
return {
name: "search",
description: "Search symbols or file locations",
inputSchema: {
type: "object",
properties: {
symbol: { type: "string" },
language: { type: "string" },
file: { type: "string" },
line: { type: "number" },
column: { type: "number" },
filters: { type: "object" },
exact: { type: "boolean" },
},
required: ["symbol", "language"],
},
};
}
function createCapturedConnection(calls: CapturedRequest[]): MCPServerConnection {
const transport = createMockTransport(
new Map([["tools/call", [{ content: [{ type: "text", text: "ok" }] }]]]),
(method, params) => calls.push({ method, params }),
);
return createMockConnection({ tools: {} }, transport);
}
describe("MCP tool arguments", () => {
it("omits optional empty placeholders before tools/call", async () => {
const calls: CapturedRequest[] = [];
const tool = new MCPTool(createCapturedConnection(calls), createSearchToolDefinition());
await tool.execute(
"call-1",
{ symbol: "Foo", language: "", file: "", line: 0, filters: {}, exact: false },
undefined,
unusedContext,
undefined,
);
expect(calls).toEqual([
{
method: "tools/call",
params: {
name: "search",
arguments: { symbol: "Foo", language: "", line: 0, exact: false },
},
},
]);
});
it("omits optional empty placeholders for deferred MCP tools", async () => {
const calls: CapturedRequest[] = [];
const connection = createCapturedConnection(calls);
const tool = new DeferredMCPTool("intellij-index", createSearchToolDefinition(), async () => connection);
await tool.execute(
"call-1",
{ symbol: "Foo", language: "TypeScript", file: "", column: "", filters: {} },
undefined,
unusedContext,
undefined,
);
expect(calls).toEqual([
{
method: "tools/call",
params: {
name: "search",
arguments: { symbol: "Foo", language: "TypeScript" },
},
},
]);
});
});