Add MCP
This commit is contained in:
parent
3d6c45f2b4
commit
a317d1aaef
|
@ -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():
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user