mcp-chatbot is a simple CLI chatbot used to demonstrate how to integrate the Model Context Protocol (MCP) into a command-line chatbot. This implementation shows the flexibility of MCP: it supports multiple tools through MCP servers and is compatible with any LLM provider that follows the OpenAI API standard.
Purpose This project mainly serves as an integration example to help developers understand how to connect MCP servers and tools in a CLI chatbot and connect to any OpenAI API-compatible LLM.
Main capabilities
- LLM provider flexibility: can be used with any LLM that follows the OpenAI API standard (the material states it has been tested on Llama 3.2 90b on Groq and GPT-4o mini on GitHub Marketplace).
- Dynamic tool integration: tools are declared in the system prompt, ensuring maximum compatibility across different LLMs.
- Server configuration: supports multiple MCP servers through a simple JSON configuration file, with a structure similar to the Claude Desktop App.
- Tool discovery: automatically discovers tools from configured servers.
- System prompt: tools are dynamically included in the system prompt so that the LLM can understand the available capabilities.
- Server integration: supports any MCP-compatible server; the material states it has been tested with multiple server implementations including Uvicorn and Node.js.
Usage
- Clone the repository: git clone https://github.com/3choff/mcp-chatbot.git cd mcp-chatbot
- Install dependencies: pip install -r requirements.txt
- Set environment variables: create a .env file in the root directory and add the API key: LLM_API_KEY=your_api_key_here
- Configure servers: servers_config.json uses the same structure as Claude Desktop, making it easy to integrate multiple servers. Example: { "mcpServers": { "sqlite": { "command": "uvx", "args": ["mcp-server-sqlite", "--db-path", "./test.db"] }, "puppeteer": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-puppeteer"] } } } Environment variables are also supported, passed in the same way as in the Claude Desktop App. Example: { "mcpServers": { "server_name": { "command": "uvx", "args": ["mcp-server-name", "--additional-args"], "env": { "API_KEY": "your_api_key_here" } } } }
- Run the client: python main.py
- Interact with the assistant: the assistant automatically detects available tools and can respond to queries based on the tools provided by the configured servers.
- Exit the session: enter quit or exit to end the session.
Run flow
- Initialization: Configuration loads environment variables and server settings; servers use their respectivetool initialization; tools are discovered and formatted for the LLM to understand.
- Runtime flow: receive user input; send the input together with the context of available tools to the LLM; parse the LLM response: if it is a tool call, execute the tool and return the result; if it is a direct response, return it to the user; the tool result is sent back to the LLM for interpretation; the final response is presented to the user.
Class structure
- Configuration: manages environment variables and server configuration
- Server: handles MCP server initialization, tool discovery, and execution
- Tool: represents a single tool and its attributes and formatting
- LLMClient: manages communication with the LLM provider
- ChatSession: orchestrates the interaction among the user, the LLM, and tools
Use cases Suitable for developers who want to understand or demonstrate the integration of MCP with a CLI chatbot, as well as experimental projects that need to connect to any OpenAI API-compatible LLM and extend tool capabilities through MCP servers.
Limitations The materials do not provide more limitation information beyond charging, pricing, platform support scope, performance results, or specific usage steps, and none is currently provided. The project uses the MIT license.