Skip to content

Improve MCP server for MCP inspector#201

Merged
gophergogo merged 5 commits intomainfrom
fix/improve_for_mcp_inspector
Mar 20, 2026
Merged

Improve MCP server for MCP inspector#201
gophergogo merged 5 commits intomainfrom
fix/improve_for_mcp_inspector

Conversation

@bettercallsaulj
Copy link
Copy Markdown
Collaborator

No description provided.

RahulHere added 4 commits March 6, 2026 02:02
Add JsonValue type to ResponseResult variant to support arbitrary nested
JSON responses. This enables proper MCP protocol compliance for responses
like initialize that require nested object structures.

Changes:
- Add json::JsonValue to ResponseResult variant in types.h
- Add JsonValue serialization handler in json_serialization.cc
Fix response formats for initialize, tools/list, and prompts/list to
comply with MCP protocol specification.

Changes:
- handleInitialize: Use proper nested JSON structure instead of flattened
  dot notation (e.g., {"serverInfo": {"name": ...}} not {"serverInfo.name": ...})
- handleListTools: Wrap tools array in {"tools": [...]} object
- handleListPrompts: Wrap prompts array in {"prompts": [...]} object
Add CORS headers to all HTTP responses for browser-based MCP clients
(e.g., MCP Inspector). Also add check to pass through already
HTTP-formatted responses from routing filter.

Changes:
- Add Access-Control-Allow-Origin, Methods, and Headers to JSON responses
- Add same CORS headers to SSE responses
- Skip HTTP framing for responses that already have HTTP headers
Add support for browser-based MCP clients by handling CORS preflight
requests and sending proper HTTP responses for JSON-RPC notifications.

Changes:
- Register OPTIONS handlers for /mcp, /mcp/events, /rpc, /health, /info
- Add default OPTIONS handler for any unregistered path
- Add CORS headers to /health and /info endpoint responses
- Send HTTP 202 Accepted response for JSON-RPC notifications
  (notifications don't have JSON-RPC responses but HTTP requires one)
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 5, 2026

❌ Code Formatting Check Failed

Some files in this PR are not properly formatted according to the project's clang-format rules.

To fix this issue:

make format

Then commit and push the changes.

@gophergogo gophergogo changed the title Improvement MCP server for MCP inspector Improve MCP server for MCP inspector Mar 16, 2026
@sjoelund
Copy link
Copy Markdown

This is exactly what I needed. I couldn't figure out why the client would just not respond when sent an OPTIONS request. With this branch, the llama.cpp client can see the example server.

@gophergogo gophergogo merged commit 1024ae2 into main Mar 20, 2026
1 check passed
@gophergogo
Copy link
Copy Markdown
Collaborator

This is exactly what I needed. I couldn't figure out why the client would just not respond when sent an OPTIONS request. With this branch, the llama.cpp client can see the example server.

@sjoelund the PR has been merged. What you said is right! We dog food Gopher MCP to build our entire MCP gateway infra, that's why we know the exact problem and push improvements to community to benefit others like yourself.

Please feel free to log tickets if you have any issues, and welcome contribute code. ~thanks.

@sjoelund
Copy link
Copy Markdown

Yes, I will log tickets when I am sure of something being wrong. But I will check the PRs first. It seems I need #205 as well.

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.

4 participants