Skip to content

Commit 85b81a6

Browse files
authored
Merge pull request #196 from guillaumebriday/patch-1
[Docs] Rename APITool to WeatherTool and add error handling
2 parents 47c70ef + 2b20558 commit 85b81a6

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

README.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,10 +597,10 @@ Tools can return structured data alongside text content using the `structured_co
597597
The structured content will be included in the JSON-RPC response as the `structuredContent` field.
598598

599599
```ruby
600-
class APITool < MCP::Tool
600+
class WeatherTool < MCP::Tool
601601
description "Get current weather and return structured data"
602602

603-
def self.call(endpoint:, server_context:)
603+
def self.call(location:, units: "celsius", server_context:)
604604
# Call weather API and structure the response
605605
api_response = WeatherAPI.fetch(location, units)
606606
weather_data = {
@@ -622,6 +622,32 @@ class APITool < MCP::Tool
622622
end
623623
```
624624

625+
### Tool Responses with Errors
626+
627+
Tools can return error information alongside text content using the `error` parameter.
628+
629+
The error will be included in the JSON-RPC response as the `isError` field.
630+
631+
```ruby
632+
class WeatherTool < MCP::Tool
633+
description "Get current weather and return structured data"
634+
635+
def self.call(server_context:)
636+
# Do something here
637+
content = {}
638+
639+
MCP::Tool::Response.new(
640+
[{
641+
type: "text",
642+
text: content.to_json
643+
}],
644+
structured_content: content,
645+
error: true
646+
)
647+
end
648+
end
649+
```
650+
625651
### Prompts
626652

627653
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.

0 commit comments

Comments
 (0)