mirror of
https://github.com/Sun-ZhenXing/mcp-template-python.git
synced 2026-02-04 02:03:32 +00:00
78 lines
1.7 KiB
Python
78 lines
1.7 KiB
Python
import argparse
|
|
import sys
|
|
|
|
from .__about__ import __module_name__, __version__
|
|
from .app import MCP_MAP
|
|
from .config import settings
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description="MCP Server")
|
|
|
|
parser.add_argument(
|
|
"--stdio",
|
|
action="store_true",
|
|
help="Run the server with STDIO (default: False)",
|
|
)
|
|
parser.add_argument(
|
|
"--host",
|
|
default=settings.default_host,
|
|
help=f"Host to bind to (default: {settings.default_host})",
|
|
)
|
|
parser.add_argument(
|
|
"--port",
|
|
type=int,
|
|
default=settings.default_port,
|
|
help=f"Port to listen on (default: {settings.default_port})",
|
|
)
|
|
parser.add_argument(
|
|
"--dev",
|
|
default=False,
|
|
action="store_true",
|
|
help="Run the server in development mode (default: False)",
|
|
)
|
|
parser.add_argument(
|
|
"--version",
|
|
action="version",
|
|
version=f"%(prog)s {__version__}",
|
|
help="Show the version of the MCP server",
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
if args.dev:
|
|
dev(args.host, args.port)
|
|
sys.exit(0)
|
|
|
|
if args.stdio:
|
|
mcp = MCP_MAP[settings.default_mcp]
|
|
mcp.run()
|
|
else:
|
|
import uvicorn
|
|
|
|
from .server import app
|
|
|
|
uvicorn.run(
|
|
app,
|
|
host=args.host,
|
|
port=args.port,
|
|
)
|
|
|
|
|
|
def dev(
|
|
host: str = settings.default_host,
|
|
port: int = settings.default_port,
|
|
):
|
|
"""Run the MCP server in development mode."""
|
|
import uvicorn
|
|
|
|
uvicorn.run(
|
|
f"{__module_name__}.server:app",
|
|
host=host,
|
|
port=port,
|
|
reload=True,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|