-
Notifications
You must be signed in to change notification settings - Fork 713
docs: use helper functions and return error as result #322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,9 +58,9 @@ func main() { | |
| } | ||
|
|
||
| func helloHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { | ||
| name, ok := request.GetArguments()["name"].(string) | ||
| if !ok { | ||
| return nil, errors.New("name must be a string") | ||
| name, err := request.RequireString("name") | ||
| if err != nil { | ||
| return mcp.NewToolResultError(err.Error()), nil | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Errors should be returned in the result so that the MCP client/host/LLM can use it as feedback. We follow that in other examples and we should do that here too. |
||
| } | ||
|
|
||
| return mcp.NewToolResultText(fmt.Sprintf("Hello, %s!", name)), nil | ||
|
|
@@ -94,11 +94,15 @@ MCP Go handles all the complex protocol details and server management, so you ca | |
| - [Prompts](#prompts) | ||
| - [Examples](#examples) | ||
| - [Extras](#extras) | ||
| - [Transports](#transports) | ||
| - [Session Management](#session-management) | ||
| - [Basic Session Handling](#basic-session-handling) | ||
| - [Per-Session Tools](#per-session-tools) | ||
| - [Tool Filtering](#tool-filtering) | ||
| - [Working with Context](#working-with-context) | ||
| - [Request Hooks](#request-hooks) | ||
| - [Tool Handler Middleware](#tool-handler-middleware) | ||
| - [Regenerating Server Code](#regenerating-server-code) | ||
| - [Contributing](/CONTRIBUTING.md) | ||
|
Comment on lines
94
to
-101
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently the ToC was not up to date, my formatter automatically formatted it for me on save. |
||
|
|
||
| ## Installation | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the helper function. That's how we would want developers to use the SDK.