Replace custom JSON handler with StreamableHTTPHandler in mcp-gateway#7585
Merged
Replace custom JSON handler with StreamableHTTPHandler in mcp-gateway#7585
Conversation
Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Integrate mcp-gateway with awf firewall using MCP streamable-http protocol
Replace custom JSON handler with StreamableHTTPHandler in mcp-gateway
Dec 25, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The mcp-gateway was using a custom JSON POST API instead of the standard MCP streamable-http protocol, preventing proper client connection via
StreamableClientTransport.Changes
Architecture shift: Each backend MCP server now gets its own proper streamable-http endpoint via go-sdk's
StreamableHTTPHandler:mcp.Server, forward calls to backend session/mcp/{server}endpoints now usemcp.NewStreamableHTTPHandlerinstead of manual JSON-RPC parsing/healthand/serversendpoints unchangedCode reduction: Removed ~150 lines of custom protocol implementation (
handleInitialize,handleListTools,handleCallTool, etc.) in favor of go-sdk's built-in handling.Usage
Agents connect using standard MCP protocol:
{ "mcpServers": { "gh-aw": { "url": "http://host.docker.internal:8080/mcp/gh-aw" } } }Client code:
Ready for awf firewall integration once
host.docker.internalis whitelisted in Squid proxy.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/user/usr/bin/gh gh api user --jq .login(http block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>Integrate mcp-gateway (awmg) with awf firewall using MCP streamable-http protocol</issue_title>
<issue_description>## Summary
Enable MCP servers running on the host to be accessible by agents running inside the awf (aw-firewall) container through the mcp-gateway, using the standard MCP streamable-http protocol.
Current State
mcp-gateway (awmg) currently:
/health,/servers,/mcp/{server}(POST)http://host.docker.internal:PORT/mcp/{server}URLsawf (firewall) currently:
host.docker.internalfor accessing host servicesThe Problem
The current gateway's
/mcp/{server}endpoint is a custom JSON POST API, not a proper MCP streamable-http endpoint. An MCP client usingStreamableClientTransport(which is the standard way to connect via HTTP) won't be able to communicate with it correctly.Proposed Architecture
Required Changes
1. Gateway: Add StreamableHTTPHandler endpoint
The gateway needs to expose a proper MCP streamable-http endpoint. The go-sdk already has
StreamableHTTPHandleravailable (used inmcp_server.go:762-794):The gateway would need to:
StreamableHTTPHandleron/mcp2. Tool Aggregation Strategy
Two approaches to consider:
Option A - Namespace prefixing: Tools from different servers get prefixed (e.g.,
gh-aw:list_files,filesystem:read_file)Option B - Flat namespace: All tools exposed without prefix, conflicts resolved by priority
3. Agent Configuration
The agent inside awf would use a single MCP config entry:
{ "mcpServers": { "gateway": { "url": "http://host.docker.internal:8080/mcp" } } }4. Firewall Whitelist
host.docker.internalneeds to be whitelisted in the Squid proxy configuration for the awf container.Benefits
StreamableClientTransportandStreamableHTTPHandlerare already used in the codebaseImplementation Scope
Main work in `pkg/cli/mc...
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.