TT-18010: Normalize MCP protocol context - #8594
andrei-tyk wants to merge 6 commits into
Conversation
|
This PR introduces a centralized parsing mechanism for the Model Context Protocol (MCP) to ensure a single, consistent interpretation of incoming requests throughout the gateway's processing pipeline. Previously, different components like routing, policy enforcement, and analytics would independently parse the MCP request body. This led to duplicated effort and potential inconsistencies. This change refactors the This new Files Changed AnalysisThe changes are centered around the gateway's MCP handling:
Architecture & Impact Assessment
Request Flow TransformationThis diagram illustrates how the change centralizes request parsing. Before: Multiple components read and parsed the request body independently. sequenceDiagram
participant Client
participant JSONRPCMiddleware
participant Other Middlewares
participant SuccessHandler
Client->>JSONRPCMiddleware: POST /mcp request
JSONRPCMiddleware->>JSONRPCMiddleware: Read & Parse Body for routing
JSONRPCMiddleware->>Other Middlewares: Forward request
Other Middlewares->>Other Middlewares: Read & Parse Body again for policy
Other Middlewares->>SuccessHandler: Forward request
SuccessHandler->>SuccessHandler: Read & Parse Body again for analytics
After: The body is parsed once, and the result is shared via the request context. sequenceDiagram
participant Client
participant JSONRPCMiddleware
participant Other Middlewares
participant SuccessHandler
Client->>JSONRPCMiddleware: POST /mcp request
JSONRPCMiddleware->>JSONRPCMiddleware: Read & Parse Body ONCE
JSONRPCMiddleware->>JSONRPCMiddleware: Store ProtocolContext in http.Request
JSONRPCMiddleware->>Other Middlewares: Forward request
Other Middlewares->>Other Middlewares: Get ProtocolContext from http.Request
Other Middlewares->>SuccessHandler: Forward request
SuccessHandler->>SuccessHandler: Get ProtocolContext from http.Request
Scope Discovery & Context ExpansionThis PR is part of a larger, cross-repository initiative. The changes to analytics data in the Gateway are only useful when the downstream components are prepared for them. The PR description and The introduction of the Metadata
Powered by Visor from Probelabs Last updated: 2026-08-18T08:58:37.507Z | Triggered by: pr_updated | Commit: e518d59 💡 TIP: You can chat with Visor using |
Security Issues (1)
Security Issues (1)
Performance Issues (1)
Powered by Visor from Probelabs Last updated: 2026-08-18T08:57:59.983Z | Triggered by: pr_updated | Commit: e518d59 💡 TIP: You can chat with Visor using |
becc05b to
e518d59
Compare
|
Superseded by the current v2 implementation in #8678. |
|
SentinelOne CNS Hardcoded Secret Detector SentinelOne CNS is a cloud-agnostic, agentless CSPM & CWPP solution that continuously detects and prevents vulnerabilities that have the highest probability of being exploited in Azure, AWS, Google Cloud, and Kubernetes. |
🎯 Recommended Merge TargetsBased on JIRA ticket TT-18010: Detect and record protocol version Fix Version: Tyk 5.16.0
Required:
📋 Workflow
|
Description
Introduces a single bounded MCP ingress envelope/protocol context and exports effective/declared/source protocol fields through analytics. Dashboard pins the Pump prerequisite, covers old/new record decoding, and adds black-box analytics cases.
Related Issue
Motivation and Context
Routing, policy, errors, filtering, handler selection, and analytics need one agreed protocol interpretation instead of reparsing request bodies independently.
How This Has Been Tested
GOCACHE=/private/tmp/tt18006-go-cache go test ./internal/mcp/... ./internal/jsonrpc/errors -count=1— pass on the complete Gateway stack.GOCACHE=/private/tmp/tt18006-pump-gocache go test ./analytics ./serializer -count=1— pass, covering JSON/BSON and protobuf/msgpack compatibility.GOCACHE=/private/tmp/tt18006-dashboard-gocache go test ./dashboard -run 'TestMCP(TrustedOriginsManagementContract|ProtocolContextAnalyticsJSONCompatibility)' -count=1— pass.python3 -m compileall -q tests/api/mcp_client.py tests/api/tests/mcp— pass..venv/bin/pytest -c pytest_local.ini tests/mcp/ ...analytics gate was not run because the live release environment is unavailable.Types of changes
Checklist