Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 12, 2026

Multi-Transport HTTP MCP Backend Support - COMPLETE ✓

Problem Solved

The gateway now properly handles different types of HTTP MCP servers, including safeinputs which uses a non-standard JSON-RPC 2.0 over HTTP implementation.

Implementation Summary

File Modified: internal/mcp/connection.go (229 additions, 46 deletions)

Key Changes:

  1. Added HTTPTransportType enum to track transport in use:

    • HTTPTransportStreamable - for 2025-03-26 spec
    • HTTPTransportSSE - for 2024-11-05 spec
    • HTTPTransportPlainJSON - for non-standard implementations
  2. Enhanced NewHTTPConnection with smart fallback logic:

    • Detects custom headers and skips SDK transports (they don't support headers)
    • For servers without headers, tries: Streamable HTTP → SSE → Plain JSON-RPC
    • Critical for safeinputs which requires auth headers
  3. Added transport-specific connection functions:

    • tryStreamableHTTPTransport() - Uses SDK's StreamableClientTransport
    • trySSETransport() - Uses SDK's SSEClientTransport
    • tryPlainJSONTransport() - Manual HTTP POST implementation
  4. Refactored SendRequestWithServerID:

    • Routes to appropriate handler based on transport type
    • Plain JSON-RPC uses direct HTTP requests
    • SDK transports use session methods
  5. Added callSDKMethod helper:

    • Eliminates code duplication
    • Centralizes method dispatch for SDK-based transports
  6. Defensive programming:

    • Nil checks in all SDK method wrappers
    • Prevents panics when session is unavailable
    • Better error messages

Test Results

  • ✓ All mcp package tests pass
  • ✓ All launcher package tests pass
  • ✓ Linting passes (ineffassign issues fixed)
  • ✓ Code formatted with gofmt
  • ✓ Code review feedback addressed

Compatibility

  • Safeinputs: ✓ Works with custom headers + plain JSON-RPC
  • Standard MCP HTTP: ✓ Will use streamable or SSE when available
  • Backward Compatible: ✓ Existing plain JSON-RPC backends continue to work

What This Enables

  • Gateway can now connect to safeinputs MCP server
  • Automatic fallback ensures compatibility with all HTTP MCP variants
  • Future-proof for when more servers adopt standard transports

💡 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.

Copilot AI and others added 3 commits January 12, 2026 04:29
Add support for multiple HTTP transport types with fallback:
- Try streamable HTTP first (SDK StreamableClientTransport)
- Fall back to SSE (SDK SSEClientTransport)
- Fall back to plain JSON-RPC over HTTP (manual implementation)

This ensures compatibility with safeinputs and other non-standard HTTP MCP servers.

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
- Skip SDK transports when custom headers are provided (they don't support headers)
- This fixes safeinputs and similar backends that require authentication
- Format code with gofmt

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
- Add nil check for session in SDK method wrappers to prevent panics
- Extract callSDKMethod to eliminate code duplication
- Improve defensive programming

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix gateway handling of safeinputs backend HTTP server Add HTTP transport fallback for non-standard MCP servers Jan 12, 2026
Copilot AI requested a review from lpcox January 12, 2026 04:38
@lpcox
Copy link
Collaborator

lpcox commented Jan 12, 2026

@copilot please fix thesel linting issues

run golangci-lint
Running [/home/runner/golangci-lint-2.7.2-linux-amd64/golangci-lint run --timeout=5m] in [/home/runner/work/gh-aw-mcpg/gh-aw-mcpg] ...
Error: internal/mcp/connection.go:196:2: ineffectual assignment to lastErr (ineffassign)
lastErr = err
^
Error: internal/mcp/connection.go:207:2: ineffectual assignment to lastErr (ineffassign)
lastErr = err
^
2 issues:

  • ineffassign: 2

Remove unused lastErr variable assignments. The variable was being
assigned on lines 196 and 207 but overwritten before use. Now we
directly use err in the final error message since it contains the
last error from the final transport attempt.

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 12, 2026

@copilot please fix thesel linting issues

run golangci-lint
...

Fixed in 0904e6d. Removed the unused lastErr variable and its ineffectual assignments - now using err directly in the final error message which already contains the last transport attempt's error.

@lpcox lpcox marked this pull request as ready for review January 12, 2026 04:49
@lpcox lpcox merged commit 21668b8 into main Jan 12, 2026
3 checks passed
@lpcox lpcox deleted the copilot/fix-gateway-http-server-handling branch January 12, 2026 04:49
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.

2 participants