How It Works
Built-in Interceptors
| Interceptor | Priority | BeforeRequest | AfterResponse | Purpose |
|---|---|---|---|---|
| Trace | 0 | Fail open | Fail open | Creates OpenTelemetry spans, stores trace records |
| Logging | 75 | Fail open | Fail open | Structured request/response logging |
| Audit | 75 | Fail open | Fail closed | Records security audit events |
| Metrics | 100 | Fail open | Fail open | Counters, histograms, latency |
Priority Constants
Interceptor Interface
Each interceptor implements two methods:BeforeRequest— Called before the request reaches the upstream server. Can inspect, modify, or block the request.AfterResponse— Called after the response comes back from the upstream. Can record, transform, or block the response.
Failure Modes
Understanding failure modes is critical for security:Request Phase (BeforeRequest)
Any error from any interceptor blocks the request entirely. The request never reaches the upstream server, and the client receives an error. Currently, all built-in interceptors returnnil in BeforeRequest (fail open individually). Future interceptors like Policy will block requests that violate defined policies.
Response Phase (AfterResponse)
Behavior varies by interceptor:- Trace, Logging, Metrics — Absorb errors (fail open). A storage failure won’t block your MCP call.
- Audit — Propagates errors (fail closed). If the audit event can’t be recorded, the call fails. This ensures complete audit trails.
Practical Implications
Request/Response Types
Request
Each request carries:| Field | Description |
|---|---|
ID | Unique request identifier |
TraceID | OpenTelemetry trace ID |
SpanID | OpenTelemetry span ID |
Type | Operation type (tool_call, resource_read, etc.) |
Upstream | Target server name |
Method | JSON-RPC method |
ToolName | Tool name (for tool calls) |
ToolParams | Tool arguments (JSON) |
ResourceURI | Resource URI (for resource reads) |
PromptName | Prompt name (for prompt gets) |
Principal | Client/user identifier |
Metadata | Inter-interceptor communication map |
Response
| Field | Description |
|---|---|
Success | Whether the operation succeeded |
Error | Error (if failed) |
Duration | How long the upstream call took |
RawResponse | Raw JSON response |
Metadata Communication
Interceptors can share data through the request’sMetadata map. For example, the trace interceptor stores timing information that other interceptors can reference.
Auth and Policy interceptors are planned but not yet implemented. The policy interceptor will execute at
PriorityNormal (50) and fail closed on policy evaluation errors. See Roadmap: Policy Engine.