Skip to content

Upgrade to FastMCP 2.0 and implement httpx monkey patch for agent compatibility #59

@aarora79

Description

@aarora79

Problem Description

When using MCP servers with the pydantic fastmcp 2.0 library (https://github.com/jlowin/fastmcp), there's a compatibility issue with the agent's httpx request handling. The FastMCP 2.0 library returns different SSE endpoint data compared to the Anthropic MCP Python SDK's FastMCP version.

Current Behavior

FastMCP 2.0 (jlowin/fastmcp):

root@049f308b152b:/app# curl http://127.0.0.1:8001/sse
event: endpoint
data: /messages/?session_id=e4bfbe6166884fddb43043cc9048239c

Anthropic SDK FastMCP:

root@f371d2be39c2:/app# curl http://127.0.0.1:8000/sse
event: endpoint
data: /currenttime/messages/?session_id=80aaaf4ed25c48258d3b7a2537bad54c

Issue

The key difference is that FastMCP 2.0 does not include the mount point (e.g., currenttime) in the endpoint data, while the Anthropic SDK version does. The agent relies on this mount point information to properly route requests.

Why FastMCP 2.0 is Preferred

Despite this compatibility issue, FastMCP 2.0 provides significant advantages:

  • Access to the Context object in MCP tools
  • Ability to access underlying HTTP request information
  • Support for auth headers and custom client information passed through headers

Required Changes

1. Agent-side httpx Monkey Patch

  • Implement monkey patching of the httpx request method on the agent side
  • Ensure the agent can properly handle FastMCP 2.0's endpoint format
  • Maintain compatibility with mount point routing

2. Server Updates

  • Update the fininfo server to use Pydantic FastMCP 2.0
  • Ensure all existing functionality is preserved
  • Leverage the new Context object capabilities where beneficial

3. Testing Requirements

  • Test with both currenttime and fininfo servers
  • Verify agent can communicate with both servers seamlessly
  • Ensure no regression in existing functionality

Sub-Issue: Build Script Improvements

The build_and_run.sh script needs the following updates:

  1. Registry Files Copy: Copy registry/servers/*.json files to /opt/mcpgateway/servers
  2. Faiss Index Cleanup: Delete faiss index files on every startup

These changes are needed as interim measures until true multi-tenancy is implemented for the gateway registry.

Acceptance Criteria

  • Agent successfully communicates with FastMCP 2.0 servers
  • Mount point routing works correctly with monkey-patched httpx
  • fininfo server upgraded to FastMCP 2.0
  • Context object integration implemented where applicable
  • Both currenttime and fininfo servers tested with agent
  • build_and_run.sh updated with registry file copying
  • Faiss index cleanup implemented in startup script
  • No regression in existing functionality

Labels

enhancement, bug, infrastructure

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions