Files
dcalc/backend/mcpServer.py
T
2026-03-09 23:34:04 +08:00

29 lines
747 B
Python

import os
import time
from fastmcp import FastMCP
from main import application
from fastmcp.server.providers.openapi import MCPType
from config.main import config
def custom_route_mapper(route, mcp_type: MCPType) -> MCPType | None:
"""Advanced route type mapping."""
# Convert all admin routes to tools regardless of HTTP method
if "/open/" in route.path and route.method in ["GET"]:
return MCPType.TOOL
else:
return MCPType.EXCLUDE
mcp = FastMCP.from_fastapi(
app=application,
name="Dcalc_MCP",
instructions="DNF相关的MCP服务",
route_map_fn=custom_route_mapper,
)
os.environ['TZ'] = 'Asia/Shanghai'
time.tzset()
mcp.run(transport="streamable-http", host="0.0.0.0", port=config.MCPPORT)