mcpparser

package
v0.0.0-...-4ef879c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MCPParser

type MCPParser struct {
	// contains filtered or unexported fields
}

MCPParser parses MCP JSON-RPC 2.0 request bodies and populates pctx.Extensions.MCP with the method, RPC ID, raw params, and the IsAction classification verdict for downstream guardrails.

Recognizes three shapes:

  1. JSON-RPC body (POST /mcp with a valid {jsonrpc, method, ...} payload): populates Method/RPCID/Params. IsAction=true for known action methods (tools/call, prompts/get, resources/read); all other methods leave IsAction at the zero-value false.

  2. Body-less DELETE on a configured path with the Mcp-Session-Id header: MCP Streamable HTTP session termination per spec. Populates Method=$transport/terminate, IsAction=false.

  3. Body-less GET on a configured path: MCP Streamable HTTP server- to-client SSE channel-open. Populates Method=$transport/stream, IsAction=false.

Body-less requests on non-configured paths leave Extensions.MCP nil — the parser can't reliably tell whether they're MCP traffic.

func NewMCPParser

func NewMCPParser() *MCPParser

func (*MCPParser) Capabilities

func (p *MCPParser) Capabilities() pipeline.PluginCapabilities

func (*MCPParser) Configure

func (p *MCPParser) Configure(raw json.RawMessage) error

Configure decodes the optional `paths` list and compiles a path matcher used by body-less transport-layer detection. Always initializes the matcher (default paths are applied when omitted) so OnRequest never has to nil-check.

func (*MCPParser) Name

func (p *MCPParser) Name() string

func (*MCPParser) OnRequest

func (p *MCPParser) OnRequest(_ context.Context, pctx *pipeline.Context) pipeline.Action

func (*MCPParser) OnResponse

func (p *MCPParser) OnResponse(_ context.Context, pctx *pipeline.Context) pipeline.Action

OnResponse is the legacy buffered-path response hook. Because this plugin implements StreamingResponder, pipeline.RunResponse skips it and OnResponseFrame is the dispatch path under all listeners — this method is unreachable from a normal listener. Kept for tests and hypothetical pipelines that call OnResponse directly without going through RunResponse, with a defensive guard against re-recording if the streaming path has already populated state.

func (*MCPParser) OnResponseFrame

func (p *MCPParser) OnResponseFrame(_ context.Context, pctx *pipeline.Context, frame []byte, last bool) pipeline.Action

OnResponseFrame is the streaming-aware response hook. Listeners invoke it once per SSE frame (text/event-stream) and once with last=true at end-of-stream. application/json responses arrive as a single last=true frame — so the same code handles both shapes.

Per-message recording: for MCP, each frame's payload is one complete JSON-RPC response message. We parse + record per message rather than waiting for end-of-stream, so a long-running tools/call surfaces partial results in the session timeline as they arrive — up to maxStreamObserves rows; beyond that the per-frame Observe is suppressed and a single _truncated row is emitted at end-of-stream.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL