mcptools
mcptools copied to clipboard
fix: include annotations in tools/list response
Problem
tool_as_json() omits the annotations field when serializing tools for the tools/list MCP response. The MCP spec (2025-03-26+) defines annotations as part of each tool, and ellmer already supports declaring them via tool(annotations = tool_annotations(...)) — but they're silently dropped.
Closes #100.
Fix
If the ToolDef has annotations (i.e., length(tool@annotations) > 0), include them in the JSON output. Otherwise, omit the field (same as current behaviour).
Testing
Verified locally that a tool defined with:
ellmer::tool(
fun = function() "ok",
name = "ping",
description = "Health check",
annotations = ellmer::tool_annotations(read_only_hint = TRUE, idempotent_hint = TRUE)
)
Produces annotations: { readOnlyHint: true, idempotentHint: true } in the tools/list response after this fix.
Checklist
- [x]
R CMD checkpasses (no new code paths that could fail — just adds a field to existing output) - [x] Backwards compatible — tools without annotations are unchanged