A TypeScript client implementation of the Model Context Protocol (MCP). This client allows you to interact with AI models using the MCP specification, enabling standardized communication between clients and AI models through Claude 3.5 Sonnet.
- Connect to MCP servers via multiple transport types:
- Stdio Transport: Local JavaScript (.js) or Python (.py) server scripts
- StreamableHTTP Transport: Remote HTTP-based MCP servers
- Interactive chat interface with Claude 3.5 Sonnet
- Automatic tool discovery and execution
- Automatic transport detection based on server URL
- Environment-based configuration
- Node.js (>=18.0.0)
- pnpm (for package management)
- Python 3 (if connecting to Python-based MCP servers via stdio)
- Anthropic API key
pnpm install
Create a .env
file in the project root with your Anthropic API key:
ANTHROPIC_API_KEY=your_api_key_here
pnpm build
For development with watch mode:
pnpm dev
The client automatically detects the transport type based on the server path/URL:
For local JavaScript or Python MCP servers:
# For JavaScript servers
node build/index.js /path/to/server.js
# For Python servers
node build/index.js /path/to/server.py
For remote HTTP-based MCP servers:
# Connect to any HTTP-based MCP server
node build/index.js https://example.com/mcp-endpoint
# Connect to Zapier MCP server
node build/index.js https://mcp.zapier.com/api/mcp/s/<your-zapier-server-id>/mcp
Once the client is running with any server, you can ask questions like:
Query: What's the weather in Taos Ski Valley today?
The client will automatically:
- Discover the available tools from the server
- Use Claude Sonnet to determine which tool to call
- Execute the appropriate API call
- Return a natural language response with the requested information
- Use Case: Local development and testing with MCP servers
- Supported: JavaScript (.js) and Python (.py) server scripts
- Detection: Automatically detected when server path doesn't start with "http"
- Advantages: Low latency, full control over server environment
- Use Case: Production deployments and remote MCP servers
- Supported: Any HTTP-based MCP server endpoint
- Detection: Automatically detected when server URL starts with "http" or "https"
- Advantages: No local server setup required, scalable, cloud-based
- Connection: The client automatically detects and connects to an MCP server via the appropriate transport:
- Stdio for local server scripts
- StreamableHTTP for remote HTTP endpoints
- Tool Discovery: Automatically discovers available tools from the server
- Chat Interface: Provides an interactive chat loop where you can ask questions
- Tool Execution: Claude 3.5 Sonnet can automatically call server tools when needed
- Response Processing: Handles both text responses and tool calls seamlessly
The client is built with a clean, modular architecture:
- Configuration Management: Centralized configuration with environment variable validation
- Transport Abstraction: Automatic transport selection based on server URL/path
- Error Handling: Comprehensive error handling with descriptive messages
- Type Safety: Full TypeScript support with proper type annotations
- Modular Design: Separated concerns with focused, single-responsibility methods
The client is built with TypeScript and uses:
@anthropic-ai/sdk
for Claude API integration@modelcontextprotocol/sdk
for MCP protocol implementationStdioClientTransport
for local server connectionsStreamableHTTPClientTransport
for remote HTTP connections
dotenv
for environment variable management
The codebase follows modern TypeScript best practices:
- Modular Architecture: Clean separation of concerns with focused methods
- Type Safety: Comprehensive TypeScript types and interfaces
- Error Handling: Robust error handling with meaningful error messages
- Documentation: JSDoc comments for all public and private methods
- Constants Management: Centralized configuration and constants
- Code Organization: Logical method grouping and clear naming conventions
pnpm install
- Install dependenciespnpm build
- Build the TypeScript projectpnpm dev
- Build in watch mode for developmentpnpm clean
- Clean the build directory
For more information about MCP, see the official tutorial: https://modelcontextprotocol.io/quickstart/client#node