Skip to content

Commit 4d5aefc

Browse files
authored
Merge branch 'main' into fr/add_dependabot
2 parents b4d1678 + b615fa4 commit 4d5aefc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2414
-141
lines changed

.github/workflows/readme-check.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
name: README Check
22
on:
3-
workflow_dispatch:
3+
workflow_dispatch:
44
pull_request:
55
paths:
66
- 'internal/readme/**'
77
- 'README.md'
8-
8+
- 'internal/docs/**'
9+
- 'docs/**'
10+
911
permissions:
1012
contents: read
1113

@@ -19,13 +21,13 @@ jobs:
1921
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
2022
- name: Check README is up-to-date
2123
run: |
22-
go generate ./internal/readme
24+
go generate ./...
2325
if [ -n "$(git status --porcelain)" ]; then
24-
echo "ERROR: README.md is not up-to-date!"
26+
echo "ERROR: docs are not up-to-date!"
2527
echo ""
26-
echo "The README.md file differs from what would be generated by `go generate ./internal/readme`."
27-
echo "Please update internal/readme/README.src.md instead of README.md directly,"
28-
echo "then run `go generate ./internal/readme` to regenerate README.md."
28+
echo "The docs differ from what would be generated by `go generate ./...`."
29+
echo "Please update internal/**/*.src.md instead of directly editing README.md or docs/ files,"
30+
echo "then run `go generate ./...` to regenerate docs."
2931
echo ""
3032
echo "Changes:"
3133
git status --porcelain
@@ -34,4 +36,4 @@ jobs:
3436
git diff
3537
exit 1
3638
fi
37-
echo "README.md is up-to-date"
39+
echo "Docs are up-to-date."

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
runs-on: ubuntu-latest
4040
strategy:
4141
matrix:
42-
go: ["1.23", "1.24", "1.25.0-rc.3"]
42+
go: ["1.23", "1.24", "1.25"]
4343
steps:
4444
- name: Check out code
4545
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<!-- Autogenerated by weave; DO NOT EDIT -->
2-
# MCP Go SDK v0.4.0
2+
# MCP Go SDK v0.5.0
33

44
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/modelcontextprotocol/go-sdk)
55

66
***BREAKING CHANGES***
77

