Skip to content

MCP SSE Transport Error: Not connected #2

@kashifccript

Description

@kashifccript

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();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions