mirror of
https://github.com/Sun-ZhenXing/mcp-template-python.git
synced 2026-02-04 10:13:31 +00:00
feat: update config & deps
This commit is contained in:
@@ -2,6 +2,7 @@ import argparse
|
||||
import sys
|
||||
|
||||
from .__about__ import __module_name__, __version__
|
||||
from .config import MCP_MAP, settings
|
||||
|
||||
|
||||
def main():
|
||||
@@ -14,14 +15,14 @@ def main():
|
||||
)
|
||||
parser.add_argument(
|
||||
"--host",
|
||||
default="127.0.0.1",
|
||||
help="Host to bind to (default: 127.0.0.1)",
|
||||
default=settings.default_host,
|
||||
help=f"Host to bind to (default: {settings.default_host})",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--port",
|
||||
type=int,
|
||||
default=3001,
|
||||
help="Port to listen on (default: 3001)",
|
||||
default=settings.default_port,
|
||||
help=f"Port to listen on (default: {settings.default_port})",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--dev",
|
||||
@@ -42,8 +43,7 @@ def main():
|
||||
sys.exit(0)
|
||||
|
||||
if args.stdio:
|
||||
from .app.math import mcp
|
||||
|
||||
mcp = MCP_MAP[settings.default_mcp]
|
||||
mcp.run()
|
||||
else:
|
||||
import uvicorn
|
||||
@@ -57,7 +57,10 @@ def main():
|
||||
)
|
||||
|
||||
|
||||
def dev(host: str = "127.0.0.1", port: int = 3001):
|
||||
def dev(
|
||||
host: str = settings.default_host,
|
||||
port: int = settings.default_port,
|
||||
):
|
||||
"""Run the MCP server in development mode."""
|
||||
import uvicorn
|
||||
|
||||
|
||||
24
src/mcp_template_python/config.py
Normal file
24
src/mcp_template_python/config.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
from .app.math import mcp as math
|
||||
|
||||
MCP_MAP = {
|
||||
"math": math,
|
||||
}
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
"""
|
||||
Configuration settings for the MCP template application.
|
||||
"""
|
||||
|
||||
default_mcp: str = "math"
|
||||
default_host: str = "127.0.0.1"
|
||||
default_port: int = 3001
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
env_file_encoding = "utf-8"
|
||||
|
||||
|
||||
settings = Settings()
|
||||
@@ -2,11 +2,7 @@ import contextlib
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from .app.math import mcp as math
|
||||
|
||||
MCP_MAP = {
|
||||
"math": math,
|
||||
}
|
||||
from .config import MCP_MAP
|
||||
|
||||
|
||||
@contextlib.asynccontextmanager
|
||||
@@ -25,6 +21,11 @@ async def root():
|
||||
return {"message": "Welcome to the MCP Template Python Server!"}
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
async def health():
|
||||
return {"status": "healthy"}
|
||||
|
||||
|
||||
for name, mcp in MCP_MAP.items():
|
||||
app.mount(f"/{name}/compatible", mcp.sse_app())
|
||||
app.mount(f"/{name}", mcp.streamable_http_app())
|
||||
|
||||
Reference in New Issue
Block a user