Skip to content

refactor(gateway): migrate MCP implementation to ModelContextProtocol…#28

Open
GreenShadeZhang wants to merge 1 commit intoclawdotnet:mainfrom
GreenShadeZhang:dev_update_mcp
Open

refactor(gateway): migrate MCP implementation to ModelContextProtocol…#28
GreenShadeZhang wants to merge 1 commit intoclawdotnet:mainfrom
GreenShadeZhang:dev_update_mcp

Conversation

@GreenShadeZhang
Copy link
Contributor

Description

This PR refactors the Gateway MCP server implementation to use the official ModelContextProtocol C# SDK and removes the legacy hand-rolled JSON-RPC endpoint implementation.

Problems solved:

  • Reduces protocol maintenance burden from custom MCP routing/envelope handling.
  • Aligns Gateway MCP behavior with SDK-native MCP transport/capability handling.
  • Keeps the existing OpenClaw MCP capability surface (tools/resources/prompts) while simplifying implementation structure.
  • Preserves MCP auth and rate-limit protections on /mcp.

Key changes:

  • Replaced legacy Endpoints/McpEndpoints.cs with SDK-based MCP registration.
  • Added SDK-based MCP modules under Mcp:
    • OpenClawMcpTools
    • OpenClawMcpResources
    • OpenClawMcpPrompts
    • McpSdkExtensions
    • GatewayRuntimeHolder
  • Wired SDK route and middleware in Program.cs (MapMcp("/mcp"), MCP auth/rate-limit path).
  • Updated service registration and endpoint mappings to remove old MCP endpoint path.

AOT note:

  • Current SDK integration path relies on reflection-based discovery, so Gateway MCP is currently configured for non-AOT publishing in this refactor.

Related Issues

  • Contributes to MCP SDK migration effort in Gateway.
  • No direct issue number linked yet.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)

Checklist

  • I have read the CONTRIBUTING guidelines
  • My code follows the code style implementation of this project
  • I have added tests that prove my fix is effective or that my feature works
  • All new and existing tests passed locally (dotnet test)
  • I have updated the documentation (README.md, comments) if required
  • I have checked for security implications (input validation, authorization)

Validation performed:

  • dotnet build OpenClaw.Gateway.csproj -c Release

Screenshots (if applicable)

ScreenShot_2026-03-20_172722_491

Benchmarks (if applicable)

No benchmark run for this refactor.
Expected runtime impact is neutral to minor overhead differences depending on SDK transport internals.

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

Successfully merging this pull request may close these issues.

1 participant