branben/OmniRoute · Pull Request #15983

SPEC — MCP 2026-07-28 spec upgrade

feat/mcp-v2-sidecar → release/v3.8.53 +2761 / −14 21 files

Decisions locked before any code

# Decision Alternative rejected Why
D1Parallel v2 sidecar under open-sse/mcp-server/v2/Migrate v1 in-placev1 is live with 37 tools and production clients. The spec's compatibility clause supports a parallel surface. Changing v1 risks every existing client.
D2Opt-in via OMNIROUTE_MCP_V2 feature flag (DB-overridable)Always-on v2Existing v1 clients must see zero behavior change. The flag is registered in featureFlagDefinitions (registry slot 85) so operators can toggle per-environment, not just via env.
D3Scope enforcement resolved through v1's DB-aware switchRead env at module loadv1's dashboard toggle is DB-backed. If v2 read env at module load, an env-only toggle would let v2 stay open while v1 enforced — a security gap.
D4Scopes from authenticated request only — withScopeEnforcement passes only {authInfo, sessionId}Pass full _meta from clientA caller that self-grants a scope in _meta must still be refused. The shared function's client-supplied _meta branch is unreachable from v2.
D5No identity reflection on denial surface — use buildScopeDenialMessageEcho caller/source like v1 did pre-S-04callerId is caller-influenced, so it stays in the audit payload only. The denial message itself does not echo it.
D6Separate HTTP route at /api/mcp/v2 with v1's exact auth classificationShare v1's /api/mcp routev2 is stateless (no Mcp-Session-Id handshake). Sharing the route would force v1's session lifecycle onto v2.
D7Stateless per-request server+transportPersistent v2 server2026-07-28 drops the initialize handshake. A fresh server+transport pair per request matches the spec and avoids state leakage between clients.
D8Honest server/discover — tools only, no unregistered resources/promptsExpose full catalog via discoverThe v2 sidecar has exactly 8 tools. discover must answer truthfully.
D98 tools only, all calling omniRouteFetch() against real endpointsAdd more tools in this PRBounded contribution toward #17131. Full catalog migration is separate work.
D10Sanitized transport/tool errors — no stack traces or internal paths leak to clientPass errors through rawProduction safety.
D11Return stdio cleanup handle from startMcpStdioV2()Fire-and-forget stdioAllows the caller to close the transport cleanly.
D12Tests reuse repository isolation fixture + explicit empty plugin dirSpin up a real plugin directoryKeeps tests hermetic. Child transports are closed after each test, including timeouts.

Milestone map → tickets

Milestone Ticket Title Dependencies
M1school-core-emb (U1)browser-use unblock for mcp2 (cap browser-use<0.12 + shim decorators)none
M2school-core-58y (U2)fastmcp 4.x stateless support in SDKU1
M3school-core-77r (U3)Mcp-* headers + _meta passthroughU2
M3school-core-4qs (U4)server/discover + SSE-only deprecationU2
M3school-core-ven (U5)OAuth issuer-keyed RFC 9207U2
M3school-core-te6 (U6)OAuth CIMD/application_typeU2
M4school-core-rxp (U7)upstream browser-use 0.13.x (tracked)U2
M5school-core-hr6Epic: close when all U-items shipall

Milestone 1 — v2 sidecar scaffold (open-sse/mcp-server/v2/)

New module: open-sse/mcp-server/v2/server.ts

New route: src/app/api/mcp/v2/route.ts

Feature flag: OMNIROUTE_MCP_V2

Added to featureFlagDefinitions.ts (registry slot 85). Read at module load, like OMNIROUTE_MCP_ENFORCE_SCOPES.

Milestone 2 — protocol compliance details

Headers + routing

server/discover

List caching

_meta passthrough

MRTR contract

Milestone 3 — security and hardening

Scope enforcement (D3)

Identity hygiene (D5)

Error sanitization (D10)

Milestone 4 — tests

11 test files under tests/unit/mcp/v2/:

File What it proves
v2-server.spec.tsCore v2 server behavior, tool dispatch, scope enforcement
v2-discover-honesty.spec.tsdiscover returns tools only, no fake resources/prompts
v2-esm-link.spec.tsESM import of v2 server works (link resolution)
v2-feature-flag.spec.tsOMNIROUTE_MCP_V2 gating; DB-overridable
v2-gaps.spec.tsSpecific 2026-07-28 gaps that v1 failed
v2-http-route.spec.tsRoute gating, stateless discover/list/call over real HTTP
v2-parity.spec.tsv2 parity with v1 for shared behaviors
v2-scope-enforcement.spec.tsScope enforcement ≥ v1; _meta cannot grant
v2-tool-smoke.spec.ts8 tools smoke test against real endpoints
v2-modern.spec.tsModern (2026-07-28) stdio behavior
v2-legacy.spec.tsLegacy stdio still works unchanged

Isolation

Repository isolation fixture + explicit empty plugin directory. Child transports closed after each test, including timeouts.

Vitest config

vitest.mcp.config.ts — isolated MCP test runner so MCP tests don't pollute the main suite.

Verification commands

npm run test:vitest -- --config vitest.mcp.config.ts

# Expected: 92/94 pass (2 known Node ESM startup probes exceed 60s deadline)
# Do NOT increase the deadline — that would mask the real issue.

npm run lint -- open-sse/mcp-server/v2 src/app/api/mcp/v2 tests/unit/mcp
npm run typecheck:core
scripts/check/check-commit-evidence.sh
scripts/check/check-test-discovery.mjs

Measured evidence from PR #15983

Risks

Risk Likelihood Mitigation
SDK 2.3.1 API mismatch with current @modelcontextprotocol/sdklowPinned in package.json; verified in tests
v2 flag accidentally on in productionlowOff by default; DB-overridable; Diego review required before merge
Scope enforcement weaker than v1lowResolved through v1's DB-aware switch (D3); _meta grant blocked (D4)
Client confusion between /api/mcp and /api/mcp/v2mediumSeparate route, separate path; v1 unchanged
Node ESM startup probes flakymediumKnown, measured, not masked — separate ticket if needed

Out of scope