anthropics / anthropics/claude-code

[BUG] Custom remote MCP connector: tools/call result with embedded binary resource (`type: "resource"` + `blob`) fails schema validation

Aperta
#93,946 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
area:claude-code-web area:mcp bug platform:web platform:windows
Lingua principale
Python
Stelle
145k
Fork
23.1k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

### Preflight Checklist

- [x] I have searched [existing issues](https://github.com/anthropics/claude-code/issues?q=is%3Aissue%20state%3Aopen%20label%3Abug) and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code

### What's Wrong?

When a custom remote MCP connector's tool returns an embedded binary resource
(content: [{ type: "resource", resource: { uri, mimeType, blob } }]), the
tools/call result fails client-side schema validation with
"MCP error -32602: Invalid tools/call result", even though the server's raw
HTTP response is verified to be well-formed and contains a valid non-empty
base64 `blob`.

Two issues were found while debugging:

1. `_meta` handling: Initially our `resource` object had no `_meta` key at
all (omitted). The validation error reported `_meta: expected record,
received null` — implying some client-side normalization step defaults
an absent `_meta` to `null` rather than leaving it `undefined`, which
then fails an `.optional()`-style Zod check. Explicitly adding
`"_meta": {}` to our `resource` object resolved this specific error.

2. `blob` disappearing: After fixing (1), validation still fails, now
reporting both `text` and `blob` as `undefined` inside the `resource`
union — even though:
- Calling our backend directly (bypassing the connector) with the same
request returns a well-formed JSON body with a correctly populated
`blob` string.
- Our reverse-proxy's access log confirms a reasonably-sized response
(several KB, matching the expected base64 payload) was actually
returned — not truncated to near-zero bytes.

This suggests the `blob` field is being dropped somewhere between our
server's response and the client-side schema validation, specific to
custom/remote connectors.

Non-binary tool results (type: "text") from the same server, over the same
connector, work correctly.

### What Should Happen?

The tool result should validate successfully and the binary content
(resource + blob) should be available to Claude, per the MCP specification
for embedded resources.

### Error Messages/Logs

```shell
MCP error -32602: Invalid tools/call result: [
{
"code": "invalid_union",
"errors": [
[{"code":"invalid_type","path":["text"],"message":"Invalid input: expected string, received undefined"}],
[{"code":"invalid_type","path":["data"],"message":"Invalid input: expected string, received undefined"},
{"code":"invalid_type","path":["mimeType"],"message":"Invalid input: expected string, received undefined"}],
...
[
{"code":"invalid_union","errors":[
[{"code":"invalid_type","path":["text"],"message":"Invalid input: expected string, received undefined"}],
[{"code":"invalid_type","path":["blob"],"message":"Invalid input: expected string, received undefined"}]
],"path":["resource"],"message":"Invalid input"}
]
],
"path": ["content", 0],
"message": "Invalid input"
}
]
```

### Steps to Reproduce

1. Register a custom remote MCP connector whose server implements
JSON-RPC 2.0 over Streamable HTTP (protocolVersion "2024-11-05").
2. Implement a tool whose tools/call result returns:
{
"content": [{
"type": "resource",
"resource": {
"uri": "example://some/path",
"mimeType": "application/zip",
"blob": "",
"_meta": {}
}
}]
}
3. From a Claude.ai chat, call this tool through the connector.
4. Observe MCP error -32602 (see Error Messages/Logs).
5. Verify (e.g. via curl directly to the backend, bypassing the connector)
that the server's actual HTTP response contains a correctly populated
`blob` string of reasonable size — ruling out a server-side bug.

### Claude Model

Sonnet (default)

### Is this a regression?

I don't know

### Last Working Version

_No response_

### Claude Code Version

2.1.243 (Claude Code)

### Platform

Anthropic API

### Operating System

Windows

### Terminal/Shell

Windows Terminal

### Additional Information

This issue occurred using a custom remote MCP connector (self-hosted PHP
backend, not one of Anthropic's first-party connectors) registered via
Claude.ai's custom connector feature. The connector correctly handles
JSON/text tool results; only embedded binary resource content (blob) is
affected.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.