feat: add docker support

This commit is contained in:
Sun-ZhenXing
2025-06-15 12:35:56 +08:00
parent e1b112f401
commit b53f744aa7
10 changed files with 187 additions and 31 deletions

View File

@@ -1 +1,2 @@
__version__ = "0.1.0"
__module_name__ = "mcp_template_python"

View File

@@ -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__":

View File

@@ -35,7 +35,3 @@ async def div_nums(a: float, b: float) -> float:
Divides the first number by the second.
"""
return truediv(a, b)
if __name__ == "__main__":
mcp.run()