experimental-ext-interceptors/go/sdk
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Ukjae Jeong 1a3e5ef459
Go SDK: Keep audit interceptors non-blocking on errors (#36)
<!-- Provide a brief summary of your changes -->
Ensure Go audit-mode interceptors remain non-blocking when validator or
mutator invocation returns an error.

## Motivation and Context
<!-- Why is this change needed? What problem does it solve? -->

SEP says audit-mode interceptors MUST NOT block execution regardless of
results. The Go SDK already avoided blocking on audit-mode validation
findings, but validator/mutator handler or RPC errors could still abort
unless `FailOpen` was set.

This change makes audit mode consistently non-blocking for invocation
errors as well, matching the existing C# orchestrator behavior where
`isAudit || failOpen` allows execution to continue.

## How Has This Been Tested?
<!-- Have you tested this in a real application? Which scenarios were
tested? -->

Added focused Go chain tests covering audit-mode validator and mutator
errors.

## Breaking Changes
<!-- Will users need to update their code or configurations? -->

None. This only relaxes audit-mode error handling to match SEP
semantics.

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

C# already treats audit-mode invocation failures as non-blocking. This
aligns the Go chain behavior with that implementation and SEP audit-mode
semantics.

Signed-off-by: Ukjae Jeong <jeongukjae@gmail.com>
2026-08-12 14:47:57 -07: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 Go SDK: Keep audit interceptors non-blocking on errors (#36) 2026-08-12 14:47:57 -07: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