Skip to content

Commit 8d9bc95

Browse files
zzstoatzzclaude
andauthored
fix(slackbot): create MCP server per agent run to avoid cancel scope error (#1289)
The module-level MCPServerStreamableHTTP singleton was shared across concurrent asyncio.create_task handlers. streamablehttp_client uses anyio.create_task_group() internally, binding a cancel scope to the entering task. When the last handler to exit was a different task than the one that opened the connection, anyio raised "Attempted to exit cancel scope in a different task than it was entered in". Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 377d08d commit 8d9bc95

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

  • examples/slackbot/src/slackbot

examples/slackbot/src/slackbot/core.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@
4747

4848
GITHUB_API_TOKEN = Secret.load(settings.github_token_secret_name, _sync=True).get()
4949

50-
slack_search_mcp = MCPServerStreamableHTTP(
51-
url="https://marvin-slack-thread-assets.fastmcp.app/mcp",
52-
)
53-
5450
logger = get_logger(__name__)
5551

5652

@@ -178,6 +174,9 @@ def create_agent(
178174
api_key=Secret.load(settings.anthropic_key_secret_name, _sync=True).get(), # type: ignore
179175
),
180176
)
177+
slack_search_mcp = MCPServerStreamableHTTP(
178+
url="https://marvin-slack-thread-assets.fastmcp.app/mcp",
179+
)
181180
agent = Agent[
182181
UserContext, str
183182
](

0 commit comments

Comments
 (0)