Commit graph go-sdk/internal
Author SHA1 Message Date
Griffin
ef2fc60b5c
docs: adjust example code to remove horizontal scroll bar (#509)
This change adjusts the code example in readme so if you view it in
github it won't show a horizontal scroll bar in code example.

It's trivial change, but I believe it's still an improvement.
2025-09-22 09:07:17 -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
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
Robert Findley
f5cee0aa32
docs: document stateless mode and custom transports (#485) 2025-09-18 11:22:40 -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
22f86c4dfd
internal/testing: add copyright header (#477) 2025-09-16 21:43:18 -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
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
Rob Findley
c2c810bf40 mcp: update jsonschema-go to v0.2.3, prepare README 2025-09-12 12:00:54 -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
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
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
Flc゛
e06cc69dc4
fix(docs): correct number in README (#427) 2025-09-08 02:11:31 -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
Jonathan Amsterdam
29c1650e2a
internal/oauthex: OAuth extensions (#125)
Add a package for the extensions to OAuth 2.0 required by MCP.

This first PR adds Protected Resource Metadata.
2025-09-03 14:20:53 -04:00
Brad Hoekstra
24fc13eb88
cleanup: remove reference to deleted jsonschema package
Signed-off-by: Brad Hoekstra <bhoekstra@google.com>
2025-09-02 14:19:53 -04:00
Rob Findley
f37e549e25 mcp: polish package doc for v0.3.0
Do a pass through the package doc for v0.3.0.
2025-08-22 16:03:15 -04:00
Robert Findley
dd8e3af18d
README: soften the warning, and reference roadmap (#345)
We can warn a little less loudly against using the SDK.
2025-08-21 17:41:38 -04:00
Jonathan Amsterdam
6378df6f24
all: remove ServerRequest[T] for concrete T (#342)
Replace all occurrences of ServerRequest[*CallToolParams] and other
concrete instantiations with CallToolRequest and the like.

Make the XXXRequest types aliases, to preserve the convenience of
generics for the internal machinery (see shared.go, for example.)

I will expand the aliases in a followup PR.
2025-08-21 12:10:53 -04:00
Jonathan Amsterdam
32cf71de3a
mcp: change tool handler design (#325)
Change the design of tool handlers by removing genericity from the common path.
- `ToolHandler` gets the args as a `json.RawMessage`. Using Server.AddTool does no unmarshaling or schema validation.
- `ToolHandlerFor`, installed with `AddTool`, are the only generic pieces.

TODO:
uncomment and fix some tests
2025-08-20 19:36:34 -04:00
Jonathan Amsterdam
8e6ab130d8
mcp: pass TokenInfo to server handler (#292)
If there is a TokenInfo in the request context of a
StreamableServerTransport, then propagate it through to the
ServerRequest that is passed to server methods like callTool.

Fixes #317.
2025-08-20 10:50:16 -04:00
Rob Findley
1a54234c27 mcp: fix reconnect semantics for hanging GET
A few problems with reconnection cropped up in the review of PR #307.
We should allow for the hanging GET to fail with StatusMethodNotAllowed.
This simply means that the server does not support sending notifications
or requests over the GET, which is allowed in the spec.

Also, we should fix the initial delay of the hanging GET request: it
should start with 0 delay. Fix the math for this and subsequent
attempts. Incidentally, this makes the tests take 3s on my machine, down
from 9s.

Also address some comments from #307.
2025-08-20 09:59:52 -04:00
Rob Findley
98e67fdf62 mcp: improvements for 'stateless' streamable servers; 'distributed' mode
Several improvements for the stateless streamable mode, plus support for
a 'distributed' (or rather, distributable) version of the stateless
server.

- Add a 'Stateless' option to StreamableHTTPOptions and
  StreamableServerTransport, which controls stateless behavior.
  GetSessionID may still return a non-empty session ID.
- Audit validation of stateless mode to allow requests with a session
  id. Propagate this session ID to the temporary connection.
- Peek at requests to allow 'initialize' requests to go through to the
  session, so that version negotiation can occur (FIXME: add tests).

Fixes #284
For #148
2025-08-20 09:59:52 -04:00
Robert Findley
46ba813860
.github: add a staticcheck action (#326)
Add a staticcheck step to the lint job of the Test workflow, and fix
reported diagnostics.
2025-08-19 14:58:01 -04:00
Rob Findley
3db848abec mcp: implement a concurrency model for calls
Implement the concurrency model described in #26: notifications are
synchronous, but calls are asynchronous (except for 'initialize'). To
achieve this, implement jsonrpc2.Async(ctx) to signal asynchronous
handling. This is simpler to use than returning ErrAsyncResponse and
calling Respond, and since this is an internal detail we don't need to
worry too much about whether it's idiomatic.

Add tests that verify both features, for both client and server.

Also:
- replace req.ID.IsValid with req.IsCall
- remove the methodHandler type as we can just use MethodHandler

Fixes #26
2025-08-19 11:21:02 -04:00
Jonathan Amsterdam
6e03217c83
mcp: introduce Requests (#267)
Handlers and client/server methods take a single request argument
combining the session and params. This slightly simplifies the signature
for handlers, since there is no longer an often-ignored session
argument.

But more importantly, it opens the door to adding more information in
requests, such as auth info and HTTP request headers.

For #243.
2025-08-12 17:49:50 -04:00
Robert Findley
e097918484
mcp: make transports open structs
As described in #272, there is really no reason for transports to be
closed structs with constructors, since their state must be established
by a call to Connect. Making them open structs simplifies their APIs,
and means that all transports can be extended in the future: we don't
have to create empty Options structs just for the purpose of future
compatibility.

For now, the related constructors and options structs are simply
deprecated (with go:fix directives where possible). A future CL will
remove them prior to the v1.0.0 release.

For #272
2025-08-12 15:14:21 -04:00
Robert Findley
dae88535ba
mcp: support stateless streamable sessions (#277)
Support stateless streamable sessions by adding a GetSessionID function
to StreamableHTTPOptions. If GetSessionID returns "", the session is
stateless, and no validation is performed. This is implemented by
providing the session a trivial initialization state.

To implement this, some parts of #232 (distributed sessions) are copied
over, since they add an API for creating an already-initialized session.

In total, the following new API is added:
- StreamableHTTPOptions.GetSessionID
- ServerSessionOptions (a new parameter to Server.Connect)
- ServerSessionState
- ClientSessionOptions (a new parameter to Client.Connect, for symmetry)

For #10
2025-08-11 16:43:46 -04:00
Jonathan Amsterdam
be1ddf5f80 jsonrpc: paper over race in jsonrpc2 test
In jsonprc2_test.go, binder.Bind starts a goroutine.
That goroutine begins to run during jsonrpc2.bindConnection, and
can race with the setting of conn.write in bindConnection.

This PR adds a sleep, which is a poor way to deal with the race, but
the least invasive change. Better ones include running the test
function after Dial returns, or adding a Connection.Ready method
to detect when initialization is complete.
2025-08-09 16:00:45 -04:00
Rob Findley
c03cd684ab internal/jsonrpc2: allow asynchronous writes
This CL introduces a fundamental change to the jsonrpc2 library:
connection writes, which were previously serialized by the jsonrpc2
library itself, are now allowed to be concurrent.

The change in semantics of the jsonrpc2 library should hopefully be easy
to review, since moving the synchronization to the Writer implementation
is equivalent to the previous logic. However, this change is critical
for the streamable client transport, because it allows for concurrent
http requests to the server.

Consider that a write is a POST to the server, and we don't know that
write succeeded until we get the response header. Previously, we had the
following problem: if the client POSTs a request, and the server blocks
its response on a request made through the hanging GET, the client was
unable to respond because the initial POST is still blocked. We could
update our streamable server transport to force a flush of the response
headers, but we can't guarantee that other servers behave the same way.
Fundamentally, writes in the spec are asynchronous, and we need to
support that.
2025-08-08 12:38:43 -04:00
Sam Thanawalla
b392875dc5
internal/util: move FieldJSONInfo into jsonschema/util (#251)
This CL effectively removes any dependencies on mcp from jsonschema.
This will enable us to move the repo.
This CL also deletes unused marshalStructWithMap and
unmarshalStructWithMap which had a dependency on FieldJSONInfo.

Fixes: #250
2025-08-06 12:07:57 -04:00
Robert Findley
b34ba2149d
mcp: handle bad or missing params (#210)
Audit all cases where params must not be null, and enforce this using
methodInfo via a new methodFlags bitfield that parameterizes method
requirements. Write extensive conformance tests catching all the
(server-side) crashes that were possible.

We should go further and validate schema against the spec, but that is
more indirect, more complicated, and potentially slower. For now we
adopt this more explicit approach.

Still TODO in a subsequent CL: verify the client side of this with
client conformance tests.

Additionally, improve some error messages that were redundant or leaked
internal implementation details.

Fixes #195
2025-07-31 10:57:59 -04:00
CSK
982a0bceca
feat(devcontainer): Adds Dev Container configuration (#154)
This fixes #151, which makes it easier for users to easily use GitHub
Codespaces, providing them with a VS Code like environment with their
preferred settings/themes and the required dependencies, all within the
browser.
2025-07-30 12:54:41 -04:00
Koichi Shiraishi
619bc41581
internal/jsonrpc2,mcp: fix typos (#183)
- add links to doc strings
- use correct symbol and package names
2025-07-28 12:18:03 -04:00
CSK
d437c81cbe
docs: Enhance README formatting and fix relative links (#146)
This PR improves the formatting and internal link structure of both the
main `README.md` and the source file at `internal/readme/README.src.md`.
Changes include:

### 🛠 Changes Made

* Replaced plain-text warning with a GitHub-style admonition block (`>
[!WARNING]`) for improved visibility and consistency with other docs.

Example:

> [!WARNING]
> The SDK should be considered unreleased, and is currently unstable
> and subject to breaking changes. Please test it out and file bug
reports or API
> proposals, but don't use it in real projects. See the issue tracker
for known
> issues and missing features. We aim to release a stable version of the
SDK in
> August, 2025.

* Updated markdown links to use cleaner relative paths:
* Changed `CONTRIBUTING.md` reference to
`[CONTRIBUTING.md](/CONTRIBUTING.md)`
  * Updated `examples/` reference to `[examples/](/examples/)`
* Ensured that all updates were mirrored in both the generated and
source README files.

### 📌 Why It Matters

These changes improve the readability and usability of the
documentation, especially when viewed on GitHub. The updated formatting
helps call attention to important warnings, and fixing relative paths
ensures that links work reliably across platforms and contexts.
2025-07-18 08:43:47 -04:00
Qihang Hu
bf7e518215
docs: fix the service example in the readme and examples/hello (#127)
Fix an example using mcp tag instead of jsonschema.
2025-07-14 11:39:30 -04:00
Ryuji Iwata
b780f1b3e1
Fix jsonrpc path and url (#128)
jsonrpc's github path notation and pkg.go.dev link url are broken.
2025-07-14 08:21:30 -04:00
Vid Drobnič
fe208c144f
jsonrpc: expose encoding and decoding functions (#114)
Expose `jsonrpc2.MakeID`, `jsonrpc2.EncodeMessage` and
`jsonrpc2.DecodeMessage` functions to allow implementing custom
`mcp.Transport`. 

Add an example that demonstrates a custom transport
implementation.

Fixes #110.
2025-07-14 07:01:40 -04:00
Jonathan Amsterdam
78a66a438a
README for v0.2.0 (#118)
Preliminary readme for v0.2.0.

We will make a GH "release" with the release notes.
2025-07-11 08:08:14 -04:00
Jonathan Amsterdam
6c6243c0b0
mcp: NewClient and NewServer take Implementation (#113)
Change the name and version arguments to NewClient and NewServer to a
`*Implementation`, to future-proof against the spec.

Fixes #109.
2025-07-10 16:57:38 -04:00
Jonathan Amsterdam
aebd244981
mcp: new API for features (#88)
BREAKING CHANGE

Change the API for adding tools, prompts, resources and resource
templates to a server.

The ServerXXX types are gone along with the plural Add methods
(AddTools, AddPrompts etc.)
Instead there are single Add methods (AddTool, AddPrompt).
In addition, instead of NewServerTool, there is AddTool[In, Out].

Fixes #73.
2025-07-07 14:54:52 -04:00