-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Hi erveryone
I am trying to connect to Composio MCP server using the below function. It get connected to my app and Action are working fine but after some time it gets disconnected with this error:
{
error: AI_ToolExecutionError: Error executing tool GMAIL_FETCH_EMAILS: MCP SSE Transport Error: Not connected {
toolArgs: { label_ids: [ 'UNREAD' ], user_id: 'me' },
toolName: 'GMAIL_FETCH_EMAILS',
toolCallId: 'call_sDS4yP25Kz4dYViFAhP58y4n'
}
code:
its a nextjs route in api/chat/route.ts
import { openai } from "@ai-sdk/openai";
import { frontendTools } from "@assistant-ui/react-ai-sdk";
import { streamText } from "ai";
import { experimental_createMCPClient as createMCPClient } from "ai";
const mcpClient = await createMCPClient({
// TODO adjust this to point to your MCP server URL
transport: {
type: "sse",
url: "https://mcp.composio.dev/composio/server/xyz123?transport=mcp", //provided by composio after server creation.
},
});
const mcpTools = await mcpClient.tools();
export async function POST(req: Request) {
const { messages, system, tools } = await req.json();
const result = streamText({
model: openai("gpt-4o"),
messages,
// forward system prompt and tools from the frontend
toolCallStreaming: true,
system,
tools: {
...frontendTools(tools),
...mcpTools,
},
onError: console.log,
});
return result.toDataStreamResponse();
}