tools
This commit is contained in:
@@ -10,6 +10,10 @@ import {
|
||||
ListPromptsResultSchema,
|
||||
GetPromptResult,
|
||||
GetPromptResultSchema,
|
||||
ListToolsResult,
|
||||
ListToolsResultSchema,
|
||||
CallToolResult,
|
||||
CallToolResultSchema,
|
||||
} from "mcp-typescript/types.js";
|
||||
|
||||
export class McpClient {
|
||||
@@ -86,6 +90,29 @@ export class McpClient {
|
||||
);
|
||||
}
|
||||
|
||||
// Tool Operations
|
||||
async listTools(): Promise<ListToolsResult> {
|
||||
return await this.client.request(
|
||||
{
|
||||
method: "tools/list",
|
||||
},
|
||||
ListToolsResultSchema,
|
||||
);
|
||||
}
|
||||
|
||||
async callTool(
|
||||
name: string,
|
||||
params: Record<string, unknown>,
|
||||
): Promise<CallToolResult> {
|
||||
return await this.client.request(
|
||||
{
|
||||
method: "tools/call",
|
||||
params: { name, ...params },
|
||||
},
|
||||
CallToolResultSchema,
|
||||
);
|
||||
}
|
||||
|
||||
getServerCapabilities() {
|
||||
return this.client.getServerCapabilities();
|
||||
}
|
||||
|
||||
@@ -30,6 +30,19 @@ wss.on("connection", (ws: WebSocket) => {
|
||||
} else if (command.type === "getPrompt" && command.name) {
|
||||
const prompt = await mcpClient.getPrompt(command.name);
|
||||
ws.send(JSON.stringify({ type: "prompt", data: prompt }));
|
||||
} else if (command.type === "listTools") {
|
||||
const tools = await mcpClient.listTools();
|
||||
ws.send(JSON.stringify({ type: "tools", data: tools }));
|
||||
} else if (
|
||||
command.type === "callTool" &&
|
||||
command.name &&
|
||||
command.params
|
||||
) {
|
||||
const result = await mcpClient.callTool(
|
||||
command.name + "asdf",
|
||||
command.params,
|
||||
);
|
||||
ws.send(JSON.stringify({ type: "toolResult", data: result }));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
|
||||
Reference in New Issue
Block a user