Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

MichalKalita
Copy link
Contributor

@MichalKalita MichalKalita commented Sep 11, 2025

Fixes: #250

When the connection to the Actorized MCP server is not completed in 30 seconds, this MCP server silently fails and opens a user session without this Actorized MCP server.

Potential improvements:

  • inside getMCPServersAsTools load all MCP servers in parallel
  • somehow write to client if MCP server is not connected, maybe create some resource with "startup errors?" @jirispilka @MQ37
    • Not completed, there is no reliable way to return the MCP error when starting the session

@github-actions github-actions bot added the t-ai Issues owned by the AI team. label Sep 11, 2025
@MichalKalita
Copy link
Contributor Author

Or, theoretically, we can start the session without these tools and add them after the MCP server is connected. But it will probably be a problem for clients without the tool update feature.

@MichalKalita MichalKalita changed the title fix: Actorized mcp server have 5 seconds timeout to connect fix: Actorized mcp server have 30 seconds timeout to connect Sep 11, 2025
@MichalKalita MichalKalita changed the title fix: Actorized mcp server have 30 seconds timeout to connect fix: Actorized MCP servers have 30 seconds timeout to connect Sep 11, 2025
@MQ37
Copy link
Contributor

MQ37 commented Sep 11, 2025

Or, theoretically, we can start the session without these tools and add them after the MCP server is connected. But it will probably be a problem for clients without the tool update feature.

Yes, but we can use the https://github.com/apify/mcp-client-capabilities package and for the clients that support tools changed notification we can load that dynamically and connect them instantly and for those who do not we can let them wait or time out the proxy MCP connection.

@MQ37
Copy link
Contributor

MQ37 commented Sep 11, 2025

@MichalKalita from my testing the LLM usually do not read the resources sadly, we could pass that in the initialize response instructions but the clients are not reading that either 😅

@MQ37
Copy link
Contributor

MQ37 commented Sep 11, 2025

inside getMCPServersAsTools load all MCP servers in parallel

This is actually a great improvement, I wanted to do it but never finished that 😅

@MichalKalita
Copy link
Contributor Author

MichalKalita commented Sep 17, 2025

Testing with:
mcp-servers/slidespeak-mcp-server ❌ error 500 in 8s

{"jsonrpc":"2.0","id":0,"error":{"code":-32001,"message":"Error POSTing to endpoint (HTTP 404): {\n \"error\": {\n \"type\": \"record-or-token-not-found\",\n \"message\": \"Actor or Actor task was not found or access denied\"\n }\n}","data":{}}}

direct connection works

mcp-servers/brave-search-mcp-server ✅ cold start in 11s

jiri.spilka/weather-mcp-server ❌ error 500 in 8s (direct connection works)

{
  "jsonrpc": "2.0",
  "id": 0,
  "error": {
    "code": -32001,
    "message": "Error POSTing to endpoint (HTTP 500): {\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32603,\"message\":\"Internal server error\"},\"id\":null}",
    "data": {}
  }
}

apify/actors-mcp-server
jakub.kopecky/browserbase-mcp-server 7.3s ✅
jakub.kopecky/arxiv-mcp-server 1.2s ❌ is loaded like normal Actor, not MCP
jiri.spilka/playwright-mcp-server 25s ❌
Error in request {"logMessage":"Error handling MCP request","error":{"name":"Error","message":"SSE error: Non-200 status code (400)","stack":"Error: SSE error: Non-200 status code (400) direct connection works

@MichalKalita
Copy link
Contributor Author

There was simple bug, I fixed it.
But I found jakub.kopecky/browserbase-mcp-server have some issue to make more sessions @MQ37

 FAIL  tests/integration/actor.server-sse.test.ts > Apify MCP Server SSE > should connect to "jakub.kopecky/browserbase-mcp-server" MCP server and at least one tool is available
Error: SSE error: Non-200 status code (500)
 ❯ EventSource._eventSource.onerror node_modules/@modelcontextprotocol/sdk/src/client/sse.ts:158:23
 ❯ EventSource.failConnection_fn node_modules/eventsource/src/EventSource.ts:535:5
 ❯ node_modules/eventsource/src/EventSource.ts:374:7

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯

 FAIL  tests/integration/actor.server-streamable.test.ts > Apify MCP Server Streamable HTTP > should connect to "jakub.kopecky/browserbase-mcp-server" MCP server and at least one tool is available
McpError: MCP error -32001: Request timed out
 ❯ Timeout.timeoutHandler node_modules/@modelcontextprotocol/sdk/src/shared/protocol.ts:625:43

@MichalKalita MichalKalita marked this pull request as ready for review September 18, 2025 10:03
@MQ37
Copy link
Contributor

MQ37 commented Sep 18, 2025

jakub.kopecky/browserbase-mcp-server

Created issue for that https://github.com/apify/ai-team/issues/85

Copy link
Contributor

@MQ37 MQ37 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few nits/questions, otherwise LGTM

});

// Wait for all actors to be processed in parallel
const actorToolsArrays = await Promise.all(actorToolPromises);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notice: for the most use cases it should be fine, but we should be aware of rate limits

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find any rate limiting docs in the public docs on internal Notion. What type of limits do you mean?

Comment on lines +37 to +48

try {
client = await createMCPSSEClient(url, token);
return client;
} catch (error) {
if (error instanceof TimeoutError) {
log.warning('Connection to MCP server using SSE transport timed out', { url });
return null;
}

log.error('Failed to connect to MCP server using SSE transport', { cause: error });
throw error;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit/question: Why is the try block here? We are just catching and then re-throwing. I would remove the try block for the SSE.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I throw exception, connection will not be opened.
When TimeoutError occurs, only warning will be logged to us and connection will be opened, but without this MCP server.

Copy link
Collaborator

@jirispilka jirispilka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left only a few comments. Can you please re-consider the number of mcp-servers u use for testing?

@MichalKalita
Copy link
Contributor Author

@jirispilka I kept only a single MCP server.

Copy link
Collaborator

@jirispilka jirispilka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@MichalKalita MichalKalita merged commit cdffc3e into master Sep 22, 2025
4 checks passed
@MichalKalita MichalKalita deleted the fix/mcp-timeout branch September 22, 2025 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t-ai Issues owned by the AI team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Actor MCP servers add timeout when connecting
3 participants