Skip to content

[BUG] Tool invocation returns 'Invalid method' error after PR #746 #753

@crivetimihai

Description

@crivetimihai

Problem

After PR #746, tool invocations through the RPC endpoint fail with an 'Invalid method' error when using the traditional format where the tool name is used directly as the method.

Error Response

{
  "jsonrpc": "2.0",
  "error": {
    "code": -32000,
    "message": "Invalid method",
    "data": {
      "query": "test",
      "limit": 5
    }
  },
  "id": 1755258291346
}

Root Cause

PR #746 introduced a breaking change in how tools are invoked via the RPC endpoint:

Before PR #746

Tools could be invoked directly using the tool name as the method:

{
  "jsonrpc": "2.0",
  "method": "my_tool_name",
  "params": {
    "arg1": "value1"
  }
}

After PR #746

Tools must now be invoked using the tools/call method with the tool name in parameters:

{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "name": "my_tool_name",
    "arguments": {
      "arg1": "value1"
    }
  }
}

Impact

This breaking change affects all existing clients that invoke tools using the old format, causing them to receive 'Invalid method' errors.

Solution Implemented

Added backward compatibility support in mcpgateway/main.py (lines 2320-2336) that:

  1. Attempts to invoke unknown methods as tools directly (supporting old format)
  2. Falls back to gateway forwarding if not a tool
  3. Only returns 'Invalid method' error if both attempts fail

This allows both formats to work:

  • Old format: method: "tool_name" with params as arguments
  • New format: method: "tools/call" with tool name and arguments in params

Test Coverage

Created comprehensive test suites:

  • tests/unit/mcpgateway/test_rpc_tool_invocation.py - Tests for new format and RPC methods
  • tests/unit/mcpgateway/test_rpc_backward_compatibility.py - Tests for backward compatibility

All tests pass, confirming both formats work correctly.

Recommendation

Consider documenting this change in the migration guide or changelog to help users transition from the old to the new format while maintaining backward compatibility.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions