From a317d1aaefc6a70c3f7faf41545aaf7ced6a40bc Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Wed, 18 Jun 2025 22:14:20 +0200 Subject: [PATCH] Add MCP --- test_langgraph/__main__.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/test_langgraph/__main__.py b/test_langgraph/__main__.py index 357797d..7e03cb5 100644 --- a/test_langgraph/__main__.py +++ b/test_langgraph/__main__.py @@ -2,6 +2,7 @@ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import StreamingResponse from fastapi.encoders import jsonable_encoder +import uvicorn from . import tools @@ -26,7 +27,22 @@ app.add_middleware( allow_headers=["*"], ) -for tool in tools.get_tools(): - component, method = tool.__name__.split('.') - path = f'/{component}/{method}' - app.get(path, response_model=None,tags=[component])(tool) +def setup_mcp(): + try: + from fastapi_mcp import FastApiMCP + mcp = FastApiMCP(app) + mcp.mount() + print('MCP mounted') + except ImportError: + print('MCP could not be mounted') + +def setup_tools(): + for tool in tools.get_tools(): + component, method = tool.__name__.split('.') + path = f'/{component}/{method}' + app.get(path, response_model=None,tags=[component])(tool) + +if __name__ == "__main__": + setup_tools() + setup_mcp() + uvicorn.run(app, host="0.0.0.0", port=8000)