Quick Start
1
Simple Usage
2
With Configuration
Transport Selection
TheMCP class picks the right transport automatically — no config objects needed.
Examples
- Auto (default)
- Explicit SSE
- HTTP-Streaming
- Debug mode
Configuration Options
Instance API
New Exports
Best Practices
Always call close() when done
Always call close() when done
MCP connections stay open until explicitly closed. Always call
await mcp.close() to release resources, especially in long-running applications or when switching servers.Use debug=true when connecting a new server
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.
Pass transport explicitly when URL patterns are ambiguous
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.Prefer MCP over MCPHttpStreaming for new code
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.Related
MCP Security
Secure MCP connections with authentication and rate limiting
Python MCP Transports
Python equivalent — stdio, Streamable HTTP, WebSocket, SSE
Tools
Tool system overview for TypeScript agents
Agent
Agent configuration and capabilities

