Skip to content

Fix void MCP tools are reported as internal failures - #7072

Merged
tim-smart merged 2 commits into
mainfrom
audit/repro-17f0b91a-mcp-void-tool-error
Aug 5, 2026
Merged

tim-smart merged 2 commits into
mainfrom
audit/repro-17f0b91a-mcp-void-tool-error

Conversation

@fubhy

@fubhy fubhy commented Aug 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Calling a registered tool whose successful handler returns void produces content: [{"type":"text","text":"Tool execution failed due to an internal server error."}] with isError: true.

Important

This PR includes focused regression coverage and the implementation fix.

Void MCP tools are reported as internal failures

Module: effect/unstable/ai/McpServer
Audit ID: effect-c9c84023834a0007
Severity / confidence: medium / high

What happens

Calling a registered tool whose successful handler returns void produces content: [{"type":"text","text":"Tool execution failed due to an internal server error."}] with isError: true.

Why it happens

The toolkit result path applies JSON.stringify to the encoded void value, producing undefined for the required TextContent text string; the resulting defect is converted into the generic error CallToolResult.

Expected behavior

MCP 2025-06-18 CallToolResult treats omitted or false isError as success and reserves isError: true for tool execution errors; a successful no-output call can return an empty content array.

Relevant implementation

These links and excerpts are pinned to audit base 17f0b91a243ccfe4a38d27debdc983adf434e738.

View problematic code at packages/effect/src/unstable/ai/McpServer.ts:1298-1325
          Effect.map((result) =>
            new CallToolResult({
              isError: false,
              structuredContent: typeof result.encodedResult === "object" ? result.encodedResult : undefined,
              content: [{
                type: "text",
                text: JSON.stringify(result.encodedResult)
              }]
            })
          ),
          Effect.tapCause(Effect.logError),
          Effect.catch((error) => {
            if (AiError.isAiError(error)) {
              const reason = (error as AiError.AiError).reason
              return reason._tag === "ToolParameterValidationError"
                ? Effect.fail(new InvalidParams({ message: reason.message }))
                : Effect.succeed(toolErrorResult(INTERNAL_TOOL_ERROR_MESSAGE))
            }
            if (isDeclaredFailure(error)) {
              const message = error instanceof Error
                ? error.message
                : INTERNAL_TOOL_ERROR_MESSAGE
              return Effect.succeed(toolErrorResult(message))
            }
            return Effect.succeed(toolErrorResult(INTERNAL_TOOL_ERROR_MESSAGE))
          }),
          Effect.catchDefect(() => Effect.succeed(toolErrorResult(INTERNAL_TOOL_ERROR_MESSAGE)))
        )

View exact lines on GitHub

Reproduction

pnpm test --run packages/effect/test/unstable/ai/McpServer/McpServer.test.ts

Observed failure: Focused contract assertion failed against 17f0b91, demonstrating: Void MCP tools are reported as internal failures.

Implementation

Void encoded results now produce an empty content array while remaining successful. The regression test asserts the complete result shape.

Run the focused regression command:

pnpm test --run packages/effect/test/unstable/ai/McpServer/McpServer.test.ts

Audit provenance

  • Audit base: 17f0b91a243ccfe4a38d27debdc983adf434e738
  • Reproduction base: 17f0b91a243ccfe4a38d27debdc983adf434e738
  • Findings: effect-c9c84023834a0007
  • Fix: void encoded results return an empty successful content array

Closes EFF-481

@fubhy fubhy added the audit Findings originating from the Effect runtime correctness audit label Aug 5, 2026
@changeset-bot

changeset-bot Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4288c23

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
effect Patch
@effect/ai-anthropic Patch
@effect/ai-openai Patch
@effect/ai-openai-compat Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/openapi-generator Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node Patch
@effect/platform-node-shared Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/vitest Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

pullfrog[bot]
pullfrog Bot previously requested changes Aug 5, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The regression test correctly reproduces the bug, but the implementation fix promised by the PR title is not present on this branch yet. Please add the source fix in packages/effect/src/unstable/ai/McpServer.ts before merging.

