modelcontextprotocol / modelcontextprotocol/typescript-sdk

Raw bytes support sending to mcp server in callTool method

Open
#539 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug enhancement needs decision P3
Dominant language
TypeScript
Stars
13.4k
Forks
2.2k
Avg merge
3d 15h
Merged PRs (30d)
4

Description

Describe the bug
Unable to send ray bytes / ArrayBuffer / Buffer to mcp server, pydantic validation failes

To Reproduce
Steps to reproduce the behavior:

  1. read file from html as buffer send it to client and use callTool method to upload file and it fails

Expected behavior

  1. read file from from user in html, using FileReader [ readAsDataURL, readAsArrayBuffer]
  2. solution 1 troed : readAsDataURL covert to base64 then Buffer.from(data, 'base64') send to mcp server fails
  3. solution 2 tried : readAsDataURL covert to base64 then Buffer.from(data, 'base64') then bytes = new Uint8Array(tmp.buffer, tmp.byteOffset, tmp.byteLength) still fails.
  4. readAsArrayBuffer sending this directly still fails and tried few more soultion none worked.

Logs
{
type: "text",
text: 'Error executing tool upload_file_and_email: 1 validation error for upload_file_and_emailArguments files..env\ Input should be a valid bytes [type=bytes_type, input_value={'0': 65, '1': 90, '2': 8....., '333': 109, '334': 34}, input_type=dict] For further information visit https://errors.pydantic.dev/2.11/v/bytes_type`,
}

Additional context

  1. at last modified server to hanle base64 directly instead of bytes.
  2. i think it call_tool method convert it to stre

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the SDK's callTool method and reproduce the upload using a browser ArrayBuffer, Buffer, or Uint8Array. Trace the value through serialization to the MCP server and verify that the server receives bytes rather than an object; confirm the fix with the pydantic validation case described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.