mirror of
https://github.com/Sun-ZhenXing/mcp-template-python.git
synced 2026-02-04 10:13:31 +00:00
feat: add docker support
This commit is contained in:
@@ -1,43 +1,72 @@
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
from .__about__ import __module_name__, __version__
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Run a MarkItDown MCP server")
|
||||
parser = argparse.ArgumentParser(description="MCP Server")
|
||||
|
||||
parser.add_argument(
|
||||
"--http",
|
||||
"--stdio",
|
||||
action="store_true",
|
||||
help="Run the server with Streamable HTTP and SSE transport rather than STDIO (default: False)",
|
||||
help="Run the server with STDIO (default: False)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--host", default=None, help="Host to bind to (default: 127.0.0.1)"
|
||||
"--host",
|
||||
default="127.0.0.1",
|
||||
help="Host to bind to (default: 127.0.0.1)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--port", type=int, default=None, help="Port to listen on (default: 3001)"
|
||||
"--port",
|
||||
type=int,
|
||||
default=3001,
|
||||
help="Port to listen on (default: 3001)",
|
||||
)
|
||||
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 not args.http and (args.host or args.port):
|
||||
parser.error(
|
||||
"Host and port arguments are only valid when using streamable HTTP or SSE transport (see: --http)."
|
||||
)
|
||||
sys.exit(1)
|
||||
if args.dev:
|
||||
dev(args.host, args.port)
|
||||
sys.exit(0)
|
||||
|
||||
if args.http:
|
||||
if args.stdio:
|
||||
from .app.math import mcp
|
||||
|
||||
mcp.run()
|
||||
else:
|
||||
import uvicorn
|
||||
|
||||
from .server import app
|
||||
|
||||
uvicorn.run(
|
||||
app,
|
||||
host=args.host or "127.0.0.1",
|
||||
port=args.port or 3001,
|
||||
host=args.host,
|
||||
port=args.port,
|
||||
)
|
||||
else:
|
||||
from .app.math import mcp
|
||||
|
||||
mcp.run()
|
||||
|
||||
def dev(host: str = "127.0.0.1", port: int = 3001):
|
||||
"""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__":
|
||||
|
||||
Reference in New Issue
Block a user