Reviewed changes

  • Added a regression test in packages/effect/test/unstable/ai/McpServer/McpServer.test.ts that demonstrates void toolkit tools are currently reported as internal failures (isError: true).

⚠️ Implementation fix still needed

The PR description states the root cause is at packages/effect/src/unstable/ai/McpServer.ts:1304, where JSON.stringify(result.encodedResult) produces undefined for a Schema.Void result and the resulting invalid CallToolResult is converted into the generic internal-error response. The current diff only adds the failing test; the source fix needs to accompany it.

Technical details
# Void tool results need an empty `content` array

## Affected sites
- `packages/effect/src/unstable/ai/McpServer.ts:1298-1307` — `JSON.stringify(undefined)` is used as `TextContent.text`, which violates the `Schema.String` requirement and triggers the internal-error path.
- `packages/effect/test/unstable/ai/McpServer/McpServer.test.ts:286-296` — the regression test only asserts `isError` is not `true`.

## Required outcome
- A successful tool call whose encoded result is `undefined` (e.g., `Schema.Void`) must not be reported as an error.
- The returned `CallToolResult` should use an empty `content: []` array, matching the expected behavior in the PR description.
- The regression test should assert the full result shape so it cannot be satisfied by an accidental partial fix.

## Suggested approach
In `McpServer.ts`, branch on `result.encodedResult === undefined` and return `content: []`; otherwise keep the existing `JSON.stringify` text block.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Fix it ➔ | View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

@tim-smart
tim-smart enabled auto-merge (squash) August 5, 2026 23:31
@tim-smart
tim-smart merged commit e443403 into main Aug 5, 2026
18 of 19 checks passed
@tim-smart
tim-smart deleted the audit/repro-17f0b91a-mcp-void-tool-error branch August 5, 2026 23:31
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
basic.ts 7.06 KB 7.06 KB 0.00 KB (0.00%)
batching.ts 9.86 KB 9.86 KB 0.00 KB (0.00%)
brand.ts 6.34 KB 6.34 KB 0.00 KB (0.00%)
cache.ts 10.71 KB 10.71 KB 0.00 KB (0.00%)
config.ts 20.73 KB 20.73 KB 0.00 KB (0.00%)
differ.ts 20.31 KB 20.31 KB 0.00 KB (0.00%)
http-client.ts 21.53 KB 21.53 KB 0.00 KB (0.00%)
logger.ts 10.84 KB 10.84 KB 0.00 KB (0.00%)
metric.ts 8.98 KB 8.98 KB 0.00 KB (0.00%)
optic.ts 7.18 KB 7.18 KB 0.00 KB (0.00%)
pubsub.ts 14.99 KB 14.99 KB 0.00 KB (0.00%)
queue.ts 11.66 KB 11.66 KB 0.00 KB (0.00%)
schedule.ts 10.83 KB 10.83 KB 0.00 KB (0.00%)
schema-class.ts 19.27 KB 19.27 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 29.09 KB 29.09 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 25.40 KB 25.40 KB 0.00 KB (0.00%)
schema-string-transformation.ts 13.42 KB 13.42 KB 0.00 KB (0.00%)
schema-string.ts 10.95 KB 10.95 KB 0.00 KB (0.00%)
schema-template-literal.ts 15.21 KB 15.21 KB 0.00 KB (0.00%)
schema-toArbitraryLazy.ts 22.02 KB 22.02 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 24.45 KB 24.45 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 19.28 KB 19.28 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 19.11 KB 19.11 KB 0.00 KB (0.00%)
schema-toFormatter.ts 18.97 KB 18.97 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 22.69 KB 22.69 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 19.60 KB 19.60 KB 0.00 KB (0.00%)
schema.ts 18.52 KB 18.52 KB 0.00 KB (0.00%)
stm.ts 12.63 KB 12.63 KB 0.00 KB (0.00%)
stream.ts 9.80 KB 9.80 KB 0.00 KB (0.00%)

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

Labels

audit Findings originating from the Effect runtime correctness audit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants