-
Notifications
You must be signed in to change notification settings - Fork 384
Open
Description
What I'm trying to do
Connect a Notion MCP server from an AIChatAgent and use the MCP tools in onChatMessage.
What happens
MCP tools are sometimes available and sometimes not. When they're missing, getAITools() returns an empty set with this warning:
[getAITools] WARNING: Reading tools from connection aik32tRf in state "connecting". Tools may not be loaded yet.
The connection finishes restoring after the response is already sent:
Chat message request
[getAITools] WARNING: Reading tools from connection aik32tRf in state "connecting". Tools may not be loaded yet.
Available tools: [ 'getWeatherInformation', 'getLocalTime', 'scheduleTask' ]
Connected successfully using streamable-http transport for https://mcp.notion.com/mcp
Discovery completed for https://mcp.notion.com/mcp
Chat message response
It seems like a race condition — sometimes the MCP connection is ready by the time onChatMessage runs, sometimes it isn't.
My code
async onChatMessage(
onFinish: StreamTextOnFinishCallback<ToolSet>,
options?: { abortSignal?: AbortSignal }
) {
const mcpState = this.getMcpServers();
const hasNotion = Object.values(mcpState.servers).some(
(s) => s.name === "notion"
);
if (!hasNotion) {
await this.addMcpServer("notion", "https://mcp.notion.com/mcp", {
callbackHost: this._callbackHost
});
}
await this.mcp.ensureJsonSchema();
const mcpTools = this.mcp.getAITools(); // ← sometimes empty
// ...
}Versions
agents@0.5.0@cloudflare/ai-chat@0.1.1
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels