Skip to content

mcp: add Extensions field to capabilities per SEP-2133#794

Merged
maciej-kisiel merged 4 commits intomodelcontextprotocol:mainfrom
ymmt2005:issue-777
Feb 17, 2026
Merged

mcp: add Extensions field to capabilities per SEP-2133#794
maciej-kisiel merged 4 commits intomodelcontextprotocol:mainfrom
ymmt2005:issue-777

Conversation

@ymmt2005
Copy link
Contributor

@ymmt2005 ymmt2005 commented Feb 16, 2026

This implements SEP-2133 and resolves #777.

Summary of changes

  • Add Extensions field to ServerCapabilities and ClientCapabilities structs per SEP-2133
  • Add AddExtension helper methods on both types that normalize nil settings to empty maps.
  • Include shallow-copy support via maps.Clone in the existing clone() methods
    • also include shallow-copy support for Experimental field.
  • Add comprehensive tests: unit tests for nil-safety, capability preservation, and over-the-wire round-trip

What's tested

  • go test ./mcp/... passes
  • Server conformance tests pass (30 scenarios, 40 assertions, 0 failures)
  • Client conformance tests match existing baseline (auth scenarios are known failures)

Implement SEP-2133 which defines a formal `extensions` field for MCP
capability negotiation. This allows clients and servers to advertise
support for formally recognized, composable extensions during
initialization, using the "{vendor-prefix}/{extension-name}" identifier
format (e.g., "io.modelcontextprotocol/oauth-client-credentials").

Changes to mcp/protocol.go:

- Add `Extensions map[string]any` field with `json:"extensions,omitempty"`
  tag to both ClientCapabilities and ServerCapabilities, following the
  same pattern as the existing Experimental field.

- Add AddExtension(name string, settings map[string]any) helper methods
  on both capability structs. These lazily initialize the Extensions map
  and normalize nil settings to an empty map[string]any{}, enforcing the
  spec requirement that each extension's settings value must be a JSON
  object (never null).

- Update both clone() methods to clone the Extensions map via
  maps.Clone, preventing shared mutation between the original and cloned
  capabilities. Add "maps" import.

Changes to mcp/server_test.go:

- Add "extensions preserved" test case to TestServerCapabilities,
  verifying extensions set via AddExtension (including nil settings
  normalization) appear in computed capabilities.

- Add "Extensions over wire" test case to TestServerCapabilitiesOverWire,
  verifying extensions round-trip through the initialize handshake.

- Add TestAddExtensionNilSafety, verifying that AddExtension with nil
  settings produces map[string]any{} (not nil) for both
  ServerCapabilities and ClientCapabilities.

Changes to mcp/client_test.go:

- Add "extensions preserved" test case to TestClientCapabilities,
  verifying extensions set via AddExtension appear in computed
  capabilities.

- Add "Extensions over wire" test case to TestClientCapabilitiesOverWire,
  verifying client extensions round-trip through the initialize
  handshake.

Fixes modelcontextprotocol#777
@maciej-kisiel
Copy link
Contributor

Also, please fix lint.

Move misplaced clone() doc comment to its correct location above the
method, and remove TestAddExtensionNilSafety which duplicates coverage
already provided by TestServerCapabilities and TestClientCapabilities.
Shallow-copy the Experimental map in both ClientCapabilities.clone and
ServerCapabilities.clone, matching the existing pattern for Extensions.

Add doc comments clarifying that map values are shallow-copied and that
callers should not modify maps after assigning them.
@ymmt2005
Copy link
Contributor Author

Addressed all review comments, including the lint error.

@maciej-kisiel
Copy link
Contributor

Thanks for contributing!

@maciej-kisiel maciej-kisiel merged commit 3dd2626 into modelcontextprotocol:main Feb 17, 2026
6 checks passed
@ymmt2005 ymmt2005 deleted the issue-777 branch February 18, 2026 01:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extension declaration for MCP Apps

3 participants