Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/core/src/Components/MCPClient.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class MCPClient extends Component {
}

// TODO [Forhad]: Need to check and validate input prompt token
const { client } = await this.connectMCP(mcpUrl);
const { client } = await this.connectMCP(mcpUrl, logger);

const toolsData = await client.listTools();
const conv = new Conversation(
Expand Down Expand Up @@ -105,17 +105,17 @@ export class MCPClient extends Component {
return { _error: `Error on running MCP Client!\n${error?.message || JSON.stringify(error)}`, _debug: logger.output };
}
}
private async connectMCP(mcpUrl: string) {
private async connectMCP(mcpUrl: string, logger: any) {
const client = new Client({ name: 'auto-client', version: '1.0.0' });

// 1) Try Streamable HTTP first
try {
const st = new StreamableHTTPClientTransport(new URL(mcpUrl));
await client.connect(st);
console.debug('Connected to MCP using Streamable HTTP');
logger.debug('Connected to MCP using Streamable HTTP');
return { client, transport: 'streamable' as const };
} catch (e: any) {
console.debug('Failed to connect to MCP using Streamable HTTP, falling back to SSE');
logger.debug('Failed to connect to MCP using Streamable HTTP, falling back to SSE');
// 2) If clearly unsupported, fall back to SSE
const msg = String(e?.message || e);
const isUnsupported = /404|405|ENOTFOUND|ECONNREFUSED|CORS/i.test(msg);
Expand Down