experimental-ext-interceptors/go/sdk
Repository files (latest commit first)
Filename Latest commit message Latest commit date
monikaicampbell bd57572579
Go SDK: Align mode with SEP (#40)
<!-- Provide a brief summary of your changes -->

## Motivation and Context
The SEP-2624 spec defines interceptor modes as "active" | "audit". This
change aligns the Go SDK's interceptor `Mode` value with the SEP spec.

## How Has This Been Tested?
- go test ./... from go/sdk — all packages pass (chain, extension,
integrations/gomiddleware).
- gofmt -l . — clean.
- go vet ./... — clean.

## Breaking Changes
Yes:
- The exported constant interceptors.ModeEnforce is removed and replaced
by interceptors.ModeActive. Callers referencing ModeEnforce must rename.
- The serialized mode value changes from "enforce" to "active". Any
config expecting "enforce" must be updated.

## Types of changes
<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] Documentation update

## Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have read the [MCP
Documentation](https://modelcontextprotocol.io)
- [x] My code follows the repository's style guidelines
- [x] New and existing tests pass locally
- [ ] I have added appropriate error handling
- [x] I have added or updated documentation as needed

## Additional context
<!-- Add any other context, implementation notes, or design decisions
-->

Signed-off-by: monikaicampbell <mcampbell350@bloomberg.net>
2026-08-21 15:56:07 +01:00
..
doc Go SDK: Align mode with SEP (#40) 2026-08-21 15:56:07 +01:00
examples Go SDK: Align mode with SEP (#40) 2026-08-21 15:56:07 +01:00
interceptors Go SDK: Align mode with SEP (#40) 2026-08-21 15:56:07 +01:00
go.mod Go SDK: Upgrade MCP SDK and remove vendored copy (#35) 2026-08-12 14:48:17 -07:00
go.sum Go SDK: Upgrade MCP SDK and remove vendored copy (#35) 2026-08-12 14:48:17 -07:00
README.md Go SDK: Align mode with SEP (#40) 2026-08-21 15:56:07 +01:00

MCP Interceptors - Go Implementation

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

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.ModeActive,
    },
    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.
if err := ext.Install(mcpServer); err != nil {
    log.Fatal(err)
}
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