Skip to content

Commit 52c300c

Browse files
committed
Switch to streamable http transport
1 parent 30ed744 commit 52c300c

File tree

2 files changed

+9
-38
lines changed

2 files changed

+9
-38
lines changed

src/worker.py

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import sys
22

3-
from workers import DurableObject
4-
53
sys.path.insert(0, "/session/metadata/vendor")
64
sys.path.insert(0, "/session/metadata")
75

6+
from mcp.server.fastmcp import FastMCP
87

9-
def setup_server():
10-
from mcp.server.fastmcp import FastMCP
8+
from exceptions import HTTPException, http_exception
119

12-
from exceptions import HTTPException, http_exception
1310

14-
mcp = FastMCP("Demo")
11+
def setup_server():
12+
mcp = FastMCP("Demo", stateless_http=True)
1513

1614
@mcp.tool()
1715
def add(a: int, b: int) -> int:
@@ -33,24 +31,13 @@ def echo_prompt(message: str) -> str:
3331
"""Create an echo prompt"""
3432
return f"Please process this message: {message}"
3533

36-
app = mcp.sse_app()
34+
app = mcp.streamable_http_app()
3735
app.add_exception_handler(HTTPException, http_exception)
3836
return mcp, app
3937

4038

41-
class FastMCPServer(DurableObject):
42-
def __init__(self, ctx, env):
43-
self.ctx = ctx
44-
self.env = env
45-
self.mcp, self.app = setup_server()
46-
47-
async def call(self, request):
48-
import asgi
49-
50-
return await asgi.fetch(self.app, request, self.env, self.ctx)
51-
39+
async def on_fetch(request, env, ctx):
40+
mcp, app = setup_server()
41+
import asgi
5242

53-
async def on_fetch(request, env):
54-
id = env.ns.idFromName("A")
55-
obj = env.ns.get(id)
56-
return await obj.call(request)
43+
return await asgi.fetch(app, request, env, ctx)

wrangler.jsonc

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,6 @@
1717
"fallthrough": true
1818
}
1919
],
20-
"durable_objects": {
21-
"bindings": [
22-
{
23-
"name": "ns",
24-
"class_name": "FastMCPServer"
25-
}
26-
]
27-
},
28-
"migrations": [
29-
{
30-
"tag": "v1",
31-
"new_sqlite_classes": [
32-
"FastMCPServer"
33-
]
34-
}
35-
],
3620
"observability": {
3721
"enabled": true
3822
}

0 commit comments

Comments
 (0)