[BUG] Metadata like maxResultSizeChars is stripped from tool spec
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Hi 👋
I have an example MCP with FastMCP that does this for demonstrational purposes:
@mcp.tool(meta={"anthropic/maxResultSizeChars": 100_000})
def get_large_text(length: int = DEFAULT_LENGTH) -> str:
...
It should return a large text and by default something over 50k characters.
anthropic/maxResultSizeChars. Seems to be ignored however. For Claude Code, this isn't a problem really because it still handles it, but Cowork does throw an error and saves it to a file to work with it, spawns incredibly slow agents to parse things again in chunks etc.
Error: result (50,013 characters) exceeds maximum allowed tokens. Output has been saved to ...
Looking at the tool JSON Claude Code and Cowork seems to have, they show me
{
"name": "mcp__large-text-test__get_large_text",
"description": "Return a string of the requested length (default 50,000 characters).",
"parameters": {
"type": "object",
"additionalProperties": false,
"properties": {
"length": {
"type": "integer",
"description": "Number of characters to return.",
"default": 50000
}
}
}
}
This doesn't include any of the meta field anymore although the raw spec seems to include it
async def main():
async with Client('large_text_server.py') as client:
result = await client.session.list_tools()
print(json.dumps(result.model_dump(by_alias=True), indent=2))
outputs the following
{
"_meta": null,
"nextCursor": null,
"tools": [
{
"name": "get_large_text",
"title": null,
"description": "Return a string of the requested length (default 50,000 characters).\n\nArgs:\n length: Number of characters to return.",
"inputSchema": {
"additionalProperties": false,
"properties": {
"length": {
"default": 50000,
"type": "integer"
}
},
"type": "object"
},
"outputSchema": {
"properties": {
"result": {
"type": "string"
}
},
"required": [
"result"
],
"type": "object",
"x-fastmcp-wrap-result": true
},
"icons": null,
"annotations": null,
"_meta": {
"anthropic/maxResultSizeChars": 100000,
"fastmcp": {
"tags": []
}
},
"execution": null
}
]
}
What Should Happen?
Documented metadata like anthropic/maxResultSizeChars should not be ignored when translating raw tool calls into the internal Claude format
Error Messages/Logs
Steps to Reproduce
- Create file test_mcp.py
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "fastmcp>=3.4.4",
# ]
# ///
from fastmcp import FastMCP
mcp = FastMCP("Large Text Test Server")
DEFAULT_LENGTH = 50_000
@mcp.tool(meta={"anthropic/maxResultSizeChars": 100_000})
def get_large_text(length: int = DEFAULT_LENGTH) -> str:
"""
Return a string of the requested length (default 50,000 characters).
Args:
length: Number of characters to return.
"""
pattern = "0123456789abcdefghijklmnopqrstuvwxyz"
repeats = (length // len(pattern)) + 1
return (pattern * repeats)[:length]
if __name__ == "__main__":
mcp.run()
- Put this into the MCP config
"large-text-test": {
"command": "uv",
"args": [
"run",
"/path/to/test_mcp.py"
]
}
3. Start Cowork
4. Use the MCP
5. Notice how it fails with `Error: result (50,013 characters) exceeds maximum allowed tokens. Output has been saved to ...`
### Claude Model
_No response_
### Is this a regression?
I don't know
### Last Working Version
_No response_
### Claude Code Version
2.1.105
### Platform
Anthropic API
### Operating System
macOS
### Terminal/Shell
iTerm2
### Additional Information
_No response_