experimental-ext-interceptors/go/sdk
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Ukjae Jeong 99bc7c9bb0
Align capability key to SEP-2133 extensions format (#25)
Both SDKs now use Capabilities.Extensions with key
"io.modelcontextprotocol/interceptors". Previously C# used the short key
"interceptors" and Go used Capabilities.Experimental. SEP capability
example updated to match.

https://modelcontextprotocol.io/seps/2133-extensions

---------

Signed-off-by: Ukjae Jeong <jeongukjae@gmail.com>
2026-07-06 10:29:21 +01:00
..
doc Align capability key to SEP-2133 extensions format (#25) 2026-07-06 10:29:21 +01:00
examples Go SDK: Align hooks with SEP (#23) 2026-06-16 15:49:49 +01:00
interceptors Align capability key to SEP-2133 extensions format (#25) 2026-07-06 10:29:21 +01:00
vendor Route go interceptor methods through receiving middleware (#10) 2026-04-30 17:14:55 +01:00
go.mod Implement Go interceptor chain (#4) 2026-04-29 15:29:25 +01:00
go.sum Implement Go interceptor chain (#4) 2026-04-29 15:29:25 +01:00
README.md Go SDK: Align hooks with SEP (#23) 2026-06-16 15:49:49 +01:00

MCP Interceptors - Go Implementation

Go implementation of the MCP Interceptor Extension based on SEP-2624.

Note: Currently the MCP SDK is vendored, in-order to add the Protocol Methods needed for interceptors.

Quick Start

mcpServer := mcp.NewServer(&mcp.Implementation{
    Name:    "my-server",
    Version: "0.1.0",
}, nil)

// Create an extension and register interceptors.
ext := extension.New()

// Register a validator that blocks dangerous tool calls.
ext.AddInterceptor(&interceptors.Validator{
    Metadata: interceptors.Metadata{
        Name: "block-dangerous",
        Hooks: []interceptors.Hook{{
            Events: []string{interceptors.EventToolsCall},
            Phase:  interceptors.PhaseRequest,
        }},
        Mode: interceptors.ModeEnforce,
    },
    Handler: func(_ context.Context, inv *interceptors.Invocation) (*interceptors.ValidationResult, error) {
        raw := inv.Payload.(json.RawMessage)
        var params struct{ Name string `json:"name"` }
        json.Unmarshal(raw, &params)
        // validate the request...
        return &interceptors.ValidationResult{Valid: true}, nil
    },
})

// Install on the server and create a chain for middleware.
ext.Install(mcpServer)
chain, err := ext.LocalChain(ctx, mcpServer)
mcpServer.AddReceivingMiddleware(gomiddleware.Middleware(chain))

mcpServer.Run(context.Background(), &mcp.StdioTransport{})

See examples/ for complete working examples.

Documentation

  • DESIGN.md — architecture, execution model, integration with the go-sdk.
  • PERFORMANCE.md — per-request cost model, allocation summary, and optimization notes.
  • CONFORMANCE.md — SEP conformance status.

Package API documentation is available via go doc:

go doc github.com/modelcontextprotocol/ext-interceptors/go/sdk/interceptors