How to expose direct endpoint for requests? #584
Unanswered
HamzaKamranKhawaja
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Don't know if this is a silly question, but I have a basic app running using FastAPI. I want to integrate MCP to enable an AI chat bot to work through the app.
Flow would look like:
js looks like:
`
async function sendToAI() {
}
`
main.py
`
mcp = FastMCP("TeamsMCP")
mcp_app = mcp.http_app(path="/mcp")
app = FastAPI(lifespan=mcp_app.lifespan)
#Local model stuff
#Allow CORS for your frontend domain
origins = ["some origin"] # replace with your frontend URL
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_methods=[""],
allow_headers=[""],
)
app.mount("/static", StaticFiles(directory="static"), name="static")
@app.get("/", response_class=HTMLResponse)
async def get_home():
with open("templates/home.html", "r") as f:
return f.read()
#Other routes...
@mcp.tool()
async def aimessage(
message: Annotated[ str, Field( description="Message for the AI bot", min_length=1, max_length=255) ]
):
"""
Send message to AI bot for response
"""
print("AI CALL RECEIVED..")
app.mount("/mcp-server", mcp_app)
`
I get a "POST /mcp-server/mcp/ HTTP/1.1" 406 Not Acceptable ERROR.
Not sure how to allow the requests to be picked up or how to allow MCP functionality here. Any help is appreciated!
Beta Was this translation helpful? Give feedback.
All reactions