Commit graph

255 commits

Author SHA1 Message Date
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
Jonathan Amsterdam
95e96a6daa
jsonschema: improve Resolved.Validate doc (#81) 2025-07-01 10:37:03 -04:00
Albert Sundjaja
bfb9215d16
jsonchema: support additional keywords
Support additional (extra) keywords beyond those specified in the
`Schema` type. The current behavior is additional keywords are dropped.

To follow up:

- There are similar util functions in `mcp/util.go` which don't seem to
be used. Maybe we should move it to `internal/util` instead of
`jsonchema/util.go` package?
- The method `[Un]MarshalJSON` is only on `pointer receiver`, is this
intended? (that means it will only work if we [un]marshal pointer to the
`Schema` instance)
- The fix is using the [un]marshalStructWithMap from `mcp/util.go` and
there are requirements for the function to work properly but these are
not strictly checked e.g. need `json:"-"` tag for the Extra field.

Fixes #69.
2025-07-01 07:02:26 -04:00
Jonathan Amsterdam
2facfc6ffe
jsonschema: unexport ForType (#71)
There's no evidence that it's needed.

Also, improve doc and error messages.
2025-06-30 14:44:40 -04:00
Jonathan Amsterdam
c657cc3836
.github: add PR template (#75)
The default template is too elaborate. Add a simpler one.
2025-06-30 14:30:30 -04:00
Jonathan Amsterdam
beed2f0677
mcp: small changes to CallTool structs (#60)
- Use `any` for CallToolResult.StructuredContent.

- Change the non-generic structs into aliases for the generic ones.
2025-06-30 13:47:24 -04:00
Sam Thanawalla
bc59932176
design: add design for rate limiting (#36)
I added an example for how rate limiting should be implemented using
middleware.

Fixes #22 

## Motivation and Context
<!-- Why is this change needed? What problem does it solve? -->
Rate limiting can be enabled using middleware. This adds an example on
how to do that.

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

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

## 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)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] 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-06-30 09:49:55 -04:00
SADIK KUZU
032c62c8ad
Fix typos (#66)
This pull request addresses multiple minor documentation and code
comment fixes to correct typos and improve clarity. These changes do not
introduce functional modifications but enhance readability and
professionalism.

### Documentation Fixes:

* Corrected a typo in the "Security Considerations" section header in
`design/design.md`. ("Securty" → "Security")
* Fixed spelling errors in the "Governance and Community" section of
`design/design.md`. ("accomodating" → "accommodating")
* Updated the "Proposals" section in `design/design.md` to fix a typo.
("accomodate" → "accommodate")

### Code Comment Fixes:

* Corrected a typo in a comment in `mcp/logging.go`. ("LoggingMesssage"
→ "LoggingMessage")
* Fixed a typo in a comment in `mcp/streamable.go`. ("priviledged" →
"privileged")

<!-- Provide a brief summary of your changes -->

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

This PR is for fixing some typos in the repo

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

## 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)
- [ ] 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. -->
- [ ] I have read the [MCP
Documentation](https://modelcontextprotocol.io)
- [ ] My code follows the repository's style guidelines
- [ ] New and existing tests pass locally
- [ ] I have added appropriate error handling
- [ ] I have added or updated documentation as needed

## Additional context
<!-- Add any other context, implementation notes, or design decisions
-->
2025-06-30 08:11:04 -04:00
cryo
45f700ea13
mcp/client: fix typo in changeAndNotify&ReadResource (#68)
This PR updates the comments for func changeAndNotify and ReadResource to correct typos and improve clarity.
2025-06-30 07:51:01 -04:00
Robert Findley
8a3f272dbb
internal/readme: fix server example (#63)
Fix an example using params.Name instead of params.Arguments.Name. All
credit due to @A11Might for noticing this. Sending a separate PR to keep
the internal/readme source consistent.
2025-06-27 15:43:14 -04:00
Robert Jackson
c47dbcd7b2
mcp: Implement KeepAlive for client and server
Implement KeepAlive features from the design doc.

Fixes #24.
2025-06-27 08:24:05 -04:00
Robert Jackson
9f6dd5c32e
feat(ci): Ensure that the README.md is in sync with internal/readme (#53) 2025-06-26 12:45:44 -04:00
Robert Findley
0e2abbb107
docs: add GitHub discussions to README.md and CONTRIBUTING.md (#49)
Also, update a pkgsite link in the README.
2025-06-26 09:37:21 -04:00
Jonathan Amsterdam
ff0d746521
mcp: fix some documentation (#41)
- Add some doc strings.

- Remove markdown-like notations.
2025-06-25 17:38:37 -04:00
Jonathan Amsterdam
81eb55e6bc
mcp: change default-true fields to pointers (#44)
Some logically boolean fields default to true. We cannot use bool for these fields, because it defaults to false. So use *bool.
2025-06-25 17:37:45 -04:00
Robert Findley
376d9499d6
README.md: add description to tool input (#38) 2025-06-25 16:57:45 -04:00
Jonathan Amsterdam
92859ef391
mcp: rename LoggingMessage to Log (#42)
Use a verb for this method name.
2025-06-25 16:52:37 -04:00
Gerard Adam
10dcf48fdb
mcp: fix tool result in examples (#45) 2025-06-25 16:48:21 -04:00
Jonathan Amsterdam
600ba61efe
mcp: fix CallToolResultFor[T] unmarshaling (#46)
Add an UnmarshalJSON method for that type.

Add a test.
2025-06-25 16:45:58 -04:00
Robert Jackson
057f525da2
feat(ci): Add check to ensure go fmt has been ran (#43) 2025-06-25 15:31:44 -04:00
Jonathan Amsterdam
09181c2c2e
mcp: use correct ResourceNotFound code (#35) 2025-06-25 14:57:07 -04:00
Sam Thanawalla
1478ba7e0e
design: add design for completion (#34) 2025-06-25 14:56:19 -04:00
qiaodev
abb650e45b
docs: fix README (#32) 2025-06-25 13:54:29 -04:00
Jonathan Amsterdam
1373ddf905
mcp: add a TODO (#31) 2025-06-25 13:19:35 -04:00
Robert Findley
5aabc33c9b
all: minor cleanup and README improvements (#30)
Clean up some inaccurate comments, and update the README to strengthen
warnings about the current status.
2025-06-25 13:12:39 -04:00
Robert Findley
204b59483b
mcp,design: revert 'content' back to an interface type (#29)
After some experience with the flattened version of Content, we see that
it can easily lead to incorrect usage and is a harder API to read.
Therefore, this CL changes back to a design similar to what we had prior
to https://go.dev/cl/672415, though opting to promote content
unmarshalling to the protocol types that use it, which leads to an
overall simpler api.
2025-06-25 13:09:05 -04:00
Robert Findley
d6ea827820
CONTRIBUTING.md: s/steering commitee/working group (#9)
Update the contribution guide to rename 'steering committee' to 'working
group', as approved by counsel. 'Steering committee' was confusing in
the context of MCP, which has its own steering committee.
2025-06-25 09:52:14 -04:00
Jonathan Amsterdam
3da831b0c9
mcp: move to 2025-06-18 schema (#8)
* mcp: move to 2025-06-18 schema

Add types and fields for the latest MCP schema.

The main challenge here was dealing with the presence of _meta fields
on many types, like Tool, Prompt and Resource.

- Distinguish between the _meta field of a request's params, which
  includes a progress token, from the _meta field on other types,
  which is simply a map.

- Redefine GetMeta to return a pointer to the map. We wanted to avoid
  that, but I don't see a clean way to do so. An alternative would be
  to have GetMeta return a map, and SetMeta to set it.

- Provide GetProgressToken for requests only (not notifications or other
  types).

- Still to do: deal with the meta and annotation fields of ContentBlock,
  which are currently duplicated for Resource and ResourceContents.

* Meta and progress token redesign
2025-06-25 09:48:33 -04:00
Robert Findley
735ad517ed
CONTRIBUTING.md: further clarify 'steering committee' (#5)
Futher clarify that the 'steering committee' is what we normally would
call a 'working group', in the preamble to the antitrust policy. We'd
like to also update the policy itself, but need approval from counsel.
2025-06-24 16:23:15 -04:00
Jonathan Amsterdam
9305d6994f
generate.go: remove
Remove the code generator. It has served its purpose.
From now on, we will modify protocol.go directly.
2025-06-23 20:16:40 -04:00