fastapi_mcp icon indicating copy to clipboard operation
fastapi_mcp copied to clipboard

Mcp server not allowing POST methods from toolkit servers .

Open L040639 opened this issue 6 months ago • 1 comments

I am getting the below error while calling the below server from my tool kit , how can i handle the post requests here from the toolkit server .

"POST /mcp HTTP/1.1" 405 Method Not Allowed "cause": "unhandled errors in a TaskGroup (1 sub-exception)"

import uvicorn
import logging
from fastapi import FastAPI, Request
from fastapi import FastAPI
from fastapi_mcp import FastApiMCP

logger = logging.getLogger("mcp")

logger.setLevel(logging.DEBUG)
# Initialize FastAPI app
app = FastAPI()

# Initialize MCP server 

# Mount the MCP server to your FastAPI app

## sample endpoints( this will call to the kubernetes api endpoints to get the details ).
@app.get("/get_namespace/", operation_id="get_namespace_info")
async def get_namespace():
    """
    Fetch namespace details.

    This endpoint returns a simple message along with namespace details.
    """
    return {
        "message": "Hello, Hanger!",
        "namespace_details": ["namespace_x", "namespace_y", "namespace_z"],
    }


# But if you re-run the setup, the new endpoints will now be exposed.
# mcp.setup_server()

if __name__ == "__main__":
        mcp = FastApiMCP(app,include_operations=["get_namespace_info"],)
        mcp.mount()
        uvicorn.run(app, host="0.0.0.0", port=8080)

L040639 avatar Jun 18 '25 03:06 L040639

This seems to be a duplicate of https://github.com/tadata-org/fastapi_mcp/issues/154

Edison-A-N avatar Jun 27 '25 07:06 Edison-A-N