Skip to content

Registering multiple tools or resources fails #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
atroyn opened this issue Jan 21, 2025 · 1 comment · Fixed by #126
Closed

Registering multiple tools or resources fails #124

atroyn opened this issue Jan 21, 2025 · 1 comment · Fixed by #126
Assignees
Labels
bug Something isn't working

Comments

@atroyn
Copy link

atroyn commented Jan 21, 2025

Describe the bug
Registering a second resource or tool fails with:

Error: A request handler for tools/list already exists, which would be overridden
    at Server.assertCanSetRequestHandler (/Users/antontroynikov/Projects/CascadeProjects/panopticon/node_modules/@modelcontextprotocol/sdk/src/shared/protocol.ts:521:13)
    at McpServer.setToolRequestHandlers (/Users/antontroynikov/Projects/CascadeProjects/panopticon/node_modules/@modelcontextprotocol/sdk/src/server/mcp.ts:85:17)
    at McpServer.tool (/Users/antontroynikov/Projects/CascadeProjects/panopticon/node_modules/@modelcontextprotocol/sdk/src/server/mcp.ts:536:10)
    at Object.<anonymous> (/Users/antontroynikov/Projects/CascadeProjects/panopticon/src/mcp/index.ts:19:8)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Module.m._compile (/Users/antontroynikov/Projects/CascadeProjects/panopticon/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/antontroynikov/Projects/CascadeProjects/panopticon/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1104:12)

To Reproduce

The following code in index.ts:

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";

// Create an MCP server
const server = new McpServer({
  name: "Demo",
  version: "1.0.0"
});

// Add an addition tool
server.tool("add",
  { a: z.number(), b: z.number() },
  async ({ a, b }) => ({
    content: [{ type: "text", text: String(a + b) }]
  })
);

// Simple tool with parameters
server.tool(
    "calculate-bmi",
    {
      weightKg: z.number(),
      heightM: z.number()
    },
    async ({ weightKg, heightM }) => ({
      content: [{
        type: "text",
        text: String(weightKg / (heightM * heightM))
      }]
    })
  );
  
  // Async tool with external API call
  server.tool(
    "fetch-weather",
    { city: z.string() },
    async ({ city }) => {
      const response = await fetch(`https://api.weather.com/${city}`);
      const data = await response.text();
      return {
        content: [{ type: "text", text: data }]
      };
    }
  );

Followed by npm run mcp

Expected behavior
It should run

@atroyn atroyn added the bug Something isn't working label Jan 21, 2025
@jspahrsummers jspahrsummers self-assigned this Jan 21, 2025
@jspahrsummers
Copy link
Member

Oops, that's embarrassing (and embarrassing we didn't have a test for it). Thanks for flagging—fix is up in #126, awaiting review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants