Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MCP Server Base64 encode/decode mismatch for Resources #342

Open
evalstate opened this issue Mar 21, 2025 · 1 comment
Open

MCP Server Base64 encode/decode mismatch for Resources #342

evalstate opened this issue Mar 21, 2025 · 1 comment

Comments

@evalstate
Copy link
Contributor

Describe the bug

In src/mcp/server/lowlevel/server.py, binary data is encoded using base64.urlsafe_b64encode(), which replaces + with - and / with _ to make it URL-safe.
However, when the client tries to validate this data with BlobResourceContents, the validator expects standard base64 encoding (with + and /).
This causes validation failures with "Invalid base64" errors when processing larger binary files that contain these special characters.

Before Fix:

# Create server
server = FastMCP("Base64 Test")

# Add resource directly
binary_resource = FileResource(
    uri=AnyUrl("resource://test/simple.bin"),
    path=Path("sample.pdf").absolute(),
    name="Test PDF",
    mime_type="application/pdf",
)

server.add_resource(binary_resource)

if __name__ == "__main__":
    server.run()

Image

Use FastMCP to return a binary resource (e.g. a PDF file), and inspect the contents.

After Fix:

Image

Expected behavior
That binary content is returned as correctly base64 content rather than an error message.

Additional context
PR incoming with automated test.

dsp-ant added a commit that referenced this issue Mar 27, 2025
Co-authored-by: David Soria Parra <[email protected]>
@evalstate
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant