Skip to content

Commit d865b5c

Browse files
committed
[session-resources] docs
1 parent 1b036ad commit d865b5c

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

www/docs/pages/servers/resources.mdx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,38 @@ func (h *CachedResourceHandler) HandleResource(ctx context.Context, req mcp.Read
543543
}
544544
```
545545

546+
## Advanced Resource Patterns
547+
548+
### Session-specific Resources
549+
550+
You can add resources to a specific client session using the `SessionWithResources` interface.
551+
552+
```go
553+
sseServer := server.NewSSEServer(
554+
s,
555+
server.WithAppendQueryToMessageEndpoint(),
556+
server.WithSSEContextFunc(func(ctx context.Context, r *http.Request) context.Context {
557+
withNewResources := r.URL.Query().Get("withNewResources")
558+
if withNewResources != "1" {
559+
return ctx
560+
}
561+
562+
session := server.ClientSessionFromContext(ctx)
563+
if sessionWithResources, ok := session.(server.SessionWithResources); ok {
564+
// Add the new resources
565+
sessionWithResources.SetSessionResources(map[string]server.ServerResource{
566+
myNewResource.URI: {
567+
Resource: myNewResource,
568+
Handler: myNewResourceHandler,
569+
},
570+
})
571+
}
572+
573+
return ctx
574+
}),
575+
)
576+
```
577+
546578
## Next Steps
547579

548580
- **[Tools](/servers/tools)** - Learn to implement interactive functionality

www/docs/pages/servers/tools.mdx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,36 @@ func addConditionalTools(s *server.MCPServer, userRole string) {
10471047
}
10481048
```
10491049

1050+
### Session-specific Tools
1051+
1052+
You can add tools to a specific client session using the `SessionWithTools` interface.
1053+
1054+
```go
1055+
sseServer := server.NewSSEServer(
1056+
s,
1057+
server.WithAppendQueryToMessageEndpoint(),
1058+
server.WithSSEContextFunc(func(ctx context.Context, r *http.Request) context.Context {
1059+
withNewTools := r.URL.Query().Get("withNewTools")
1060+
if withNewTools != "1" {
1061+
return ctx
1062+
}
1063+
1064+
session := server.ClientSessionFromContext(ctx)
1065+
if sessionWithTools, ok := session.(server.SessionWithTools); ok {
1066+
// Add the new tools
1067+
sessionWithTools.SetSessionTools(map[string]server.ServerTool{
1068+
myNewTool.Name: {
1069+
Tool: myNewTool,
1070+
Handler: NewToolHandler(myNewToolHandler),
1071+
},
1072+
})
1073+
}
1074+
1075+
return ctx
1076+
}),
1077+
)
1078+
```
1079+
10501080
## Next Steps
10511081

10521082
- **[Prompts](/servers/prompts)** - Learn to create reusable interaction templates

0 commit comments

Comments
 (0)