Closed
Description
I'm working with the new Agent framework and building an MCP client by extending the Agent class within a Durable Object, something like this:
export class MCP extends Agent<Env, never> {
mcp = new MCPClientManager("my-agent", "1.0.0");
async fetch(request: Request) {
return (
(await routeAgentRequest(request, this.env, { cors: true })) ||
new Response("Not found", { status: 404 })
);
}
async onRequest(request: Request): Promise<Response> {
const reqUrl = new URL(request.url);
if (reqUrl.pathname.endsWith("add-mcp") && request.method === "POST") {
await this.addMcpServer("Slack", "http://localhost:8000/sse", "http://localhost:8787");
return new Response("Ok", { status: 200 });
}
return new Response("Not found", { status: 404 });
}
async listTools() {
return this.mcp.listTools();
}
async getServerId() {
const tools = await this.mcp.listTools();
return tools[0].serverId;
}
async callTool(toolName: string, args?: { [x: string]: unknown }) {
return this.mcp.callTool({
name: toolName,
serverId: await this.getServerId(),
arguments: args
});
}
}
I want to call the addMcpServer method from my Hono route (i.e., remotely invoke it via RPC).
Metadata
Metadata
Assignees
Labels
No labels