init repo

This commit is contained in:
Sun-ZhenXing
2025-06-11 11:21:12 +08:00
commit e1b112f401
14 changed files with 840 additions and 0 deletions

View File

@@ -0,0 +1 @@
__version__ = "0.1.0"

View File

@@ -0,0 +1,5 @@
from .__about__ import __version__
__all__ = [
"__version__",
]

View File

@@ -0,0 +1,44 @@
import argparse
import sys
def main():
parser = argparse.ArgumentParser(description="Run a MarkItDown MCP server")
parser.add_argument(
"--http",
action="store_true",
help="Run the server with Streamable HTTP and SSE transport rather than STDIO (default: False)",
)
parser.add_argument(
"--host", default=None, 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)"
)
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.http:
import uvicorn
from .server import app
uvicorn.run(
app,
host=args.host or "127.0.0.1",
port=args.port or 3001,
)
else:
from .app.math import mcp
mcp.run()
if __name__ == "__main__":
main()

View File

View File

@@ -0,0 +1,41 @@
from operator import add, mul, sub, truediv
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("math")
@mcp.tool()
async def add_nums(a: float, b: float) -> float:
"""
Adds two numbers.
"""
return add(a, b)
@mcp.tool()
async def sub_nums(a: float, b: float) -> float:
"""
Subtracts the second number from the first.
"""
return sub(a, b)
@mcp.tool()
async def mul_nums(a: float, b: float) -> float:
"""
Multiplies two numbers.
"""
return mul(a, b)
@mcp.tool()
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()

View File

View File

@@ -0,0 +1,24 @@
import contextlib
from fastapi import FastAPI
from .app.math import mcp as math
MCP_MAP = {
"math": math,
}
@contextlib.asynccontextmanager
async def lifespan(app: FastAPI):
async with contextlib.AsyncExitStack() as stack:
for mcp in MCP_MAP.values():
await stack.enter_async_context(mcp.session_manager.run())
yield
app = FastAPI(lifespan=lifespan)
for name, mcp in MCP_MAP.items():
app.mount(f"/{name}/compatible", mcp.sse_app())
app.mount(f"/{name}", mcp.streamable_http_app())