Skip to content

fix(mcp): accept camelCase argument names agents copy from the REST API - #135

Merged
Ooscaar merged 2 commits into
developfrom
mcp-watch/camelcase-args
Nov 27, 2026
Merged

Ooscaar merged 2 commits into
developfrom
mcp-watch/camelcase-args

Conversation

@Ooscaar

@Ooscaar Ooscaar commented Nov 27, 2026

Copy link
Copy Markdown
Member

Problem

Agents send the camelCase names that the Zernio REST API and docs use, but every MCP tool takes snake_case, so pydantic rejects the call as InvalidArguments before it reaches the API. Axiom (zernio-mcp, field invalid_arguments) shows ~550 failed calls a day from 100+ users, at a steady rate (chronic, not a regression), from Claude, Cursor, ChatGPT, codex and Executor. Last 24 h, for example:

Tool Sent Calls / users
posts_get_post postId 142 / 65
posts_get postId 77 / 22
call_tool tool_name 66 / 38
media_get_media_presigned_url contentType 60 / 36
messages_get_inbox_conversation_messages conversationId, accountId 39 / 10
messages_list_inbox_conversations accountId 31 / 7
comments_get_inbox_post_comments postId, accountId 30 / 10
posts_create_post mediaItems, scheduledFor 23 / 17
posts_list_posts dateFrom, dateTo 21 / 18

How it works

ArgumentNamesMiddleware (src/late/mcp/middleware/argument_names.py) is an on_call_tool middleware registered on the main server and the ChatGPT server.

  • Fast path: a call whose top-level keys are all lowercase with no - passes through untouched, with no schema lookup. That's nearly every correct call.
  • Otherwise it looks up the tool's input schema once per tool name (cached; lookups that fail aren't cached, so the cache can't grow past the real tool count). For each key not in the schema, it compares names with case, _ and - ignored. It renames the key only if that matches exactly one parameter that the call did not also pass and no other key claims.
  • call_tool also accepts tool_name for name, through an explicit per-tool alias table.
  • FastMCP runs the middleware chain again for the tool call_tool dispatches, so arguments proxied through call_tool are covered without extra code.
  • On the main server it sits before ToolGuidanceMiddleware (which reads call_tool's name) and outside ToolTelemetryMiddleware, so telemetry records the arguments the tool actually ran with.

Deliberately not renamed

  • An explicit snake_case value is never overwritten. If both post_id and postId are sent, the call is rejected exactly as before.
  • Two keys claiming one parameter (postId + PostID): neither is renamed; the error names both.
  • Unknown keys (postIdentifier) are left alone, so the normal validation error still fires.
  • Nested keys (platforms[].accountId, media_items[].altText) are untouched. Those dicts go to the API verbatim and the API expects camelCase there.
  • A name that matches two parameters is not renamed. No Zernio tool has camelCase or colliding parameter names today (checked all 1421 + 148 tools), and none accepts extra keys.

Tests

tests/test_mcp_camelcase_arguments.py:

  1. posts_get_post(postId=…) → post_id, direct and via call_tool
  2. messages_get_inbox_conversation_messages(conversationId, accountId, sortOrder) → all renamed
  3. call_tool(tool_name="posts_get_post", arguments={"postId": …}) → name and post_id
  4. snake_case call is unchanged and skips the schema lookup (spy checks it, and that it does run for camelCase)
  5. post_id="A" + postId="B" → rejected, API not called
  6. unknown postIdentifier → normal validation error
  7. posts_create_post with platforms=[{"accountId": …}] → nested key sent to the API as accountId
  8. postId + PostID → neither renamed, error names both, API not called
  9. ChatGPT server get_post(postId=…) (in tests/test_chatgpt_server.py)
  10. synthetic server: a real camelCase parameter is passed as-is; a name matching two parameters is not renamed

Plus body field contentType on media_get_media_presigned_url, and pinned posts_get(postId=…).

Checks

  • pytest tests → 3842 passed, 44 skipped
  • ruff check src tests → All checks passed!
  • mypy src --ignore-missing-imports → Success: no issues found in 168 source files

🤖 Generated with Claude Code

Ooscaar and others added 2 commits November 27, 2026 15:46
Agents send postId, accountId, contentType, mediaItems, dateFrom: the names
the REST API and docs use. Every MCP tool takes snake_case, so pydantic
rejected several hundred calls a day from 100+ users (Axiom zernio-mcp,
posts_get_post alone ~800/week).

ArgumentNamesMiddleware renames a key the tool does not take when, ignoring
case, underscores and hyphens, it names exactly one parameter the call did
not also pass. An explicit snake_case value is never overwritten and unknown
keys still fail validation. Calls already in snake_case skip the lookup;
parameter sets are cached per tool. FastMCP re-runs the middleware for the
tool call_tool dispatches, so proxied arguments are covered; call_tool also
takes tool_name for name. Registered on both the main and ChatGPT servers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ll cases

postId and PostID together used to rename the first and reject the second;
now neither is renamed, so the error names both. Tests now cover the fast
path skipping the tool lookup, nested keys reaching the API untouched, and
tools with camelCase or colliding parameters (none exist in Zernio today).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Ooscaar
Ooscaar merged commit 50a4f4a into develop Nov 27, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant