Skip to content

feat(mcp): advertise native args object on call_tool_* variants#379

Merged
Dumbris merged 1 commit intomainfrom
fix/args-object-call-tool
Apr 11, 2026
Merged

feat(mcp): advertise native args object on call_tool_* variants#379
Dumbris merged 1 commit intomainfrom
fix/args-object-call-tool

Conversation

@Dumbris
Copy link
Copy Markdown
Member

@Dumbris Dumbris commented Apr 11, 2026

Summary

Adds a native args object parameter alongside the legacy args_json string on call_tool_read, call_tool_write, and call_tool_destructive.

Clients can now send arguments as a native JSON object:

{ "name": "github:get_user", "args": { "username": "octocat" } }

instead of a pre-serialized string:

{ "name": "github:get_user", "args_json": "{\"username\":\"octocat\"}" }

Motivation

Spotted via luutuankiet/mcp-proxy-shim — a client-side shim that transforms args_json into args to eliminate escaping overhead. Shim benchmarks: ~350 tokens saved per call, frequent escaping bugs eliminated. This brings the fix server-side.

The handler at internal/server/mcp.go:1289 already accepted an args object as a fallback — only the advertised schema was missing it, so LLM clients never discovered the native path.

Changes

  • Add WithObject("args", ...) to the tool schemas (3 variants × 2 routes).
  • Factor the duplicated builders in mcp.go / mcp_routing.go into a shared buildCallToolVariantTool(variant) helper.
  • args_json remains advertised and wins when both are provided — fully backward-compatible.

Tests

New internal/server/mcp_call_tool_args_test.go:

  • TestCallToolVariantSchemaAdvertisesArgsObject — schema contract
  • TestHandleCallToolVariantAcceptsArgsObject — runtime extraction path
  • TestHandleCallToolVariantArgsJSONWinsWhenBothProvided — precedence / backward compat

Test plan

  • go test ./internal/server/ -run 'TestCallTool|TestHandleCall|TestArgsJson|TestMCPProxyServer_' passes
  • go test ./internal/runtime/... passes
  • go vet ./internal/server/... clean
  • Live smoke test: built binary, issued tools/list on /mcp and /mcp/call — both routes show args (object) + args_json (string) on all three variants
  • Live smoke test: tools/call with native args object reaches upstream dispatch (errors on missing server, not arg parsing)

🤖 Generated with Claude Code

Adds an `args` object parameter alongside `args_json` on call_tool_read,
call_tool_write, and call_tool_destructive. The handler already accepted
`args` as a fallback, but the schema did not advertise it — so LLM clients
always produced pre-serialized JSON strings, costing ~350 tokens per call
and producing frequent escaping bugs (see luutuankiet/mcp-proxy-shim for
context).

Clients can now send arguments as a native JSON object:

  { "name": "github:get_user", "args": { "username": "octocat" } }

instead of:

  { "name": "github:get_user", "args_json": "{\"username\":\"octocat\"}" }

`args_json` remains advertised and takes precedence when both are provided,
so existing clients continue to work unchanged.

The tool definitions for the default `/mcp` and `/mcp/call` routes were
duplicated across mcp.go and mcp_routing.go; factored them into a shared
`buildCallToolVariantTool(variant)` helper to keep the schema in sync.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1a6e45c
Status: ✅  Deploy successful!
Preview URL: https://934ce287.mcpproxy-docs.pages.dev
Branch Preview URL: https://fix-args-object-call-tool.mcpproxy-docs.pages.dev

View logs

@github-actions
Copy link
Copy Markdown

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/args-object-call-tool

Available Artifacts

  • archive-darwin-amd64 (26 MB)
  • archive-darwin-arm64 (23 MB)
  • archive-linux-amd64 (15 MB)
  • archive-linux-arm64 (13 MB)
  • archive-windows-amd64 (25 MB)
  • archive-windows-arm64 (23 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (19 MB)
  • installer-dmg-darwin-arm64 (17 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 24285806964 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@Dumbris Dumbris merged commit 33f3348 into main Apr 11, 2026
23 checks passed
@Dumbris Dumbris deleted the fix/args-object-call-tool branch April 11, 2026 17:30
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.

2 participants