Skip to content

Commit 619d10d

Browse files
committed
update readme
1 parent fd08508 commit 619d10d

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,39 @@ Prompts can include:
532532
</details>
533533

534534
### RequestContext
535+
<details>
536+
<summary>Show RequestContext Examples</summary>
537+
538+
The RequestContext object provides capabilities to interact with the client, such as sending logging notification and progress notification.
535539

540+
```go
541+
// Example of using RequestContext to send logging notifications and progress notifications
542+
mcpServer.AddTool(mcp.NewTool(
543+
"test-RequestContent",
544+
mcp.WithDescription("test RequestContent"),
545+
), func(ctx context.Context, reqContext server.RequestContext, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
546+
// you could invoke `reqContext.IsLoggingNotificationSupported()` first the check if server supports logging notification
547+
// ff server does not support logging notification, this method will do nothing.
548+
_ = reqContext.SendLoggingNotification(ctx, mcp.LoggingLevelInfo, map[string]any{
549+
"testLog": "test send log notification",
550+
})
551+
552+
// server should send progress notification if request metadata includes a progressToken
553+
total := float64(100)
554+
progressMessage := "human readable progress information"
555+
_ = reqContext.SendProgressNotification(ctx, float64(50), &total, &progressMessage)
556+
557+
return &mcp.CallToolResult{
558+
Content: []mcp.Content{
559+
mcp.TextContent{
560+
Type: "text",
561+
Text: "context from header: " + ctx.Value(testHeaderKey).(string) + ", " + ctx.Value(testHeaderFuncKey).(string),
562+
},
563+
},
564+
}, nil
565+
})
566+
```
567+
</details>
536568

537569
## Examples
538570

server/request_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
type requestIDKey struct{}
1010

11-
// RequestContext represents an exchange with MCP client. The exchange provides
11+
// RequestContext represents an exchange with MCP client, and provides
1212
// methods to interact with the client and query its capabilities.
1313
type RequestContext struct {
1414
mcpServer *MCPServer

0 commit comments

Comments
 (0)