fastapi_mcp
fastapi_mcp copied to clipboard
[BUG] return so many \n
I created a simple MCP server that returns JSON data. When I use the MCP client to retrieve data, I get output like ['{\n "msg": "hello jax"\n}']. Why are there so many \n characters?
Can you share a code snippet that produces this?
Can you share a code snippet that produces this?
from fastapi import FastAPI
from fastapi_mcp import FastApiMCP
import uvicorn
app = FastAPI(title="MCP Test API")
@app.get("/say_hello/", tags=["mcp"], operation_id="say_hello")
async def say_hello(name: str):
return {"msg": f"hello {name}"}
mcp = FastApiMCP(
app,
include_tags=["mcp"],
)
mcp.mount()
if __name__ == "__main__":
uvicorn.run("test_mcp:app", host="0.0.0.0", port=8001)
when I use fastmcp, no problem return ['{"msg": "hello jax"}']
import uvicorn
from fastapi import FastAPI
from mcp.server.fastmcp import FastMCP
from starlette.routing import Mount
from starlette.applications import Starlette
api = FastAPI(title="MCP Test API")
mcp = FastMCP()
@mcp.tool()
@api.get("/say_hello")
async def say_hello(name: str):
return {"msg": f"hello {name}"}
app = Starlette(routes=[Mount("/api", app=api), Mount("/", app=mcp.sse_app())])
if __name__ == "__main__":
uvicorn.run("test_mcp2:app", host="0.0.0.0", port=8002)