You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
price_cents = lookup_price_cents(sku) # Implement your lookup
244
+
245
+
render structured: { sku: sku,
246
+
price_cents: price_cents,
247
+
meta: { currency:"USD", cached:false } }
248
+
end
249
+
end
250
+
```
251
+
252
+
The schema is included in the tool definition, and the `structured` payload is emitted as `structuredContent` in the response while remaining compatible with text/audio/image renders.
253
+
254
+
#### Returning resource links from a tool
255
+
256
+
When you want to hand back a URI instead of embedding the payload, use the built-in `render_resource_link`, which produces the MCP `resource_link` content type.
257
+
258
+
```ruby
259
+
classReportLinkTool < ApplicationMCPTool
260
+
tool_name "report_link"
261
+
description "Return a downloadable report link"
262
+
263
+
property :report_id, type:"string", required:true
264
+
265
+
defperform
266
+
render_resource_link(
267
+
uri:"reports://#{report_id}.json",
268
+
name:"Report #{report_id}",
269
+
description:"Downloadable JSON for report #{report_id}",
270
+
mime_type:"application/json"
271
+
)
272
+
end
273
+
end
274
+
```
275
+
276
+
Clients can resolve the URI with a separate `resources/read` call, keeping tool responses lightweight while still discoverable.
277
+
278
+
#### Task-augmented tools (async execution with progress)
279
+
280
+
Use MCP Tasks when work might take seconds/minutes. Advertise task support with `task_required!` (or `task_optional!`) and let callers opt in by sending `_meta.task` on `tools/call`. While running as a task, you can emit progress updates with `report_progress!`.
281
+
282
+
```ruby
283
+
classBatchIndexTool < ApplicationMCPTool
284
+
tool_name "batch_index"
285
+
description "Index many items asynchronously with progress updates"
286
+
287
+
task_required! # advertise that this tool is intended to run as a task
288
+
property :items, type:"array_string", description:"Items to index", required:true
0 commit comments