Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Collaborator Author

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.

if err != nil {
return mcp.NewToolResultError(err.Error()), nil
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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

Expand Down