Merge pull request #196 from guillaumebriday/patch-1

[Docs] Rename APITool to WeatherTool and add error handling
This commit is contained in:
Koichi ITO 2025-12-10 12:16:56 +09:00 • committed by GitHub
commit 85b81a6a65
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -597,10 +597,10 @@ Tools can return structured data alongside text content using the `structured_co
The structured content will be included in the JSON-RPC response as the `structuredContent` field.
```ruby
class APITool < MCP::Tool
class WeatherTool < MCP::Tool
description "Get current weather and return structured data"
def self.call(endpoint:, server_context:)
def self.call(location:, units: "celsius", server_context:)
# Call weather API and structure the response
api_response = WeatherAPI.fetch(location, units)
weather_data = {
@ -622,6 +622,32 @@ class APITool < MCP::Tool
end
```
### Tool Responses with Errors
Tools can return error information alongside text content using the `error` parameter.
The error will be included in the JSON-RPC response as the `isError` field.
```ruby
class WeatherTool < MCP::Tool
description "Get current weather and return structured data"
def self.call(server_context:)
# Do something here
content = {}
MCP::Tool::Response.new(
[{
type: "text",
text: content.to_json
}],
structured_content: content,
error: true
)
end
end
```
### Prompts
MCP spec includes [Prompts](https://modelcontextprotocol.io/specification/2025-06-18/server/prompts), which enable servers to define reusable prompt templates and workflows that clients can easily surface to users and LLMs.