TT-18010: share MCP protocol context and analytics O#6 - #8678
andrei-tyk wants to merge 11 commits into
Conversation
|
This pull request refactors the Model Context Protocol (MCP) request handling in the Tyk Gateway to improve performance and enrich analytics. The core change is to parse the MCP request body only once at the ingress point and share the result—including the parsed envelope, raw body, and protocol version details—via a new request-scoped Additionally, the PR enhances observability by adding Files Changed AnalysisThe changes are concentrated in the
Architecture & Impact Assessment
Paired MCP Proxy Analytics FlowsequenceDiagram
participant Client
participant PublicProxy as Public MCP Proxy
participant Observer as Completion Observer
participant InternalAdapter as Internal Adapter
participant Analytics
Client->>PublicProxy: POST /public-mcp/
activate PublicProxy
PublicProxy->>Observer: newMCPCompletionAnalyticsOwner(w)
note right of PublicProxy: Wraps ResponseWriter with snoop
PublicProxy->>InternalAdapter: Proxies request internally
activate InternalAdapter
InternalAdapter-->>PublicProxy: Writes response body
deactivate InternalAdapter
Observer-->>Observer: Captures status & body snippet
PublicProxy-->>Client: Streams response immediately
deactivate PublicProxy
Observer->>Observer: owner.Complete() called via defer
Observer->>Analytics: Records hit for PublicProxy
Scope Discovery & Context ExpansionThe impact of this PR extends beyond the Gateway repository. The explicit update of the The base branch, Metadata
Powered by Visor from Probelabs Last updated: 2026-09-16T19:08:37.326Z | Triggered by: pr_updated | Commit: 11fde7c 💡 TIP: You can chat with Visor using |
✅ Security Check PassedNo security issues found – changes LGTM. ✅ Architecture Check PassedNo architecture issues found – changes LGTM. ✅ Security Check PassedNo security issues found – changes LGTM. \n\n✅ Architecture Check PassedNo architecture issues found – changes LGTM. \n\nPerformance Issues (1)
Quality Issues (3)
Powered by Visor from Probelabs Last updated: 2026-09-16T19:08:15.162Z | Triggered by: pr_updated | Commit: 11fde7c 💡 TIP: You can chat with Visor using |
1134ce7 to
a372092
Compare
🎯 Recommended Merge TargetsBased on JIRA ticket TT-18010: Detect and record protocol version Fix Version: Tyk 5.16.0
Required:
📋 Workflow
|
c7a37da to
dc5b151
Compare
3ca5730 to
77af41f
Compare
|
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. |
3 similar comments
|
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. |
|
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. |
|
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. |
dc5b151 to
f63f590
Compare
74c1602 to
84e5466
Compare
|
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. |
f63f590 to
ca53e81
Compare
84e5466 to
11fde7c
Compare
|
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. |
1 similar comment
|
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. |
🚨 Jira Linter FailedCommit: The Jira linter failed to validate your PR. Please check the error details below: 🔍 Click to view error detailsNext Steps
This comment will be automatically deleted once the linter passes. |
Parses the bounded request envelope once and restores the body with its original closer. Shared typed protocol context retains raw declarations, effective version, detection source and validation outcome for policy, filtering, errors and analytics. Adds
effective_protocol_version,declared_protocol_versionandprotocol_version_sourcethrough Gateway, Pump and Dashboard. Session IDs do not imply negotiation; legacy initialize and the 2025-03-26 fallback remain supported. Discovery/subscription classifications add no subscription runtime.Removed the dedicated MCP v2 workflow and the added MCP review documents from the affected PR branches. Dashboard pins the corresponding cleaned Gateway commits. Verified all 15 incremental PR diffs, branch ancestry and unchanged runtime/test sources; Go module tidying changed only the Gateway pin/checksums. The full-suite results below refer to the explicitly recorded pre-cleanup commits; those suites were not rerun for this file cleanup.
Based on Gateway #8677. Counterpart: Dashboard PR. Prerequisite: Pump #1098. Fixtures: cache #6.
Review head:
1134ce76e08f47fb4ce5962a1f0b2ea00e1022e2. Matching Gateway:1134ce76e08f47fb4ce5962a1f0b2ea00e1022e2. Pump pin:977a5ddcda4a523337b4d8e8dd36a0df03c81aef.Module versions:
github.com/modelcontextprotocol/go-sdk v1.6.0,github.com/TykTechnologies/tyk-pump v1.17.0-rc1.0.20260906204536-977a5ddcda4a.Incremental integration: 6 passed, 0 failed, 0 skipped using
python scripts/run_mcp_v2.py tests/mcp/mcp_ga_protocol_analytics_test.py --junitxml=reports/TT-18010.xmlfrom Dashboardtests/api. The runner usespytest_local.ini, explicit environment overrides and-n 0; missing ticket fixtures fail setup. Affected Go packages were run at each layer withGOWORK=offand-count=1.Incremental affected-Go result: 596 passing test/subtest events, 0 failures, 0 skips.
This Gateway layer’s full CI reports: 7470 functional, 2561 shared-race and 67 scoped-race passing test/subtest events; zero failures. Existing skips: 75 functional, 2 shared-race, 0 scoped-race.
Historical validation before the workflow/document cleanup used committed pins: Dashboard
5176927f20055da63c601d951d8561cb6e58f1b5, Gateway47b7aae7b3c679b3b28bacb4f5b3b2686481ed6c, Pump977a5ddcda4a523337b4d8e8dd36a0df03c81aef, mock97e603291b7c0e1bc80c5b9effec947f05d439b1. No local module replacements are used.test_resource_metadata_on_scope_check_challenge,test_no_resource_metadata_when_prm_disabled). The existing analytics usage tests now select their own API records; the complete suite exercises that correction.GOWORK=off CI=true go test -json -p 1 -parallel 1 -cover -tags 'goplugin dev' -timeout 15m -count=1 ./gateway ./internal/mcp/... ./internal/jsonrpc/... ./internal/httpctx ./internal/httputil ./apidef/... ./config ./user. Build the matching plugin first withgo build -cover -tags 'goplugin dev' -buildmode=plugin -o test/goplugins/goplugins.so ./test/goplugins.GOWORK=off go test -json -p 1 -race -count=1 ./internal/mcp/... ./internal/jsonrpc/... ./internal/httpctx ./internal/httputil ./apidef/... ./config ./user. The two skips are existing OAS filled-golden cases. Scoped Gateway MCP/SSE/request-state race checks: 80 passing test/subtest events, 0 failures/skips (exact selection in the historical validation run). Additional local./ctxrace coverage passes (10 test/subtest events). Production and development Gateway builds pass without an SDK upgrade. Go counts include subtests; existing CI-gated/flaky/placeholder skips are retained, not counted as passes.Reproduce the four-repository run with
python tests/api/scripts/run_mcp_v2_stack.py --gateway-root /path/to/gateway --pump-root /path/to/pump --mock-root /path/to/mock --artifacts /path/to/reports --license-file /path/to/existing/licensefrom Dashboard; use the supporting-service/environment configuration intests/api/MCP_V2.mdon the final Dashboard layer. The license is supplied only at runtime.Durable evidence: Gateway validation run, artifact
mcp-v2-gateway-validation; four-repository integration run, artifactmcp-v2-integration. These retain JUnit, raw test events, logs and exact source/module records for 30 days. Integration CI status: all build/test/report stages passed; 495 active MCP tests passed.Historical CI findings were investigated individually. Dependency guards pass. Stock draft/stack aggregators report failure because their test/build jobs are skipped by existing workflow rules. Pump unit tests and lint pass; its managed drift check flags unchanged
.github/workflows/zizmor.yml. No managed-workflow edit or override label was applied. Automated Visor findings remain on earlier layers: response/log parsing optimization suggestions and localhost fixture warnings; these are recorded as open review findings, not misreported as successful checks. Dashboard's branch-suggestion npm installation failure passed on rerun.The broader full-package race experiment exposed pre-existing Streams/RPC/shutdown global-state races; these reproduced on the fetched Gateway base. Other unchanged versioning/policy race paths were reported but did not reproduce in that single baseline retry. The original failed run remains available. Required changed-state/SSE race coverage is isolated and passes; this does not claim the whole legacy Gateway package is race-free. An unchanged JWT global-log test also intermittently captured an unrelated uptime-shutdown message in the error-layer run; the retry passed all functional/race/build stages, and all six Gateway layer workflows passed before their removal.
Gateway’s embedded MCP SDK remains v1.6.0; the independently built mock uses v1.7.0. All builds use
GOWORK=offand published modules have exact commit-based pins with no local filesystem replacements. The parent epic retains the embedded SDK upgrade, modern synthetic runtime, source-header projection and end-to-end cancellation. OAuth issuer changes and stream idle deadlines are outside this stack. A released Pump dependency is required before production release readiness; no release tag was created.Ticket: https://tyktech.atlassian.net/browse/TT-18010
Ticket Details
TT-18010
Generated at: 2026-09-17 08:38:42