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
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)
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.
Expand Down