[Python] MCP Messages Endpoint Returning 404

Discussão em 'Python' iniciado por Stack, Junho 18, 2025.

  1. Stack

    Stack Membro Participativo

    I am new to MCP and I am trying to add MCP server to my existing Python Starlette App.

    def create_starlette_app():
    """
    Create a Starlette application that wraps the WSGI app and adds the MCP route if enabled.
    """

    api = create_app()
    API_APP = WSGIMiddleware(app=api)

    routes = []

    lifespan = create_lifespan

    LOGGER.info("MCP is enabled, adding MCP route to ASGI app.")
    MCP_SERVER = mcp_asgi_server()
    routes.append(Mount(name="mcp", path="/mcp", app=MCP_SERVER))
    lifespan = MCP_SERVER.lifespan

    return Router(routes=routes, lifespan=lifespan, default=API_APP)


    I am able to connect to the MCP server, but I kept getting 404 errors randomly.

    Error in post_writer: Client error '404 Not Found' for url 'http://localhost:5001/mcp/messages/?session_id=e89b672cfdf34e818f68acf2e9cc40f9'
    For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404


    I have no idea why this happen. Please help :)

    Continue reading...

Compartilhe esta Página