The MCP class picks the right transport automatically — no config objects needed.
URL pattern
transport param
Transport used
http://host/sse
'auto' (default)
SSE
http://host/api
'auto' (default)
HTTP-Streaming
any URL
'sse'
SSE (forced)
any URL
'http-streaming'
HTTP-Streaming (forced)
Auto-detection is suffix-based: only URLs that end exactly with /sse select SSE. A URL like https://api.example.com/sse/v2 will not auto-select SSE — pass 'sse' explicitly.
MCP connections stay open until explicitly closed. Always call await mcp.close() to release resources, especially in long-running applications or when switching servers.
const mcp = new MCP('http://localhost:8080/sse');try { await mcp.initialize(); // ... use the agent} finally { await mcp.close();}
Use debug=true when connecting a new server
Enable debug mode when first wiring up a new MCP server. It logs the selected transport and number of tools loaded, making misconfiguration easy to spot.
const mcp = new MCP('http://localhost:8080/api', 'auto', true);await mcp.initialize();// Console: "Initialized MCP with 5 tools using http-streaming transport"
Pass transport explicitly when URL patterns are ambiguous
Auto-detection relies on the URL ending in /sse. If your server URL doesn’t follow this convention, pass the transport explicitly to avoid surprises.
// This will use HTTP-Streaming even though it's an SSE serverconst wrong = new MCP('https://api.example.com/sse/v2'); // auto = http-streaming// Correct: pass transport explicitlyconst right = new MCP('https://api.example.com/sse/v2', 'sse');
Prefer MCP over MCPHttpStreaming for new code
Use the unified MCP class for all new integrations. MCPHttpStreaming is a standalone client without auto-detection. Only use it if you specifically need direct HTTP-Streaming without the unified interface.