refactor: share mcp api calls
This commit is contained in:
@@ -152,6 +152,33 @@ describe("MCP protocol unstableFilter", () => {
|
||||
expect(String(calledUrl)).toContain("unstableFilter=true");
|
||||
});
|
||||
|
||||
test("tools/call returns API JSON as text content", async () => {
|
||||
global.fetch = mock(() =>
|
||||
Promise.resolve(
|
||||
new Response(JSON.stringify([{ title: "item" }]), { status: 200 }),
|
||||
),
|
||||
) as unknown as typeof fetch;
|
||||
|
||||
const response = await handleMcpRequest(
|
||||
new Request("http://localhost", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
jsonrpc: "2.0",
|
||||
id: 1,
|
||||
method: "tools/call",
|
||||
params: {
|
||||
name: "search_facebook",
|
||||
arguments: { query: "laptop" },
|
||||
},
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
const body = await response.json();
|
||||
expect(body.result.content[0].type).toBe("text");
|
||||
expect(JSON.parse(body.result.content[0].text)).toEqual([{ title: "item" }]);
|
||||
});
|
||||
|
||||
test("handler should forward unstableFilter=true for search_ebay", async () => {
|
||||
await handleMcpRequest(
|
||||
new Request("http://localhost", {
|
||||
|
||||
Reference in New Issue
Block a user