@devries-cameron20 / composio-1 / commits / 1ba66ca04
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(core): normalize empty output_parameters so MCP tools can execute [PLEN-2450] (#3397)

Closes [PLEN-2450](https://linear.app/composio/issue/PLEN-2450/toolsexecute-fails-for-all-mcp-toolkits-strict-zod-validation-rejects) · refs https://github.com/ComposioHQ/composio/issues/3354 ## Summary `composio.tools.execute('<MCP_TOOL>', ...)` currently throws a `ZodError` for **every** tool from an MCP-backed toolkit (`granola_mcp`, `apify_mcp`, `tavily_mcp`, …) on `@composio/core` 0.6.x–0.9.x. The reporter on #3354 confirmed all three versions hit the identical failure; users are working around it by dropping to `@composio/client` and losing modifiers, custom-tool routing, version checks, and provider wrapping. **Root cause** (`ts/packages/core/src/models/Tools.ts` + `src/types/tool.types.ts`): - `tools.execute` and `tools.get` both run the API response through `transformToolCases → ToolSchema.parse`. - `ParametersSchema` requires `{ type: 'object', properties: {...} }`. - The API returns `output_parameters: {}` for MCP tools that have no declared output schema, so the validator throws. **Fix:** a tiny module-private `normalizeRawToolParameters` helper applied to both `input_parameters` and `output_parameters` inside `transformToolCases`. `null` / `undefined` / `{}` all map to `undefined`; everything else passes through to strict Zod validation. This: - Preserves the existing `outputParameters: undefined` ⇒ "no declared schema" contract — `outputParameters` was already optional in the public `Tool` type, so no public API change. - Fixes both `tools.execute` and `tools.list` (single funnel covers both paths). - Doesn't relax `ParametersSchema` — tools that actually declare a schema remain strictly validated. - Forward-compatible for every present / future `*_mcp` toolkit with no toolkit allow-list. ## Testing Red → green confirmed locally. New `describe('MCP-shaped tool metadata (PLEN-2450)')` block in `tools.test.ts` covers: 1. `getRawComposioToolBySlug` does not throw `ZodError` for `output_parameters: {}`. 2. Empty `output_parameters` is normalized to `undefined` on the transformed `Tool`. 3. Both-empty edge case (`input_parameters: {}` + `output_parameters: {}`). 4. `tools.list` path also tolerates empty `output_parameters`. 5. End-to-end `tools.execute` succeeds against an MCP-shaped fixture. All five tests **fail** on `next` without the helper (reproducing the exact `ZodError` from the report) and **pass** with it. Full `@composio/core` suite: **904 / 904 green**. ```bash cd ts/packages/core pnpm vitest run tools.test -t "MCP-shaped tool metadata" # → PASS (5) FAIL (0) pnpm vitest run # → PASS (904) FAIL (0) ``` ## Test plan - [x] Red phase confirmed: 5 new tests fail with the exact `ZodError` from the report. - [x] Green phase confirmed: 5 new tests pass after the helper lands. - [x] Full `@composio/core` test suite stays green (904 tests). - [x] `pnpm typecheck` clean. - [ ] Optional live sanity: build a tarball and run the reporter's `repro.mjs` against a sandbox user (`pg-test-9f4d0df7-…`) — not blocking; the mocked end-to-end test pins the same path. ## Follow-ups (out of scope) - **Python SDK** — verify whether `composio` Python has the same over-strict Pydantic check and apply the equivalent normalization if so. > Note: not proposing an API-side change. `output_parameters: {}` is the correct JSON Schema for "no declared schema" (the empty schema validates anything); the bug was the SDK's Zod validator being over-strict, not the API. The fix belongs at the SDK layer, where it now lives. Co-authored-by: jkomyno <12381818+jkomyno@users.noreply.github.com>

Alberto Schiabel committed May 16, 2026 at 22:44 UTC 1ba66ca045438a366245b5ede6e627dcb120c83c
4 files changed +136 -2
.changeset/fix-mcp-empty-output-parameters.md new
+11
@@ -0,0 +1,11 @@
1 +---
2 +'@composio/core': patch
3 +---
4 +
5 +Fix `tools.execute` (and `tools.get` / `tools.list`) failing with a `ZodError` for every tool from an MCP-backed toolkit (e.g. `granola_mcp`, `apify_mcp`, `tavily_mcp`).
6 +
7 +MCP toolkits don't declare an output schema, and the Composio API serializes that as `output_parameters: {}`. The SDK's `ParametersSchema` required `{ type: 'object', properties: {...} }`, so `transformToolCases` rejected the response and `getRawComposioToolBySlug` — called by `execute` and the list path — threw.
8 +
9 +The SDK now normalizes empty (`{}`), `null`, and missing `input_parameters` / `output_parameters` payloads to `undefined` before validation. `outputParameters` was already declared `.optional()` in the public `Tool` type, so this preserves the contract: "undefined means no declared schema." Tools that *do* declare a schema continue to be validated strictly.
10 +
11 +No public API change; no toolkit allow-list.
ts/packages/core/src/models/Tools.ts
+25 -2
@@ -65,6 +65,29 @@ type ToolRouterSessionExecuteOptions = {
65 experimental?: SessionExecuteParams.Experimental;
66 };
67
68 +type RawToolParameters =
69 + | ToolRetrieveResponse['input_parameters']
70 + | ComposioToolListResponse['items'][0]['input_parameters'];
71 +
72 +/**
73 + * Normalize a raw `input_parameters` / `output_parameters` payload returned by
74 + * the Composio API. Maps `null`, `undefined`, and empty `{}` — all of which
75 + * mean "no declared schema" — to `undefined` so the strict `ParametersSchema`
76 + * validator never sees them. Non-empty objects pass through unchanged and
77 + * remain subject to strict Zod validation.
78 + *
79 + * MCP-backed toolkits (granola_mcp, apify_mcp, tavily_mcp, …) have no
80 + * declared output schema and the API serializes that as `{}`, which would
81 + * otherwise trip `ParametersSchema`. See
82 + * https://github.com/ComposioHQ/composio/issues/3354.
83 + */
84 +function normalizeRawToolParameters(
85 + params: RawToolParameters | null | undefined
86 +): RawToolParameters | undefined {
87 + if (params == null || Object.keys(params).length === 0) return undefined;
88 + return params;
89 +}
90 +
91 /**
92 * This class is used to manage tools in the Composio SDK.
93 * It provides methods to list, get, and execute tools.
@@ -142,8 +165,8 @@ export class Tools<
165 ): Tool {
166 return ToolSchema.parse({
167 ...tool,
145 - inputParameters: tool.input_parameters,
146 - outputParameters: tool.output_parameters,
168 + inputParameters: normalizeRawToolParameters(tool.input_parameters),
169 + outputParameters: normalizeRawToolParameters(tool.output_parameters),
170 availableVersions: tool.available_versions,
171 isDeprecated: tool.deprecated?.is_deprecated ?? false,
172 isNoAuth: tool.no_auth,
ts/packages/core/test/tools/tools.test.ts
+59
@@ -544,6 +544,65 @@ describe('Tools', () => {
544 });
545 });
546
547 + // MCP-backed toolkits (granola_mcp, apify_mcp, tavily_mcp, …) have no
548 + // declared output schema, so the Composio API returns
549 + // output_parameters: {}. Before the fix, transformToolCases ran that
550 + // through ParametersSchema (which requires { type: 'object', properties:
551 + // {...} }) and threw a ZodError, breaking every tools.execute /
552 + // tools.list call for these toolkits. See
553 + // https://github.com/ComposioHQ/composio/issues/3354.
554 + describe('MCP-shaped tool metadata', () => {
555 + it('should normalize output_parameters: {} to undefined on the transformed Tool', async () => {
556 + const slug = 'GRANOLA_MCP_LIST_MEETINGS';
557 + mockClient.tools.retrieve.mockResolvedValueOnce(toolMocks.mcpRawTool);
558 +
559 + const tool = await context.tools.getRawComposioToolBySlug(slug);
560 +
561 + expect(tool.outputParameters).toBeUndefined();
562 + expect(tool.inputParameters).toEqual(toolMocks.mcpRawTool.input_parameters);
563 + });
564 +
565 + it('should normalize both empty input and output parameters to undefined', async () => {
566 + const slug = 'SOME_MCP_PING';
567 + mockClient.tools.retrieve.mockResolvedValueOnce(toolMocks.mcpRawToolBothEmpty);
568 +
569 + const tool = await context.tools.getRawComposioToolBySlug(slug);
570 +
571 + expect(tool.inputParameters).toBeUndefined();
572 + expect(tool.outputParameters).toBeUndefined();
573 + });
574 +
575 + it('should also tolerate empty output_parameters in tools.list responses', async () => {
576 + mockClient.tools.list.mockResolvedValueOnce({
577 + items: [toolMocks.mcpRawTool],
578 + totalPages: 1,
579 + });
580 +
581 + const result = await context.tools.getRawComposioTools({ toolkits: ['granola_mcp'] });
582 +
583 + expect(result).toHaveLength(1);
584 + expect(result[0].slug).toEqual('GRANOLA_MCP_LIST_MEETINGS');
585 + expect(result[0].outputParameters).toBeUndefined();
586 + expect(result[0].inputParameters).toEqual(toolMocks.mcpRawTool.input_parameters);
587 + });
588 +
589 + it('should execute an MCP tool whose metadata has empty output_parameters', async () => {
590 + // End-to-end: tools.execute → getRawComposioToolBySlug →
591 + // transformToolCases → executeComposioTool → client.tools.execute.
592 + mockClient.tools.retrieve.mockResolvedValueOnce(toolMocks.mcpRawTool);
593 + mockClient.tools.execute.mockResolvedValueOnce(toolMocks.rawToolExecuteResponse);
594 +
595 + const result = await context.tools.execute('GRANOLA_MCP_LIST_MEETINGS', {
596 + userId: 'pg-test-9f4d0df7-a59d-4341-ad00-887b2c58004b',
597 + arguments: { time_range: 'last_30_days' },
598 + version: '20260206_00',
599 + });
600 +
601 + expect(mockClient.tools.execute).toHaveBeenCalledTimes(1);
602 + expect(result).toEqual(toolMocks.toolExecuteResponse);
603 + });
604 + });
605 +
606 describe('get', () => {
607 it('should get a single tool by slug and wrap it with provider as a collection', async () => {
608 const userId = 'test-user';
ts/packages/core/test/utils/mocks/data.mock.ts
+41
@@ -90,6 +90,47 @@ export const toolMocks = {
90 additionalProperties: false,
91 },
92 },
93 + // Fixture for the MCP-shaped metadata regression tests (see
94 + // normalizeRawToolParameters in models/Tools.ts).
95 + mcpRawTool: {
96 + slug: 'GRANOLA_MCP_LIST_MEETINGS',
97 + name: 'List Meetings',
98 + description: 'Lists Granola meetings via MCP',
99 + input_parameters: {
100 + type: 'object',
101 + properties: {
102 + time_range: {
103 + type: 'string',
104 + description: 'Window to query',
105 + },
106 + },
107 + additionalProperties: false,
108 + },
109 + output_parameters: {},
110 + toolkit: {
111 + logo: 'https://example.com/granola.png',
112 + slug: 'granola_mcp',
113 + name: 'Granola MCP',
114 + },
115 + version: '20260206_00',
116 + },
117 +
118 + // Both inputs and outputs empty — pins the both-empty branch of
119 + // normalizeRawToolParameters.
120 + mcpRawToolBothEmpty: {
121 + slug: 'SOME_MCP_PING',
122 + name: 'Ping',
123 + description: 'Trivial MCP tool with no inputs and no outputs',
124 + input_parameters: {},
125 + output_parameters: {},
126 + toolkit: {
127 + logo: 'https://example.com/x.png',
128 + slug: 'some_mcp',
129 + name: 'Some MCP',
130 + },
131 + version: '20260206_00',
132 + },
133 +
134 // transformed response from the sdk
135 toolExecuteResponse: {
136 data: {