A clean, educational implementation of a Claude chatbot with MCP (Model Context Protocol) support.
- Claude API integration - Basic chat with conversation history
- MCP server connection - Automatic discovery and connection to MCP servers
- Tool usage - Claude can automatically use tools from MCP servers
- Error handling - Graceful handling of API and tool errors
-
Install dependencies:
npm install
-
Set your Anthropic API key:
export ANTHROPIC_API_KEY=your_api_key_here -
(Optional) Configure MCP servers in
mcp-config.json -
Run the chatbot:
npm start
- Initialization - Loads MCP configuration and connects to servers
- Chat Loop - Continuously processes user input
- Claude Integration - Sends messages with available tools to Claude
- Tool Execution - When Claude requests tools, executes them via MCP
- Response - Returns Claude's final response to the user
constructor()- Sets up API client, readline, and tool storageloadMcpServers()- Reads config and connects to MCP serverschatLoop()- Main conversation loopgetClaudeResponse()- Sends messages to Claude with tool contexthandleToolUse()- Executes tools and sends results back to Claude
- Debug modes and verbose logging
- Model querying and selection commands
- Complex fallback logic
- Extra status commands
- Detailed error reporting
This minimal version focuses on the core MCP integration concepts while remaining easy to understand and modify.