88
This version contains breaking changes.
99
See the [release notes](
10-
https://github.com/modelcontextprotocol/go-sdk/releases/tag/v0.4.0) for details.
10+
https://github.com/modelcontextprotocol/go-sdk/releases/tag/v0.5.0) for details.
1111

1212
[![PkgGoDev](https://pkg.go.dev/badge/github.com/modelcontextprotocol/go-sdk)](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk)
1313

docs/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!-- Autogenerated by weave; DO NOT EDIT -->
2+
These docs are a work-in-progress.
3+
4+
# Features
5+
6+
These docs mirror the [official MCP spec](https://modelcontextprotocol.io/specification/2025-06-18).
7+
8+
## Base Protocol
9+
10+
1. [Lifecycle (Clients, Servers, and Sessions)](protocol.md#lifecycle).
11+
1. [Transports](protocol.md#transports)
12+
1. [Stdio transport](protocol.md#stdio-transport)
13+
1. [Streamable transport](protocol.md#streamable-transport)
14+
1. [Custom transports](protocol.md#stateless-mode)
15+
1. [Authorization](protocol.md#authorization)
16+
1. [Security](protocol.md#security)
17+
1. [Utilities](protocol.md#utilities)
18+
1. [Cancellation](utilities.md#cancellation)
19+
1. [Ping](utilities.md#ping)
20+
1. [Progress](utilities.md#progress)
21+
22+
## Client Features
23+
24+
1. [Roots](client.md#roots)
25+
1. [Sampling](client.md#sampling)
26+
1. [Elicitation](clients.md#elicitation)
27+
28+
## Server Features
29+
30+
1. [Prompts](server.md#prompts)
31+
1. [Resources](server.md#resources)
32+
1. [Tools](tools.md)
33+
1. [Utilities](server.md#utilities)
34+
1. [Completion](server.md#completion)
35+
1. [Logging](server.md#logging)
36+
1. [Pagination](server.md#pagination)
37+
38+
# TroubleShooting
39+
40+
See [troubleshooting.md](troubleshooting.md) for a troubleshooting guide.

docs/client.md

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
<!-- Autogenerated by weave; DO NOT EDIT -->
2+
# Support for MCP client features
3+
4+
1. [Roots](#roots)
5+
1. [Sampling](#sampling)
6+
1. [Elicitation](#elicitation)
7+
8+
## Roots
9+
10+
MCP allows clients to specify a set of filesystem
11+
["roots"](https://modelcontextprotocol.io/specification/2025-06-18/client/roots).
12+
The SDK supports this as follows:
13+
14+
**Client-side**: The SDK client always has the `roots.listChanged` capability.
15+
To add roots to a client, use the
16+
[`Client.AddRoots`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#AddRoots)
17+
and
18+
[`Client.RemoveRoots`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#Client.RemoveRoots)
19+
methods. If any servers are already [connected](protocol.md#lifecycle) to the
20+
client, a call to `AddRoot` or `RemoveRoots` will result in a
21+
`notifications/roots/list_changed` notification to each connected server.
22+
23+
**Server-side**: To query roots from the server, use the
24+
[`ServerSession.ListRoots`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ServerSession.ListRoots)
25+
method. To receive notifications about root changes, set
26+
[`ServerOptions.RootsListChangedHandler`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ServerOptions.RootsListChangedHandler).
27+
28+
```go
29+
func Example_roots() {
30+
ctx := context.Background()
31+
32+
// Create a client with a single root.
33+
c := mcp.NewClient(&mcp.Implementation{Name: "client", Version: "v0.0.1"}, nil)
34+
c.AddRoots(&mcp.Root{URI: "file://a"})
35+
36+
// Now create a server with a handler to receive notifications about roots.
37+
rootsChanged := make(chan struct{})
38+
handleRootsChanged := func(ctx context.Context, req *mcp.RootsListChangedRequest) {
39+
rootList, err := req.Session.ListRoots(ctx, nil)
40+
if err != nil {
41+
log.Fatal(err)
42+
}
43+
var roots []string
44+
for _, root := range rootList.Roots {
45+
roots = append(roots, root.URI)
46+
}
47+
fmt.Println(roots)
48+
close(rootsChanged)
49+
}
50+
s := mcp.NewServer(&mcp.Implementation{Name: "server", Version: "v0.0.1"}, &mcp.ServerOptions{
51+
RootsListChangedHandler: handleRootsChanged,
52+
})
53+
54+
// Connect the server and client...
55+
t1, t2 := mcp.NewInMemoryTransports()
56+
if _, err := s.Connect(ctx, t1, nil); err != nil {
57+
log.Fatal(err)
58+
}
59+
if _, err := c.Connect(ctx, t2, nil); err != nil {
60+
log.Fatal(err)
61+
}
62+
63+
// ...and add a root. The server is notified about the change.
64+
c.AddRoots(&mcp.Root{URI: "file://b"})
65+
<-rootsChanged
66+
// Output: [file://a file://b]
67+
}
68+
```
69+
70+
## Sampling
71+
72+
[Sampling](https://modelcontextprotocol.io/specification/2025-06-18/client/sampling)
73+
is a way for servers to leverage the client's AI capabilities. It is
74+
implemented in the SDK as follows:
75+
76+
**Client-side**: To add the `sampling` capability to a client, set
77+
[`ClientOptions.CreateMessageHandler`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ClientOptions.CreateMessageHandler).
78+
This function is invoked whenever the server requests sampling.
79+
80+
**Server-side**: To use sampling from the server, call
81+
[`ServerSession.CreateMessage`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ServerSession.CreateMessage).
82+
83+
```go
84+
func Example_sampling() {
85+
ctx := context.Background()
86+
87+
// Create a client with a sampling handler.
88+
c := mcp.NewClient(&mcp.Implementation{Name: "client", Version: "v0.0.1"}, &mcp.ClientOptions{
89+
CreateMessageHandler: func(_ context.Context, req *mcp.CreateMessageRequest) (*mcp.CreateMessageResult, error) {
90+
return &mcp.CreateMessageResult{
91+
Content: &mcp.TextContent{
92+
Text: "would have created a message",
93+
},
94+
}, nil
95+
},
96+
})
97+
98+
// Connect the server and client...
99+
ct, st := mcp.NewInMemoryTransports()
100+
s := mcp.NewServer(&mcp.Implementation{Name: "server", Version: "v0.0.1"}, nil)
101+
session, err := s.Connect(ctx, st, nil)
102+
if err != nil {
103+
log.Fatal(err)
104+
}
105+
defer session.Close()
106+
107+
if _, err := c.Connect(ctx, ct, nil); err != nil {
108+
log.Fatal(err)
109+
}
110+
111+
msg, err := session.CreateMessage(ctx, &mcp.CreateMessageParams{})
112+
if err != nil {
113+
log.Fatal(err)
114+
}
115+
fmt.Println(msg.Content.(*mcp.TextContent).Text)
116+
// Output: would have created a message
117+
}
118+
```
119+
120+
## Elicitation
121+
122+
[Elicitation](https://modelcontextprotocol.io/specification/2025-06-18/client/elicitation)
123+
allows servers to request user inputs. It is implemented in the SDK as follows:
124+
125+
**Client-side**: To add the `elicitation` capability to a client, set
126+
[`ClientOptions.ElicitationHandler`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ClientOptions.ElicitationHandler).
127+
The elicitation handler must return a result that matches the requested schema;
128+
otherwise, elicitation returns an error.
129+
130+
**Server-side**: To use elicitation from the server, call
131+
[`ServerSession.Elicit`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ServerSession.Elicit).
132+
133+
```go
134+
func Example_elicitation() {
135+
ctx := context.Background()
136+
ct, st := mcp.NewInMemoryTransports()
137+
138+
s := mcp.NewServer(&mcp.Implementation{Name: "server", Version: "v0.0.1"}, nil)
139+
ss, err := s.Connect(ctx, st, nil)
140+
if err != nil {
141+
log.Fatal(err)
142+
}
143+
defer ss.Close()
144+
145+
c := mcp.NewClient(testImpl, &mcp.ClientOptions{
146+
ElicitationHandler: func(context.Context, *mcp.ElicitRequest) (*mcp.ElicitResult, error) {
147+
return &mcp.ElicitResult{Action: "accept", Content: map[string]any{"test": "value"}}, nil
148+
},
149+
})
150+
if _, err := c.Connect(ctx, ct, nil); err != nil {
151+
log.Fatal(err)
152+
}
153+
res, err := ss.Elicit(ctx, &mcp.ElicitParams{
154+
Message: "This should fail",
155+
RequestedSchema: &jsonschema.Schema{
156+
Type: "object",
157+
Properties: map[string]*jsonschema.Schema{
158+
"test": {Type: "string"},
159+
},
160+
},
161+
})
162+
if err != nil {
163+
log.Fatal(err)
164+
}
165+
fmt.Println(res.Content["test"])
166+
// Output: value
167+
}
168+
```

0 commit comments

Comments
 (0)