cloudflare / cloudflare/agents-starter

Bug: MCP closes connection after one request

Open
#72 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.3k
Forks
283
PR merge metrics
No merged PRs in 30d

Description

In the commented out code, we make a request for the MCP and it finishes we are calling:
`await this.mcp.closeConnection(mcpConnection.id);`
So the connection is closed and the second request for an MCP tool fails with this:

`error: ToolExecutionError [AI_ToolExecutionError]: Error executing tool XIWj-FhT_browser_navigate: Not connected`

What about calling it in the destroy() function on the agent? The agent will live in the durable object so I don't think we need to close the connection until the agent is destroyes. I will make a PR about it and we can discuss this in that, @threepointone !

Contributor guide

Open the contributing guide

Research direction

Start with the commented-out MCP request code and trace where closeConnection is called, then inspect the agent's destroy() lifecycle. Verify that a second MCP tool request can use the existing connection and that cleanup occurs when the agent is destroyed; no test file is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.