Commit graph

458 commits

Author SHA1 Message Date
Suraj Bobade
8c42b69817
SSE: Add support for SSE handler options (#508) v0.6.0
mcp/sse: add support to provide for options for SSE transport

- Add SSEOptions struct to define SSE handler options.
- Update Signature of NewSSEHandler to accept SSEOptions [braking
change]
- Update unit test
- Update example test

Fixes https://github.com/modelcontextprotocol/go-sdk/issues/507,
https://github.com/modelcontextprotocol/go-sdk/issues/503
2025-09-19 13:01:57 -04:00
Jonathan Amsterdam
4e9a387d04
doc: document logging (#497)
For #442.
2025-09-19 11:58:58 -04:00
Robert Findley
84a568bf89
readme: update README for v0.6.0 (#506)
Also significantly lessen our warnings, and note that this is a release
candidate, rewrite Acknowledgements to be Acknowledgements /
Alternatives, since other MCP SDKs continue to be actively developed.
2025-09-19 11:54:10 -04:00
Jonathan Amsterdam
8b6391b173
docs: explain how to get TokenInfo (#502) 2025-09-19 11:50:42 -04:00
Jonathan Amsterdam
4fa725857c
docs: document resources (#505) 2025-09-19 11:46:50 -04:00
Robert Findley
5985a7cbba
docs: document tool support (#498)
Document tool support, and tweak the wording for prompts.

For #442
2025-09-19 10:48:59 -04:00
Robert Findley
28753c9f12
docs: document completion support (#495) 2025-09-18 14:27:35 -04:00
Jonathan Amsterdam
ff81f2f35a
docs: add auth and security sections (#492)
For #442.
2025-09-18 14:25:35 -04:00
Robert Findley
1696b595c6
mcp: fix several goroutine leaks in tests (#494)
Fix some (but not all) goroutine leaks in tests. Others were nontrivial,
because they relate to streamable http.

For #489.
2025-09-18 14:24:45 -04:00
Robert Findley
49d45a8097
docs: document pagination (#491)
For #442
2025-09-18 13:31:54 -04:00
Jonathan Amsterdam
fed5106631
mcp: add prompt feature doc (#487) 2025-09-18 12:27:02 -04:00
Friedrich Große
02f0b25286
Move GetSessionID closure into ServerOptions (#488)
Fixes: #478.
2025-09-18 12:21:02 -04:00
Robert Findley
353d46ff86
mcp: remove the StreamID type (#490)
The streamID type did not carry its weight. Remove it.

Fixes #484.
2025-09-18 12:01:07 -04:00
Frenchie
1cfd489d72
chore(deps): add dependabot and SHA-pin workflow deps (#456)
Introduces Dependabot & SHA-pins workflow deps, as per the [Discord
thread](https://discord.com/channels/1358869848138059966/1399986970851282954/1415896798144368762).

A note on the commit message: I used convention commit format out of
habit, but can rewrite the it to adhere to the
[styleguide](https://go.dev/wiki/CommitMessage) if critical.
2025-09-18 11:25:19 -04:00
Robert Findley
f5cee0aa32
docs: document stateless mode and custom transports (#485) 2025-09-18 11:22:40 -04:00
dependabot[bot]
d870f5e638
build(deps): bump github.com/golang-jwt/jwt/v5 from 5.2.1 to 5.2.2 in the go_modules group across 1 directory (#476)
Bumps the go_modules group with 1 update in the / directory:
[github.com/golang-jwt/jwt/v5](https://github.com/golang-jwt/jwt).

Updates `github.com/golang-jwt/jwt/v5` from 5.2.1 to 5.2.2
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/golang-jwt/jwt/releases">github.com/golang-jwt/jwt/v5's
releases</a>.</em></p>
<blockquote>
<h2>v5.2.2</h2>
<h2>What's Changed</h2>
<ul>
<li>Fixed <a
href="https://github.com/golang-jwt/jwt/security/advisories/GHSA-mh63-6h87-95cp">https://github.com/golang-jwt/jwt/security/advisories/GHSA-mh63-6h87-95cp</a>
by <a
href="https://github.com/mfridman"><code>@​mfridman</code></a></li>
<li>Fixed some typos by <a
href="https://github.com/Ashikpaul"><code>@​Ashikpaul</code></a> in <a
href="https://redirect.github.com/golang-jwt/jwt/pull/382">golang-jwt/jwt#382</a></li>
<li>build: add go1.22 to ci workflows by <a
href="https://github.com/mfridman"><code>@​mfridman</code></a> in <a
href="https://redirect.github.com/golang-jwt/jwt/pull/383">golang-jwt/jwt#383</a></li>
<li>Bump golangci/golangci-lint-action from 4 to 5 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/golang-jwt/jwt/pull/387">golang-jwt/jwt#387</a></li>
<li>Bump golangci/golangci-lint-action from 5 to 6 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/golang-jwt/jwt/pull/389">golang-jwt/jwt#389</a></li>
<li>chore: bump ci tests to include go1.23 by <a
href="https://github.com/mfridman"><code>@​mfridman</code></a> in <a
href="https://redirect.github.com/golang-jwt/jwt/pull/405">golang-jwt/jwt#405</a></li>
<li>Fix jwt -show by <a
href="https://github.com/AlexanderYastrebov"><code>@​AlexanderYastrebov</code></a>
in <a
href="https://redirect.github.com/golang-jwt/jwt/pull/406">golang-jwt/jwt#406</a></li>
<li>docs: typo by <a
href="https://github.com/kvii"><code>@​kvii</code></a> in <a
href="https://redirect.github.com/golang-jwt/jwt/pull/407">golang-jwt/jwt#407</a></li>
<li>Update SECURITY.md by <a
href="https://github.com/oxisto"><code>@​oxisto</code></a> in <a
href="https://redirect.github.com/golang-jwt/jwt/pull/416">golang-jwt/jwt#416</a></li>
<li>Update <code>jwt.Parse</code> example to use
<code>jwt.WithValidMethods</code> by <a
href="https://github.com/mattt"><code>@​mattt</code></a> in <a
href="https://redirect.github.com/golang-jwt/jwt/pull/425">golang-jwt/jwt#425</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a href="https://github.com/Ashikpaul"><code>@​Ashikpaul</code></a>
made their first contribution in <a
href="https://redirect.github.com/golang-jwt/jwt/pull/382">golang-jwt/jwt#382</a></li>
<li><a href="https://github.com/kvii"><code>@​kvii</code></a> made their
first contribution in <a
href="https://redirect.github.com/golang-jwt/jwt/pull/407">golang-jwt/jwt#407</a></li>
<li><a href="https://github.com/mattt"><code>@​mattt</code></a> made
their first contribution in <a
href="https://redirect.github.com/golang-jwt/jwt/pull/425">golang-jwt/jwt#425</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/golang-jwt/jwt/compare/v5.2.1...v5.2.2">https://github.com/golang-jwt/jwt/compare/v5.2.1...v5.2.2</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="0951d18428"><code>0951d18</code></a>
Merge commit from fork</li>
<li><a
href="c035977d9e"><code>c035977</code></a>
Update Parse example to use WithValidMethods (<a
href="https://redirect.github.com/golang-jwt/jwt/issues/425">#425</a>)</li>
<li><a
href="bc8bdca5cc"><code>bc8bdca</code></a>
Update SECURITY.md (<a
href="https://redirect.github.com/golang-jwt/jwt/issues/416">#416</a>)</li>
<li><a
href="5ec246c074"><code>5ec246c</code></a>
docs: typo (<a
href="https://redirect.github.com/golang-jwt/jwt/issues/407">#407</a>)</li>
<li><a
href="0123f1ad66"><code>0123f1a</code></a>
Fix jwt -show (<a
href="https://redirect.github.com/golang-jwt/jwt/issues/406">#406</a>)</li>
<li><a
href="f961c72abd"><code>f961c72</code></a>
chore: bump ci tests to include go1.23 (<a
href="https://redirect.github.com/golang-jwt/jwt/issues/405">#405</a>)</li>
<li><a
href="62e504c281"><code>62e504c</code></a>
Bump golangci/golangci-lint-action from 5 to 6 (<a
href="https://redirect.github.com/golang-jwt/jwt/issues/389">#389</a>)</li>
<li><a
href="1a56dcf532"><code>1a56dcf</code></a>
Bump golangci/golangci-lint-action from 4 to 5 (<a
href="https://redirect.github.com/golang-jwt/jwt/issues/387">#387</a>)</li>
<li><a
href="c8043eab61"><code>c8043ea</code></a>
build: add go1.22 to ci workflows (<a
href="https://redirect.github.com/golang-jwt/jwt/issues/383">#383</a>)</li>
<li><a
href="7c3f6dc563"><code>7c3f6dc</code></a>
Update README.md (<a
href="https://redirect.github.com/golang-jwt/jwt/issues/382">#382</a>)</li>
<li>See full diff in <a
href="https://github.com/golang-jwt/jwt/compare/v5.2.1...v5.2.2">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/golang-jwt/jwt/v5&package-manager=go_modules&previous-version=5.2.1&new-version=5.2.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/modelcontextprotocol/go-sdk/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-09-18 10:22:57 -04:00
Robert Findley
b636b1633b
mcp: fix flaky ExampleLoggingTransport (#483)
Reads are technically racy with writes. Sort for stability.
2025-09-18 08:30:53 -04:00
Jonathan Amsterdam
208bfe25fd
oauthex: new package for oauth extensions (#429)
This package will hold externally visible parts of internal/oauthex.

For now, just add an alias to the ProtectedResourceMetadata struct. This
lets one write MCP-compliant servers.
2025-09-18 08:25:24 -04:00
Jonathan Amsterdam
140b93980c
mcp: add CallToolResult.getError (#481)
Provide a way for middleware to get the error from a tool call,
demonstrating that we can add this functionality without making a
breaking change.

Leave getError unexported for now; we can export it (and setError) at
any time.

For #64.
2025-09-18 08:08:23 -04:00
Robert Findley
b615fa49b1
mcp: add a streamable serving benchmark
Add a benchmark using the streamable HTTP handler, and a more realistic input/output signature. Also expose this handler as an example (both a go example and a server in the examples/ directory).
2025-09-17 17:49:31 -04:00
Rob Findley
a3e753b8d8 mcp: correct the JSON used for unstructured content
Recently, I refactored to fix validation and default application for
structured output. However, I used the wrong byte slice for the
unstructured output. Fix it to use the same bytes as structured output,
with a test.

Fixes #475
2025-09-17 17:42:43 -04:00
Jonathan Amsterdam
22f86c4dfd
internal/testing: add copyright header (#477) 2025-09-16 21:43:18 -04:00
Rob Findley
bd6ffe3b4c mcp: add an example customizing a nested type schema
Add an example that demonstrates how to customize a nested type schema,
which is a recurring problem for our users (see #467).

Fixes #467
Updates #368
2025-09-16 21:34:27 -04:00
Jonathan Amsterdam
b3fb83f272
internal/testing: fake auth server (#296)
This is a fake OAuth authentication server, for use in testing.
2025-09-16 21:12:14 -04:00
Rob Findley
845c29f6b7 mcp: add a benchmark for the MemoryEventStore; remove validation
Add a new benchmark measuring the append and purge performance of the
MemoryEventStore. This benchmark revealed that the store is orders of
magnitude slower than it should be due to conservative validation
(hugely so: 300KB/s vs 568MB/s). Turn off this validation by default.

For #190
2025-09-16 15:50:31 -04:00
Robert Findley
ac2f175214
docs: add feature and troubleshooting documentation (#463)
Add a framework for feature documentation, and start populating it with
our SDK documentation.

This framework is as follows:
- internal/docs/**.src.md is the markdown source for the docs/
  directory.
- The x/example/internal/cmd/weave tool is used to compile these docs to
  the top-level docs, supporting both linked code samples and generated
  tables of contents.
- The readme-check workflow is updated to check these docs as well.
- The structure of these docs follows the MCP spec.
- Wherever possible, example code is linked from actual Go documentation
  examples, so that it is testable.

Some minor modifications to the weave tool were made to support this
framework.

Additionally, partially fill out this documentation with content on
base protocol and client features, as well as troubleshooting help.

Along the way, a bug was encountered that our LoggingTransport was not
concurrency safe. This is fixed with a mutex.

Fixes https://github.com/modelcontextprotocol/go-sdk/issues/466
Fixes https://github.com/modelcontextprotocol/go-sdk/issues/409
Updates https://github.com/modelcontextprotocol/go-sdk/issues/442
2025-09-16 11:13:40 -04:00
Jonathan Amsterdam
ab4d6218c6 mcp: tweak ProgressNotificationParams 2025-09-16 10:37:47 -04:00
Rob Findley
c2c810bf40 mcp: update jsonschema-go to v0.2.3, prepare README v0.5.0 2025-09-12 12:00:54 -04:00
Rob Findley
159933cfa3 mcp: speed up TestCommandTransportDuration
At 7s, this test was 70% of our test execution time on my computer.
Speed it up by mutating the defaultTerminateDuration for the purposes of
the test.

Also update our test workflow to use go1.25, now that it's out.
2025-09-12 12:00:29 -04:00
Rob Findley
9f1b8646bd mcp: propertly validate against JSON, independent of Go values
Our validation logic was avoiding double-unmarshalling as much as
possible, by parsing before validation and validating the Go type.

This only works if the Go type has the same structure as its JSON
representation, which may not be the case in the presence of types with
custom MarshalJSON or UnmarshalJSON methods (such as time.Time).

But even if the Go type doesn't use any custom marshalling, validation
is broken, because we can't differentiate zero values from missing
values.

Bite the bullet and use double-unmarshalling for both input and output
schemas. Coincidentally, this fixes three bugs:
- We were accepting case-insensitive JSON keys, since we parsed first,
  even though they should have been rejected. A number of tests were
  wrong.
- Defaults were overriding present-yet-zero values, as noted in an
  incorrect test case.
- When "arguments" was missing, validation wasn't performed, no defaults
  were applied, and unmarshalling failed even if all properties were
  optional.

First unmarshalling to map[string]any allows us to fix all these bugs.
Unfortunately, it means a 3x increase in the number of reflection
operations (we need to unmarshal, apply defaults and validate,
re-marshal with the defaults, and then unmarshal into the Go type).
However, this is not likely to be a significant overhead, and we can
always optimize in the future.

Update github.com/google/jsonschema-go to pick up necessary improvements
supporting this change.

Additionally, fix the error codes for invalid tool parameters, to be
consistent with other SDKs (Invalid Params: -32602).

Fixes #447
Fixes #449
Updates #450
2025-09-12 10:50:19 -04:00
Rob Findley
eddef064df all: add a test that checks for missing or mismatching file copyright
In #294, we accidentally checked files with the default Go project
copyright header. Avoid this in the future with a copyright test.
2025-09-11 13:53:22 -04:00
Sam Thanawalla
b66679350e
transport.go: disable stdio batching for newer protocols (#453)
This PR disables batching support for stdio by storing the negotiated
protocol version and comparing it to protocolVersion20250618.

Fixes: #21
2025-09-11 13:33:46 -04:00
ankitm123
bf3ff50a16 mcp: remove json-rpc batching for more recent protocol versions
JSON-RPC batching support is removed for protocol versions greater than or
equal to protocolVersion20250618

Fixes #21
2025-09-11 10:50:56 -04:00
Rob Findley
872b437b2a internal/readme: use go:generate rather than Make
Simplify the readme generation to just use go:generate, no longer
depending on Make or bash.

Subsequent CLs will generate more documentation in a similar manner.

For #442
2025-09-11 10:38:07 -04:00
Sam Thanawalla
3a66cf3997
go.mod: update jsonschema to v0.2.2 (#446)
This version of jsonschema fixes embedded structs.

Fixes: #437
2025-09-11 10:21:02 -04:00
Rob Findley
728e0e3ac9 mcp: improve error messages from Wait for streamable clients
Previously, the error message received from ClientSession.Wait would
only report the closeErr, which would often be nil even if the client
transport was broken. Wait should return the reason the session
terminated, if abnormal.

I'm not sure of the exact semantics of this, but surely returning nil is
less useful than returning a meaningful non-nil error. We can refine our
handling of errors once we have more feedback.

Also add a test for client termination on HTTP server shutdown,
described in #265. This should work as long as (1) the session is
stateful (with a hanging GET), or (2) the session is stateless but the
client has a keepalive ping.

Also: don't send DELETE if the session was terminated with 404; +test.

Fixes #265
2025-09-10 11:24:26 -04:00
Rob Findley
b1c75f04d8 mcp: remove deprecated transport constructors
In #272, we made transports open structs and deprecated their
constructors. However, we left the constructors in place to allow go:fix
directives to facilitate migration.

Now let's remove the constructors before cutting the release.

Fixes #305
2025-09-10 11:21:46 -04:00
Rob Findley
5bbca40032 mcp: fix typo in protocolVersion20241105
This version was so last year.

Fixes #432
2025-09-09 11:21:18 -04:00
Jonathan Amsterdam
a082e0764d
go.mod: update to jsonschema v0.2.1 2025-09-09 10:34:38 -04:00
Robert Findley
4f197bc3b4
internal/oauthex: fix license headers (#430)
The files in the oauthex package used the default Go license header,
rather than the MCP SDK license header (an accident of tooling). We
should fix this while jba@google.com is the only author of this code.

A subsequent PR will add a lint check to prevent this in the future.
2025-09-08 13:36:50 -04:00
Clément RUFFINONI
bae3558d49
mcp: allow configurable terminate duration for CommandTransport (#363)
Make the process termination timeout configurable instead of using a
hardcoded 5-second delay. This allows applications to customize the
termination behavior based on their specific needs.

Fixes #322.
2025-09-08 13:28:32 -04:00
Flc゛
e06cc69dc4
fix(docs): correct number in README (#427) 2025-09-08 02:11:31 -04:00
Rob Findley
4656930de8 mcp: avoid "null" when tools fail to return content v0.4.0
For some reason, this was a regression from v0.3.1, for some of our
examples. Fix it and address the existing TODO.
2025-09-05 16:57:02 -04:00
Robert Findley
46e767e646
Update README for v0.4.0 (#422)
As we prepare to release v0.4.0, update the README to reference the new
version.
2025-09-05 16:30:59 -04:00
Jonathan Amsterdam
2a00640e1e
mcp/internal/oauthex: auth server metadata (#294)
Implement the Authorization Server Metadata spec.
2025-09-05 14:17:21 -04:00
Robert Findley
40b6bd30f1
all: add examples of customizing tool schemas, and clarify documentation (#421)
Add example/server/toolschemas, which demonstrates various ways to
customize tool schemas, and illustrates the differences between
ToolHandler and ToolHandlerFor.

Fixes #385
Fixes #386
For #368
2025-09-05 14:11:11 -04:00
Rob Findley
5ccd97fafc mcp: allow requests before notifications/initialized
Upon a closer reading of the spec, it is OK for the server to response
to client requests before it has received notifications/initialized (as
long as it has received initialize). This effectively rolls back the fix
from #225.

Some hooks are left for enforcing strictness around server->client
requests prior to initialized. These will be revisited in subsequent
CLs.

For #395
2025-09-05 12:04:58 -04:00
Kason Braley
b774809086
examples: Update and fix outdated (#420)
Update examples/server/rate-limiting to use the same replace directive
strategy as the auth-middleware example, and fix the breakages.

Also remove the unneeded type parameters in examples/client/middleware.
2025-09-05 07:58:26 -04:00
Rob Findley
9d34aff732 mcp: avoid "null" in structuredContent
Avoid a typed nil in structuredContent (yet another typed nil), leading
to "null" on the wire.

Fixes #417
2025-09-04 19:48:51 -04:00
Rob Findley
ee5141621c mcp: be strict about returning the Mcp-Session-Id header
Rather than returning the Mcp-Session-Id header for all responses, only
return it from initialize, per the spec.

Fixes #412
2025-09-04 15:34:05 -04:00