KEMBAR78
Remote MCP support (streamable http and sse) by ktsaou · Pull Request #21036 · netdata/netdata · GitHub
Skip to content

Conversation

@ktsaou
Copy link
Member

@ktsaou ktsaou commented Sep 22, 2025

Remote MCP Support: HTTP and SSE Transports

This PR adds direct HTTP and Server-Sent Events (SSE) transport support to Netdata's Model Context Protocol (MCP) implementation, enabling AI assistants to connect directly to Netdata without requiring the nd-mcp bridge. It also allows the dev preview api key to be given to http authorization bearer header.

Summary

Netdata's MCP server now supports three transport mechanisms:

  • WebSocket (existing): via /mcp endpoint
  • HTTP Streamable (new): chunked JSON-RPC over HTTP via /mcp endpoint
  • SSE (new): Server-Sent Events via /mcp?transport=sse or detected via Accept: text/event-stream header

This enables modern MCP clients like npx @modelcontextprotocol/remote-mcp to connect directly to Netdata's HTTP endpoints, while maintaining backward compatibility with stdio-based clients through the existing bridge.

Key Changes

Core MCP Architecture:

  • Refactored JSON-RPC handling into separate mcp-jsonrpc.c module for transport-agnostic message processing
  • Removed request ID tracking (mcp-request-id.c) - now handled individually by each transport adapter
  • Added HTTP response tracking in web_client for MCP session management

New Transport Adapters:

  • mcp-http.c: Implements chunked HTTP transport with proper content negotiation
  • mcp-sse.c: Implements Server-Sent Events with event-based message framing
  • Refactored mcp-websocket.c to use common JSON-RPC module

Enhanced Test Client:

  • Added support for testing all three transports (WebSocket, HTTP, SSE)
  • Improved SSE parsing with proper event-data handling
  • Added bearer token authentication support
  • Better error handling and transport selection

Documentation Updates:

  • Comprehensive transport comparison and usage guide in docs/learn/mcp.md
  • Updated src/web/mcp/README.md with direct connection examples
  • Added protocol analysis documents for HTTP/SSE transports
  • Updated TODO list reflecting completed Phase 1/2 tasks

Technical Details

Transport Selection:
The /mcp endpoint automatically selects the transport based on:

  1. Query parameter: ?transport=sse forces SSE
  2. Accept header: Accept: text/event-stream triggers SSE
  3. Default: HTTP streamable (chunked JSON)

Message Framing:

  • HTTP: Chunked transfer encoding with JSON-RPC messages
  • SSE: Event stream with event: message and data: fields
  • WebSocket: JSON-RPC over WebSocket frames (unchanged)

Session Management:
Each transport adapter maintains its own request tracking and session state, enabling proper message correlation and response routing.

Benefits

  1. Simpler Deployment: Many AI clients can now connect directly without bridge setup
  2. Broader Compatibility: Standard HTTP/SSE enables integration with more MCP clients
  3. Better Performance: Direct connection eliminates bridge overhead
  4. Backward Compatible: Existing WebSocket and stdio/bridge configurations continue to work

Testing

The MCP test client (src/web/mcp/mcp-test-client/index.html) now supports all three transports and can be used to verify functionality:

  • WebSocket: ws://localhost:19999/mcp
  • HTTP: http://localhost:19999/mcp
  • SSE: http://localhost:19999/mcp?transport=sse

Migration Path

  • No breaking changes: Existing configurations using nd-mcp bridge continue to work
  • New option: Clients supporting HTTP/SSE can now connect directly
  • Recommended: Use direct HTTP/SSE for new deployments; keep bridge for stdio-only clients

@github-actions github-actions bot added area/docs area/web area/build Build system (autotools and cmake). labels Sep 22, 2025
@ktsaou ktsaou force-pushed the mcp7 branch 2 times, most recently from aac28ba to c5d25f8 Compare September 24, 2025 13:17
@ktsaou ktsaou changed the title WIP: Remote MCP support Remote MCP support (streamable http and sse) Sep 24, 2025
@ktsaou ktsaou marked this pull request as ready for review September 24, 2025 13:17
@ktsaou ktsaou merged commit 891c583 into netdata:master Oct 2, 2025
130 of 132 checks passed
stelfrag pushed a commit to stelfrag/netdata that referenced this pull request Oct 3, 2025
* prepare for multiple mcp headends

* fixed last

* updated todo list

* updated todo list

* Add HTTP and SSE adapters for MCP

* Select MCP SSE via Accept header

* MCP: add HTTP/SSE transport support and fix chunked responses

* MCP test client: await HTTP/SSE responses and harden SSE parsing

* docs: drop completed MCP Phase 1/2 tasks from TODO

* docs: renumber remaining MCP phases

* docs: document HTTP/SSE MCP transports and remote-mcp usage

* updated docs for mcp changes

* bearer token in mcp-test-client

* MCP authorization via http header

(cherry picked from commit 891c583)
@stelfrag stelfrag mentioned this pull request Oct 3, 2025
Ferroin pushed a commit that referenced this pull request Oct 15, 2025
* prepare for multiple mcp headends

* fixed last

* updated todo list

* updated todo list

* Add HTTP and SSE adapters for MCP

* Select MCP SSE via Accept header

* MCP: add HTTP/SSE transport support and fix chunked responses

* MCP test client: await HTTP/SSE responses and harden SSE parsing

* docs: drop completed MCP Phase 1/2 tasks from TODO

* docs: renumber remaining MCP phases

* docs: document HTTP/SSE MCP transports and remote-mcp usage

* updated docs for mcp changes

* bearer token in mcp-test-client

* MCP authorization via http header

(cherry picked from commit 891c583)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/build Build system (autotools and cmake). area/daemon area/docs area/web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants