SurfSense/plugins/remote/host/tests/sample_plugins/slow/server.py
Anish Sarkar d8aa0f5305 feat(plugins): serve plugins without sessions, and let Stop end their calls on any copy
The plugin host serves MCP without sessions, so any copy answers any request
and Azure can add copies on load. opencode cancels with a message no such
copy can match, so each turn gives plugins on the plugin host a token for
the thread, and the app's Stop calls the host's POST /cancel with it and the
license; Redis passes it to the copy running the call, whose response ends
with Request cancelled. PLUGINS limits a container to some plugins, as one
split out of the shared container runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 00:26:53 +05:30

21 lines
568 B
Python

import anyio
from mcp.server.mcpserver import MCPServer
def server() -> MCPServer:
slow = MCPServer("slow")
@slow.tool()
async def wait(mark: str) -> str:
"""Runs until it is stopped, writing what happened to `mark`."""
path = anyio.Path(mark)
await path.write_text("started")
try:
await anyio.sleep(60)
except anyio.get_cancelled_exc_class():
with anyio.CancelScope(shield=True):
await path.write_text("cancelled")
raise
return "done"
return slow