Commit graph

284 commits

Author SHA1 Message Date
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
Jonathan Amsterdam
261a63ccc0
mcp: don't panic on bad JSON RPC input (#177)
Log internal errors from the jsonprc2 package, instead of panicking.

Fixes #175.
2025-07-28 10:29:59 -04:00
Jonathan Amsterdam
6e5ba9585f
mcp: remove create-repo.sh (#178)
It was a one-off script whose purpose has been served.
2025-07-28 10:28:01 -04:00
Jonathan Amsterdam
86f71fcb70
mcp: add stream type (#171)
Consolidate several maps into a single struct.

Simplifies the code, for the most part.
2025-07-28 10:27:02 -04:00
cryo
e8c6e03841
fix comment (#180)
update comment for func `clientMethod`
2025-07-28 07:51:49 -04:00
Adam Koszek
1ea7df3267
mcp/examples: Make example more usable. (#160)
I'm making this example more useful for debugging:
- `-port` is supported
- `-host` is supported
- error handling is there.
2025-07-27 08:23:52 -04:00
Jonathan Amsterdam
c879ac3c61
mcp: gracefully handle a nil server in handlers (#164)
If the getServer function passed to NewSSEHandler or
NewStreamableHTTPHandler returns nil, serve a 400 instead of panicking.

Fixes #161.
2025-07-24 10:35:14 -04:00
Jonathan Amsterdam
8dd9a819bb
mcp: panic if AddTool method is given a nil InputSchema (#157)
The spec requires an input schema for every tool.
2025-07-23 16:02:00 -04:00
Sam Thanawalla
94b88a26e0
mcp/server: fix nil PingParams in server.Ping (#163)
Use OrZero in case PingParams is nil to avoid typed nil.

Fixes: #162
2025-07-23 15:40:57 -04:00
Sam Thanawalla
bcbb31f072
mcp: add resource subscriptions (#138)
This CL adds the ability for clients to subscribe and receive updates
for resources as described in
https://modelcontextprotocol.io/specification/2025-06-18/server/resources#subscriptions

Fixes: #23
2025-07-23 15:23:50 -04:00
Jonathan Amsterdam
ea6162ca1c
mcp: incorporate EventStore into StreamableServerTransport (#156)
Use the EventStore interface to implement resumption on the server side.
2025-07-23 13:42:50 -04:00
ln-12
4529904c7a
Fix minor issues in design.md (#158)
design.md: minor fixes
2025-07-23 07:17:57 -04:00
Sam Thanawalla
a911cd0ffd
mcp/streamable: add resumability for the Streamable transport (#133)
This CL implements a retry mechanism to resume SSE streams to recover
from network failures.

For #10
2025-07-22 15:58:29 -04:00
Jonathan Amsterdam
1465442b25
mcp: add EventStore (#152)
Introduce an EventStore interface to store events for resumable streams.

Provide an in-memory implementation.

Still to do: connect to streaming transports.

For #10
2025-07-22 10:21:05 -04:00
Jonathan Amsterdam
9ddad03891
mcp: dedup wire type for image and audio (#149)
Factor out the wire type into a top-level struct.
2025-07-21 11:40:32 -04:00
Jonathan Amsterdam
c6fabbb3d3
jsonschema: inference ignores invalid types (#147)
Add ForLax[T], which ignores invalid types in schema inference instead
of returning an error.

This allows additional customization of a schema after inference does
what it can.

For example, an interface type where all the possible implementations
are known can be described with "oneof".

For #136.
2025-07-21 11:18:04 -04:00
Jonathan Amsterdam
a519c182e8
mcp: export Event (#145)
Export the Event type in preparation for providing user-definable
storage for resumable streams.

Also, move event code to a separate file.

This PR is just renaming and code motion.
2025-07-21 10:54:59 -04:00
Jonathan Amsterdam
3bbe74f8a5
jsonschema: make schema state independent of resolve arguments (#85)
Move schema state that depends on resolution into the Resolved struct.
The remaining unexported schema fields are dependent only on the schema
itself and its sub-schemas.

Now a schema can be resolved multiple times, as itself or as part of
other schemas.

Fixes #84.
2025-07-21 10:41:00 -04:00
Martin Emde
dced3e4503
mcp: don't omit required fields in ImageContent and AudioContent (#95)
Update `ImageContent` and `AudioContent` to use an inline wire format
to ensure that required fields are not omitted during JSON marshaling,
matching TypeScript schema requirements. This follows the TextContent
approach.

- `ImageContent` requires `data` and `mimeType` fields.
- `AudioContent` requires `data` and `mimeType` fields.
2025-07-19 17:08:56 -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
Robert Jackson
dd49b7039b
mcp: Add example of using Middleware for logging purposes (#58)
I needed to implement some logging for our experimental server that we
are building out using the SDK, and figured I could propose an example
that might make it easier for folks in the future.

For #33.
2025-07-17 10:44:15 -04:00
Jonathan Amsterdam
de4b788e59
mcp: fix conformance tests (#132)
- Use new AddXXX API.

- Update goldens to reflect new capability logic.

Fixes #131.
2025-07-14 12:47:58 -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
Robert Findley
a26e1dc253
mcp: fail when streamable http client encounters unsupported content (#130)
The streamable HTTP client is not fully implemented, but did not fail
with meaningful error messages when encountering unsupported content
types from other servers. This may be straightforward to fix, but for
now at least provide a meaningful error message.

For modelcontextprotocol/go-sdk#129.
2025-07-14 10:02:33 -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
Naoki Sega
d570022d03
mcp: add sequential thinking server example (#51)
Add example of implementing mcp on [sequentialthinking
server](https://github.com/modelcontextprotocol/servers/tree/main/src/sequentialthinking),
from [Example Servers](https://modelcontextprotocol.io/examples).

The PR includes dynamic and reflective problem-solving through
structured thinking processes.
The server provides tools for:
- starting thinking sessions
- adding sequential thoughts with step tracking
- revising previous thoughts
- creating alternative reasoning branches
-  reviewing complete processes.

Also, features include thread-safe session management, adaptive planning
that adjusts step counts dynamically.
2025-07-14 08:12:38 -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
Michael Pratt
aa9d4b28be
jsonschema: add missing colon to link block (#126)
Without this, not only is the one link not valid, the entire section is
considered invalid and none of the link references are used.
2025-07-11 17:34:18 -04:00
Jonathan Amsterdam
0f596bde17
jsonschema: improve doc (#122)
Improve the package documentation.

Add a README and LICENSE, anticipating the relocation of this package to
its own module elsewhere.
2025-07-11 11:27:33 -04:00
Jonathan Amsterdam
78a66a438a
README for v0.2.0 (#118) v0.2.0
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
b4febf129b
mcp: advertise a capability if and only if added (#93)
If tools are added to a Server when Run is called, it will send
toolCapabilities to the client. Otherwise it won't. Ditto for prompts
and resources.

For #56.
2025-07-10 15:52:11 -04:00
Jonathan Amsterdam
bfa5e30cd1
jsonrpc: package with JSON-RPC symbols (#117)
Move the aliases to the internal/jsonrpc2 package into their own
package.

Fixes #115.
2025-07-10 14:33:23 -04:00
Jonathan Amsterdam
2c577e564b
jsonschema: support "jsonschema" struct tags (#101)
Struct fields may have the "jsonschema" struct tag, which is used as the
description of the property.

Fixes #47.
2025-07-10 13:51:23 -04:00
Jonathan Amsterdam
c037ba51d2
mcp: negotiate protocol version (#112)
Negotiate the protocol version properly, and set the header on HTTP
transports.

We follow the logic of the Typescript SDK.

- On initialization, the client sends the latest version it can support,
and accepts the version that the server returns if the client supports
it. If not, the connection fails.

- The server accepts the client's version unless it doesn't support it,
in which case it replies with its latest version.

Fixes #103.
2025-07-10 11:06:55 -04:00
Chris Hoff
a1a3510315
mcp/server: make Run return on context cancel (#111)
Make `Server.Run` return when the provided context is canceled.

Add tests for when the `Run` context is cancelled and also for when the
server process receives a signal.

Fixes #107.
2025-07-10 10:07:25 -04:00
Sam Thanawalla
221febd372
examples/rate-limiting: add example for session based rate limiting (#87)
Added an example for session based rate limiting after session.ID() was
exposed.

Fixes #22
2025-07-10 09:06:13 -04:00
Albert Sundjaja
e27a36ed32
jsonchema: add cycle detection (#97)
This PR add cycle detection where it return error instead of waiting for
stack overflow.

This is a fix for https://github.com/modelcontextprotocol/go-sdk/issues/77.
The root cause of the issue was the type being processed is deeply
nested and has cycle. Hence, the heap memory growth is faster than the
stack growth, it went OOM before stack overflow panic can kick in.
2025-07-10 08:55:45 -04:00
Christopher Speller
2b07560be0
mcp: fix sseClientConn to use custom HTTP client (#105)
When attempting to create an OAuth authentication on top of the SSE
transport I discovered the sseClientConn was using http.DefaultClient
for requests instead of the custom client provided via
SSEClientTransportOptions.

This change stores the HTTP client in the sseClientConn struct and uses
it for all requests. Also adds test to verify the custom client is
properly used.
2025-07-09 11:54:53 -04:00
cryo
fbff31af14
mcp/Resource: Refactor URI Template Matching with uritemplate Library (#100)
1. Replaced the `uriTemplateToRegexp` function with the use of
[yosida95/uritemplate](https://github.com/yosida95/uritemplate) to
handle URI template matching as per the request.
2. Updated the relevant test cases to verify the new implementation and
fixed an invalid URI template (`"file:///{}/{a}/{b}"`) that doesn't
conform to RFC 6570 due to an empty `{}` expression.
3. Updated `go.mod` and `go.sum` to reflect the new dependency.

Fixes #11.
2025-07-08 15:52:54 -04:00
Gerard Adam
cdf34cc9da
mcp: memory server example (#90)
This PR adds an example of implementing go-sdk on [memory
server](https://github.com/modelcontextprotocol/servers/tree/main/src/memory).

For #33.
2025-07-08 15:46:47 -04:00
Jonathan Amsterdam
923c2d7a7e
testdata: explain omitted test files (#106)
Explain why certain files are omitted from our tests.
2025-07-08 14:08:01 -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
Martin Emde
328a25d503
mcp: ensure meta is not skipped on blob ResourceContents (#96)
I noticed this while working on #95. Seems Meta was accidentally skipped
in the custom wire format struct.
2025-07-04 14:35:33 -04:00
Martin Emde
c6b229c855
mcp: render blank text field in TextContent instead of omitempty (#91)
The text field is required, but current implementation omits the text
field when it is a blank string.

Some clients fail to parse the response if the text field is omitted. A
blank text result is a valid MCP response.

Claude desktop error message:
```
ClaudeAiToolResultRequest.content.0.text.text: Field required
```

The solution is to return the field even when it is blank by removing
`omitempty`.
2025-07-04 13:46:41 -04:00
Jonathan Amsterdam
ba7a06461a
examples/rate-limiting: change Go version to 1.23 (#89)
The version is 1.25, which doesn't match the main module's go.mod.
2025-07-02 15:11:26 -04:00
cryo
06ae01b141
mcp/streamable: fix typos (#83)
  This PR updates the comments for
`StreamableServerTransport.streamRequests` to correct typos and improve
clarity.
2025-07-02 12:38:25 -04:00
Jonathan Amsterdam
9b6327b3b7
mcp: add Session.ID (#67) v0.1.0
Support retrieving the session ID from client and server sessions.

Fixes #65.
2025-07-01 13:49:23 -04:00
Sam Thanawalla
e1b1cd0072
mcp: implement completion (#55)
This CL implements a completion handler for the server and a complete
method for the client.

Fixes: #12 
<!-- Provide a brief summary of your changes -->

## Motivation and Context
<!-- Why is this change needed? What problem does it solve? -->
This adds support for completion.

## How Has This Been Tested?
<!-- Have you tested this in a real application? Which scenarios were
tested? -->
Added tests and an example.

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

## 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)
- [x] 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
-->
2025-07-01 13:09:15 -04:00
Xin
92b6983c1c
mcp: add ResourceLink type (#76)
This PR introduces the ResourceLink type to represent links to
resources. The new type includes the following fields: `uri`, `name`,
`title`, `description`, `mimeType`, `size`, and `_meta`.

This implementation conforms to the `ResourceLink` schema introduced in
the [MCP schema
2025-06-18](1cfdf1e7a8/schema/2025-06-18/schema.json (L1826)).

Note: `ResourceLink` extends from the `Resource` type in the MCP schema.
As such, it inherits support for optional fields like `title`, `_meta`,
etc. Thus, `URI`, `Name`, `Title`, `Description`, and `Size` are added
to the `wireContent`

For reference, the [TypeScript SDK test
suite](fb4d07f0ee/src/types.test.ts (L43))
provides examples demonstrating valid ResourceLink objects with all
optional fields populated.

https://modelcontextprotocol.io/specification/2025-06-18/server/tools#resource-links
- [ResourceLink JSON
Schema](1cfdf1e7a8/schema/2025-06-18/schema.json (L1826))

Signed-off-by: Xin Fu <xfu83@bloomberg.net>

Fixes #14.
2025-07-01 12:41:22 -04:00