diff --git a/README.md b/README.md index c041c3af..7054751c 100644 --- a/README.md +++ b/README.md @@ -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.