Skip to content

fix(mcp): build tool input schemas from the input side of action schemas - #1675

Open
burrows99 wants to merge 1 commit into
coinbase:mainfrom
burrows99:fix/mcp-tool-schema-input-io
Open

burrows99 wants to merge 1 commit into
coinbase:mainfrom
burrows99:fix/mcp-tool-schema-input-io

Conversation

@burrows99

Copy link
Copy Markdown

Description

getMcpTools throws while building the tool list as soon as one active action has a schema with a .transform() or a z.custom() type:

Error: Transforms cannot be represented in JSON Schema

It calls z.toJSONSchema(action.schema), which defaults to io: "output", and zod cannot describe a transform's output (or a custom type) in JSON Schema. On main this affects 28 actions, including pyth (used by the MCP example server), x402 and cdpEvmWallet / cdpSmartWallet swap (both in the create-onchain-agent MCP templates), plus erc8004, wow, sushi, jupiter, flaunch, clanker, basename and truemarkets. The LangChain and Vercel AI SDK extensions build the same schemas without errors because they convert the input side.

Changes in framework-extensions/model-context-protocol/src/index.ts:

  • io: "input": the tool schema now describes what the caller sends, which is what toolHandler parses.
  • unrepresentable: "any": a z.custom field becomes {} instead of throwing. toolHandler still validates it with action.schema.parse.
  • an override that keeps additionalProperties: false on objects, as the output conversion did. Without it the input mode leaves objects open.

I checked every action provider exported by @coinbase/agentkit (108 actions on an EVM network): the 80 schemas that converted before come out deep-equal to what main produced, and the 28 that threw now convert.

flowchart TD
    A[Agent with pyth or x402 or CDP swap] --> B{getMcpTools}
    B -->|Before| C[Throws and no tools are listed]
    B -->|After| D[Every tool is listed]
Loading

Narrated recording, before then after (sound on):

evidence.mp4

Tests

Shown in the recording (a Node REPL in typescript/examples/model-context-protocol-smart-wallet-server, which uses the workspace packages, with a stub wallet provider so no keys or network are needed):

const { AgentKit, pythActionProvider, erc20ActionProvider, wowActionProvider } = require("@coinbase/agentkit")
const { getMcpTools } = require("@coinbase/agentkit-model-context-protocol")
const walletProvider = { getNetwork: () => ({ protocolFamily: "evm", networkId: "base-sepolia" }) }
const agentKit = await AgentKit.from({ walletProvider, actionProviders: [pythActionProvider(), erc20ActionProvider()] })
const { tools, toolHandler } = await getMcpTools(agentKit)

On main:

Uncaught Error: Transforms cannot be represented in JSON Schema

With this change, tools.map(t => t.name):

[
  'PythActionProvider_fetch_price_feed',
  'PythActionProvider_fetch_price',
  'ERC20ActionProvider_get_balance',
  'ERC20ActionProvider_transfer',
  'ERC20ActionProvider_approve',
  'ERC20ActionProvider_get_allowance',
  'ERC20ActionProvider_get_erc20_token_address'
]

Edge cases and unchanged behaviour checked:

  • Pyth quoteCurrency / assetType (nullable + transform) are listed as anyOf [string, null] with their descriptions (recording).
  • wow contractAddress (z.custom) becomes { description } and the other fields keep their types (recording).
  • ERC20ActionProvider_get_balance schema is unchanged, still additionalProperties: false (recording, and the 108-action deep-equal comparison above).
  • toolHandler still validates: { tokenAddress: "nope" } is rejected with Invalid Ethereum address format (recording).

Unit tests, lint and type check in typescript/framework-extensions/model-context-protocol:

$ npx jest src/index.test.ts
  ✓ should return an array of tools and a tool handler with correct properties
  ✓ should build the input schema for actions using transforms or custom types
Tests:       2 passed, 2 total

The new test fails on main with Transforms cannot be represented in JSON Schema. pnpm run lint, prettier --check and tsc --noEmit pass. I did not run a chatbot against a live network or the full monorepo test suite.

Checklist

  • Added documentation to all relevant README.md files (no README change needed)
  • Added a changelog entry

AI assistance (Claude Code) was used to find and fix this and to prepare the PR.

🤖 Generated with Claude Code

getMcpTools converted each action schema with z.toJSONSchema's default
"output" mode, which throws on .transform() and z.custom. Any agent with
the pyth, x402, CDP swap, erc8004, wow, sushi, jupiter, flaunch, clanker
or basename providers crashed while listing tools.

Convert with io: "input" (what the caller sends), map unrepresentable
types to {} and keep objects closed with additionalProperties: false, so
every schema that converted before is unchanged.
@cb-heimdall

Copy link
Copy Markdown

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
1 if authored by an app that is not allowlisted and lacks verified human attribution 0
Sum 1

@github-actions github-actions Bot added documentation Improvements or additions to documentation framework extension New framework extension typescript labels Nov 22, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation framework extension New framework extension typescript

Development

Successfully merging this pull request may close these issues.

2 participants