Jofthomas commited on
Commit
692e2cd
·
verified ·
1 Parent(s): 3cb7e26

Upload 3 files

Browse files
Files changed (3) hide show
  1. echo_server.py +8 -0
  2. math_server.py +8 -0
  3. server.py +25 -0
echo_server.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+
3
+ mcp = FastMCP(name="EchoServer", stateless_http=True)
4
+
5
+
6
+ @mcp.tool(description="A simple echo tool")
7
+ def echo(message: str) -> str:
8
+ return f"Echo: {message}"
math_server.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+
3
+ mcp = FastMCP(name="MathServer", stateless_http=True)
4
+
5
+
6
+ @mcp.tool(description="A simple add tool")
7
+ def add_two(n: int) -> int:
8
+ return n + 2
server.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import contextlib
2
+ from fastapi import FastAPI
3
+ from echo_server import mcp as echo_mcp
4
+ from math_server import mcp as math_mcp
5
+ import os
6
+
7
+
8
+ # Create a combined lifespan to manage both session managers
9
+ @contextlib.asynccontextmanager
10
+ async def lifespan(app: FastAPI):
11
+ async with contextlib.AsyncExitStack() as stack:
12
+ await stack.enter_async_context(echo_mcp.session_manager.run())
13
+ await stack.enter_async_context(math_mcp.session_manager.run())
14
+ yield
15
+
16
+
17
+ app = FastAPI(lifespan=lifespan)
18
+ app.mount("/echo", echo_mcp.streamable_http_app())
19
+ app.mount("/math", math_mcp.streamable_http_app())
20
+
21
+ PORT = os.environ.get("PORT", 10000)
22
+
23
+ if __name__ == "__main__":
24
+ import uvicorn
25
+ uvicorn.run(app, host="0.0.0.0", port=PORT)