Skip to content

fix(runtime): support subpaths and preserve target routing in MCP proxy - #627

Open
xsvm wants to merge 1 commit into
langgenius:mainfrom
xsvm:fix/runtime-mcp-proxy-subpaths
Open

fix(runtime): support subpaths and preserve target routing in MCP proxy#627
xsvm wants to merge 1 commit into
langgenius:mainfrom
xsvm:fix/runtime-mcp-proxy-subpaths

Conversation

@xsvm

@xsvm xsvm commented Sep 11, 2026

Copy link
Copy Markdown

Summary

  • Mounts wildcard subpath route for MCP proxy (/mcp/proxy/:serverId/* alongside /mcp/proxy/:serverId).
  • Implements safe subpath extraction extractMcpProxySubPath with percent-encoding and path traversal guards (.., \, %25, %2f, %5c, and malformed encoding).
  • Updates toUpstreamProxyUrl to correctly append subpaths to upstream target URLs while normalizing trailing slashes and preserving query parameters.
  • Adds end-to-end HTTP integration tests covering routing, path traversal rejection (400), upstream trailing slash handling, and internal grant parameter stripping.
  • Fixes fix(runtime): MCP proxy router drops downstream subpaths and returns 404 #626.

Why

  • Standard Model Context Protocol (MCP) transports (such as SSE and HTTP streaming) require distinct downstream subpaths (e.g. /sse, /messages, /tools/call).
  • Previously, Hono rejected any subpath with 404 Route Not Found, and toUpstreamProxyUrl unconditionally dropped subpaths even if received.

Verification

  • Commands:
    • bun test apps/api/tests/driver-mcp-proxy-route.test.ts (5 pass, 0 fail, 17 expects)
    • bun test apps/api/tests/driver-llm-proxy-route.test.ts (33 pass, 0 fail)
    • bun x tsc -p apps/api/tsconfig.json --noEmit (0 errors)
    • vp fmt --check (100% matched)
    • bun scripts/validate-commit-range.ts upstream/main HEAD (1 commit passed)
  • Manual steps: N/A
  • Not run: N/A

Impact

  • User/API/contract changes: Fixes MCP runtime proxy routing for downstream subpaths; 100% backwards-compatible with existing base route behavior.
  • Generated files / GraphQL / DB / lockfile: N/A
  • Env or config changes: N/A
  • Risk and rollback: Zero regression risk. Clean single-commit revert if needed.

Review

  • Closest review areas: apps/api/src/adapters/http/routes/driver-route.ts
  • Known trade-offs: Kept extractMcpProxySubPath and toUpstreamProxyUrl internal/private to align with the existing extractLlmProxySubPath pattern and avoid unnecessary public API surface expansion.

Design (UI changes only, otherwise N/A)

  • N/A

Fixes an issue where the runtime MCP proxy router strictly matched /mcp/proxy/:serverId without a wildcard, causing requests with subpaths (e.g. /messages, /sse) to fail with 404. Also ensures toUpstreamProxyUrl safely appends the subpath onto the resolved upstream URL instead of truncating it.
@github-actions

github-actions Bot commented Sep 11, 2026

Copy link
Copy Markdown

All contributors on this pull request have signed the CLA.
Posted by the CLA Assistant Lite bot.

@xsvm

xsvm commented Sep 11, 2026

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@xsvm

xsvm commented Sep 11, 2026

Copy link
Copy Markdown
Author

recheck

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.

fix(runtime): MCP proxy router drops downstream subpaths and returns 404

1 participant