Skip to content
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

Compatibility with other mcp servers issue. #4

Open
Nickonomic opened this issue Dec 30, 2024 · 1 comment
Open

Compatibility with other mcp servers issue. #4

Nickonomic opened this issue Dec 30, 2024 · 1 comment

Comments

@Nickonomic
Copy link

Nickonomic commented Dec 30, 2024

A rather peculiar issue here: I can't make any-chat-completions work alongside mcp-notion-server. This is true for both Claude Desktop and my mcp client. Somehow it depends on the order of initialization of tools.

If I run: uv run python -m mcpcli --telegram --server chat-perplexity --server notion --server filesystem --server todoist, chat-perplexity works normally but notion server fails as all calls to it are being captured by chat-perplexity.
If I run : uv run python -m mcpcli --telegram --server notion --server chat-perplexity --server filesystem --server todoist, notion works fine but chat-perplexity fails as all calls to it are being captured by notion.

I'm specifically including other servers here because they seem to be completely unaffected by this conflict of chat-perplexity and notion. That is, they work fine with either of the two.

Have you any idea of what's happening?

@Nickonomic
Copy link
Author

I think I've found the solution to the conflict between any-chat-completions-mcp and other MCP servers (like Notion). The issue is in how unknown tools are handled.

Current code in any-chat-completions-mcp:

switch (request.params.name) {
  case `chat-with-${AI_CHAT_NAME_CLEAN}`: {
    // ... handler code ...
  }
  default:
    throw new Error("Unknown tool");  // This breaks tool routing
}

When running alongside other MCP servers, throwing an error for unknown tools causes the MCP protocol to stop trying other servers. The fix is to return proper error responses:

server.setRequestHandler(CallToolRequestSchema, async (request) => {
  try {
    const { name, arguments: args } = request.params;
    
    if (name === `chat-with-${AI_CHAT_NAME_CLEAN}`) {
      if (!args?.content) {
        throw new Error("Content is required");
      }

      const content = String(args.content);
      
      const client = new OpenAI({
        apiKey: AI_CHAT_KEY,
        baseURL: AI_CHAT_BASE_URL,
      });

      const chatCompletion = await client.chat.completions.create({
        messages: [{ role: 'user', content: content }],
        model: AI_CHAT_MODEL,
      });

      return {
        content: [
          {
            type: "text",
            text: chatCompletion.choices[0]?.message?.content || "No response"
          }
        ],
        isError: false
      };
    }

    // For any other tool, return error response instead of throwing
    return {
      content: [{ type: "text", text: `Unknown tool: ${name}` }],
      isError: true
    };
  } catch (error) {
    return {
      content: [
        {
          type: "text",
          text: `Error: ${error instanceof Error ? error.message : String(error)}`
        }
      ],
      isError: true
    };
  }
});

Key changes:

  1. Return error responses with isError: true instead of throwing errors
  2. Include descriptive error messages
  3. Add proper error handling for all cases

The fix follows the MCP protocol's expected behavior for tool routing, where servers should signal they can't handle a tool through error responses rather than throwing errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant