Spaces:
Sleeping
Sleeping
Upload 8 files
Browse files- arithmetic_server.py +15 -1
- backend.py +2 -2
- stock_server.py +16 -1
arithmetic_server.py
CHANGED
@@ -1,4 +1,8 @@
|
|
1 |
from mcp.server.fastmcp import FastMCP
|
|
|
|
|
|
|
|
|
2 |
|
3 |
# Creates a server named "Arithmetic"
|
4 |
mcp = FastMCP("Arithmetic")
|
@@ -25,6 +29,16 @@ def divide(a: int, b: int) -> float:
|
|
25 |
raise ValueError("Division by zero is not allowed.")
|
26 |
return a / b
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
if __name__ == "__main__":
|
30 |
-
|
|
|
1 |
from mcp.server.fastmcp import FastMCP
|
2 |
+
from starlette.applications import Starlette
|
3 |
+
from starlette.routing import Mount
|
4 |
+
import contextlib
|
5 |
+
import uvicorn
|
6 |
|
7 |
# Creates a server named "Arithmetic"
|
8 |
mcp = FastMCP("Arithmetic")
|
|
|
29 |
raise ValueError("Division by zero is not allowed.")
|
30 |
return a / b
|
31 |
|
32 |
+
@contextlib.asynccontextmanager
|
33 |
+
async def lifespan(app: Starlette):
|
34 |
+
async with contextlib.AsyncExitStack() as stack:
|
35 |
+
await stack.enter_async_context(mcp.session_manager.run())
|
36 |
+
yield
|
37 |
+
|
38 |
+
app = Starlette(
|
39 |
+
routes=[Mount("/mcp", mcp.streamable_http_app())],
|
40 |
+
lifespan=lifespan,
|
41 |
+
)
|
42 |
|
43 |
if __name__ == "__main__":
|
44 |
+
uvicorn.run(app, host="0.0.0.0", port=8001)
|
backend.py
CHANGED
@@ -175,11 +175,11 @@ class MCPAgent:
|
|
175 |
self.client = MultiServerMCPClient({
|
176 |
"arithmetic": {
|
177 |
"url": "http://localhost:8001/mcp",
|
178 |
-
"transport": "
|
179 |
},
|
180 |
"stocks": {
|
181 |
"url": "http://localhost:8002/mcp",
|
182 |
-
"transport": "
|
183 |
},
|
184 |
}
|
185 |
)
|
|
|
175 |
self.client = MultiServerMCPClient({
|
176 |
"arithmetic": {
|
177 |
"url": "http://localhost:8001/mcp",
|
178 |
+
"transport": "streamable-http",
|
179 |
},
|
180 |
"stocks": {
|
181 |
"url": "http://localhost:8002/mcp",
|
182 |
+
"transport": "streamable-http",
|
183 |
},
|
184 |
}
|
185 |
)
|
stock_server.py
CHANGED
@@ -2,6 +2,10 @@ from mcp.server.fastmcp import FastMCP
|
|
2 |
import aiohttp
|
3 |
import json
|
4 |
from typing import Optional
|
|
|
|
|
|
|
|
|
5 |
|
6 |
mcp = FastMCP("StockMarket")
|
7 |
|
@@ -59,5 +63,16 @@ async def get_company_news(symbol: str, limit: int = 3) -> str:
|
|
59 |
2. Analysts upgrade {symbol} to 'Buy' rating
|
60 |
3. {symbol} unveils new product line for 2025"""
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
if __name__ == "__main__":
|
63 |
-
|
|
|
2 |
import aiohttp
|
3 |
import json
|
4 |
from typing import Optional
|
5 |
+
from starlette.applications import Starlette
|
6 |
+
from starlette.routing import Mount
|
7 |
+
import contextlib
|
8 |
+
import uvicorn
|
9 |
|
10 |
mcp = FastMCP("StockMarket")
|
11 |
|
|
|
63 |
2. Analysts upgrade {symbol} to 'Buy' rating
|
64 |
3. {symbol} unveils new product line for 2025"""
|
65 |
|
66 |
+
@contextlib.asynccontextmanager
|
67 |
+
async def lifespan(app: Starlette):
|
68 |
+
async with contextlib.AsyncExitStack() as stack:
|
69 |
+
await stack.enter_async_context(mcp.session_manager.run())
|
70 |
+
yield
|
71 |
+
|
72 |
+
app = Starlette(
|
73 |
+
routes=[Mount("/mcp", mcp.streamable_http_app())],
|
74 |
+
lifespan=lifespan,
|
75 |
+
)
|
76 |
+
|
77 |
if __name__ == "__main__":
|
78 |
+
uvicorn.run(app, host="0.0.0.0", port=8002)
|