Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[feature] Make MAXIMUM_MESSAGE_SIZE configurable instead of hard coding to 4MB #1012

Open
@Jason-CKY

Description

@Jason-CKY

Description

currently the maximum size of a message in streamable-http transport is hard-coded to 4MB, throwing 413 Request Entity Too Large error.
This limits mcp tools that takes in bigger payloads like base64 encoded images/videos for multi-modal workloads.

suggest to make this a configurable instead to remove this limitation.

similar issues reported downstream jlowin/fastmcp#854

References

#server code
import anyio
import fastmcp
from fastmcp import FastMCP, Context
mcp = FastMCP(name="testServer")

@mcp.tool()
async def filetest(image:str)->str:

    return "filetest success !"

if __name__ == '__main__':
    mcp.run(transport="streamable-http", host="0.0.0.0", port=8001, path="/messages")
#client code
import asyncio
import os

from fastmcp import Client, Context
from fastmcp.client.transports import StreamableHttpTransport
from fastmcp.client.logging import LogMessage

async def log_handler(message: LogMessage):
    level = message.level.upper()
    loggerdata = message.logger or 'default'
    data = message.data
    print(f"[Server Log - {level}] {loggerdata}: {data}")
def generate_random_string(size_mb):
    
    size_bytes = int(size_mb * 1024 * 1024)
    print(f'teststr size: {size_bytes}')
    
    random_data = os.urandom(size_bytes)

    random_string = random_data.hex()
    return random_string
async def streamableHealthyCheck(timeinterval):
    async with Client(StreamableHttpTransport("http://127.0.0.1:8001/messages/"),
                      log_handler=log_handler) as client:

        tools = await client.list_tools()
        print(f'cvpro tools: {tools}')

        try:

            teststr = generate_random_string(2)
            result = await client.call_tool(
                "filetest",
                arguments={"image": teststr},
            )
            print(f"filetest finished: , {result[0].text}")

        except Exception as e:
            print(f"healthycheck error: {str(e)}")
if __name__ == '__main__':
    asyncio.run(streamableHealthyCheck(1))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions