feat(mcp): add mcp support#1867
feat(mcp): add mcp support#1867NameHaibinZhang wants to merge 16 commits intoopen-telemetry:mainfrom
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1867 +/- ##
===========================================
+ Coverage 67.22% 78.15% +10.92%
===========================================
Files 277 278 +1
Lines 33258 33790 +532
===========================================
+ Hits 22358 26407 +4049
+ Misses 9539 6126 -3413
+ Partials 1361 1257 -104
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
CI Supervisor: Pull request checks (attempt 1)
|
CI Supervisor: Pull request checks (attempt 2)
|
CI Supervisor
|
|
@NameHaibinZhang we recently added JSONRPC detection, did you consider using the same logic from there for parsing and detection? |
NimrodAvni78
left a comment
There was a problem hiding this comment.
thank you for the addition!
i think the scope of this PR is too wide, mainly with the go large buffers refactor and not reusing existing logic of JsonRPC parsing
I would also appreciate adding integration tests for this
There was a problem hiding this comment.
Pull request overview
Adds Model Context Protocol (MCP) observability by detecting MCP-over-HTTP (JSON-RPC 2.0), enriching spans with MCP/GenAI semantic attributes, and enabling cross-tracer payload correlation so Go uprobe HTTP spans can be enriched using kprobe-captured body data.
Changes:
- Implement MCP HTTP payload parsing/detection and add unit tests for MCP method variants and error handling.
- Add connection-based large-buffer lookup and use it to enrich Go tracer HTTP spans with MCP/JSON-RPC detection.
- Export MCP/GenAI semantic attributes via OTel traces, and add config/schema/docs entries to gate MCP support.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/obi/config.go | Adds MCP config defaults (disabled by default). |
| pkg/internal/ebpf/generictracer/generictracer.go | Expands PID filtering to include Go PIDs when payload extraction is enabled; adds periodic PID filter rebuild. |
| pkg/export/otel/tracesgen/tracesgen.go | Adds MCP span attribute emission to OTel exporter. |
| pkg/export/attributes/names/attrs.go | Adds MCP/GenAI attribute name constants (semconv v1.40 keys where needed). |
| pkg/ebpf/common/tcp_large_buffer.go | Adds connection-keyed buffer index + extraction helper to share buffers across tracers. |
| pkg/ebpf/common/tcp_large_buffer_test.go | Adds tests validating connection-key buffer extraction semantics. |
| pkg/ebpf/common/http_transform.go | Detects MCP during HTTP parsing and adds Go-span enrichment via connection-based large-buffer lookup. |
| pkg/ebpf/common/http_transform_test.go | Adds test ensuring Go HTTP span enrichment can detect MCP via connection-based lookup. |
| pkg/ebpf/common/common.go | Extends parse context with connBuffers and invokes Go-span enrichment in ringbuf parsing. |
| pkg/ebpf/common/http/mcp.go | Implements MCP detection/parsing from JSON-RPC request/response bodies. |
| pkg/ebpf/common/http/mcp_test.go | Adds comprehensive MCP unit tests. |
| pkg/ebpf/common/http/openai_test.go | Minor lint annotation removal in shared HTTP test helper. |
| pkg/config/payload_extraction.go | Adds MCPConfig and includes it in GenAIConfig.Enabled(). |
| pkg/config/payload_extraction_test.go | Adds tests for GenAIConfig.Enabled() including MCP. |
| pkg/appolly/app/request/span.go | Adds MCP subtype + MCPCall model, trace naming, and GenAI operation name support. |
| docs/config-schema.json | Updates JSON schema for MCP payload extraction config. |
| devdocs/features.md | Documents MCP support and required env vars. |
| SUPPORT_MATRIX.md | Updates GenAI vendor list and adds MCP support entry. |
|
I tend to agree with @NimrodAvni78, it would be great if we could split this into smaller PRs as per contributing guidelines. |
ok |
47eb236 to
a4b0e32
Compare
ok |
|
@NimrodAvni78 @rafaelroquetto I've minimized the MCP support code and reverted the changes to gotracer. It passed all tests, please review, thks. |
|
@NameHaibinZhang can we add integration tests for this? |
sure |
|
@NimrodAvni78 I have already added integration tests, please review, thks. |
Summary
Add observability support for the Model Context Protocol (MCP) — the emerging standard for communication between AI agents and tool/resource servers.
MCP runs over HTTP using JSON-RPC 2.0. This change enables OBI to automatically detect, parse, and export MCP spans with rich semantic attributes following the OpenTelemetry MCP semantic conventions (semconv v1.40.0).
Key changes
Protocol detection (
pkg/ebpf/common/http/mcp.go): Identifies MCP traffic by parsing the JSON-RPC request body and matching method names (tools/call,resources/read,prompts/get,initialize, etc.) with ajsonrpc: "2.0"version check. Falls back to theMcp-Session-Idheader for unknown extension methods. Extracts tool name, resource URI, prompt name, session ID, protocol version, request ID, and error information from both request and response bodies.Span enrichment (
pkg/appolly/app/request/span.go): AddsHTTPSubtypeMCPsubtype,MCPCallstruct, andOperationName()for GenAI operation naming (tools/call→execute_tool). ExtendsSpanStatusCodeandSpanStatusMessageto treat MCP JSON-RPC errors (non-zero error code in HTTP 200 responses) as span errors, matching existing JSON-RPC behavior.HTTP transform integration (
pkg/ebpf/common/http_transform.go): Wires MCP detection into the HTTP span pipeline, gated by the MCP enabled flag. Placed before JSON-RPC detection so MCP-specific semantics take priority.OTel attribute export (
pkg/export/otel/tracesgen/tracesgen.go,pkg/export/attributes/names/attrs.go): Emitsmcp.method.name,mcp.session.id,mcp.resource.uri,mcp.protocol.version,gen_ai.tool.name,gen_ai.prompt.name,gen_ai.operation.name,jsonrpc.request.id,rpc.response.status_code, anderror.messageattributes.Configuration (
pkg/config/payload_extraction.go,pkg/obi/config.go): AddedMCPConfigwithOTEL_EBPF_HTTP_MCP_ENABLEDenv var, disabled by default.GenAIConfig.Enabled()includes MCP.Tests: Comprehensive unit tests covering all MCP method types, error responses, session header fallback, non-MCP rejection (missing
jsonrpc: "2.0", unknown methods, non-POST, invalid JSON), span status/message for MCP errors,GenAIConfig.Enabled()coverage, and OTel trace generation for MCP success/error spans (server and client).Validation