Skip to content
Back to search

mcp-chatbot

A simple CLI chatbot that demonstrates the integration of the Model Context Protocol (MCP).

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/3choff--mcp-chatbot/badge.svg)](/listings/3choff--mcp-chatbot)

HTML

<a href="/listings/3choff--mcp-chatbot"><img src="/api/listings/3choff--mcp-chatbot/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

1. **Clone the repository:**

   git clone https://github.com/3choff/mcp-chatbot.git
   cd mcp-chatbot

2. **Install the dependencies:**

   pip install -r requirements.txt

3. **Set up environment variables:**

Create a `.env` file in the root directory and add your API key:

   LLM_API_KEY=your_api_key_here

4. **Configure servers:**

The `servers_config.json` follows the same structure as Claude Desktop, allowing for easy integration of multiple servers. Here's an example:

   {
     "mcpServers": {
       "sqlite": {
         "command": "uvx",
         "args": ["mcp-server-sqlite", "--db-path", "./test.db"]
       },
       "puppeteer": {
         "command": "npx",
         "args": ["-y", "@modelcontextprotocol/server-puppeteer"]
       }
     }
   }

Environment variables are supported as well. Pass them as you would with the Claude Desktop App.

Example:

   {
     "mcpServers": {
       "server_name": {
         "command": "uvx",
         "args": ["mcp-server-name", "--additional-args"],
         "env": {
           "API_KEY": "your_api_key_here"
         }
       }
     }
   }

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.MD · README · 161 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # MCP Chatbot
  2. This chatbot example demonstrates how to integrate the Model Context Protocol (MCP) into a simple CLI chatbot. The implementation showcases MCP's flexibility by supporting multiple tools through MCP servers and is compatible with any LLM provider that follows OpenAI API standards.
  3. If you find this project helpful, don’t forget to ⭐ star the [repository](https://github.com/3choff/mcp-chatbot) or buy me a ☕ [coffee](https://ko-fi.com/3choff).
  4. ## Key Features
  5. - **LLM Provider Flexibility**: Works with any LLM that follows OpenAI API standards (tested with Llama 3.2 90b on Groq and GPT-4o mini on GitHub Marketplace).
  6. - **Dynamic Tool Integration**: Tools are declared in the system prompt, ensuring maximum compatibility across different LLMs.
  7. - **Server Configuration**: Supports multiple MCP servers through a simple JSON configuration file like the Claude Desktop App.
  8. ## Requirements
  9. - Python 3.10
  10. - `python-dotenv`
  11. - `requests`
  12. - `mcp`
  13. - `uvicorn`
  14. ## Installation
  15. 1. **Clone the repository:**
  16. ```bash
  17. git clone https://github.com/3choff/mcp-chatbot.git
  18. cd mcp-chatbot
  19. ```
  20. 2. **Install the dependencies:**
  21. ```bash
  22. pip install -r requirements.txt
  23. ```
  24. 3. **Set up environment variables:**
  25. Create a `.env` file in the root directory and add your API key:
  26. ```plaintext
  27. LLM_API_KEY=your_api_key_here
  28. ```
  29. 4. **Configure servers:**
  30. The `servers_config.json` follows the same structure as Claude Desktop, allowing for easy integration of multiple servers.
  31. Here's an example:
  32. ```json
  33. {
  34. "mcpServers": {
  35. "sqlite": {
  36. "command": "uvx",
  37. "args": ["mcp-server-sqlite", "--db-path", "./test.db"]
  38. },
  39. "puppeteer": {
  40. "command": "npx",
  41. "args": ["-y", "@modelcontextprotocol/server-puppeteer"]
  42. }
  43. }
  44. }
  45. ```
  46. Environment variables are supported as well. Pass them as you would with the Claude Desktop App.
  47. Example:
  48. ```json
  49. {
  50. "mcpServers": {
  51. "server_name": {
  52. "command": "uvx",
  53. "args": ["mcp-server-name", "--additional-args"],
  54. "env": {
  55. "API_KEY": "your_api_key_here"
  56. }
  57. }
  58. }
  59. }
  60. ```
  61. ## Usage
  62. 1. **Run the client:**
  63. ```bash
  64. python main.py
  65. ```
  66. 2. **Interact with the assistant:**
  67. The assistant will automatically detect available tools and can respond to queries based on the tools provided by the configured servers.
  68. 3. **Exit the session:**
  69. Type `quit` or `exit` to end the session.
  70. ## Architecture
  71. - **Tool Discovery**: Tools are automatically discovered from configured servers.
  72. - **System Prompt**: Tools are dynamically included in the system prompt, allowing the LLM to understand available capabilities.
  73. - **Server Integration**: Supports any MCP-compatible server, tested with various server implementations including Uvicorn and Node.js.
  74. ### Class Structure
  75. - **Configuration**: Manages environment variables and server configurations
  76. - **Server**: Handles MCP server initialization, tool discovery, and execution
  77. - **Tool**: Represents individual tools with their properties and formatting
  78. - **LLMClient**: Manages communication with the LLM provider
  79. - **ChatSession**: Orchestrates the interaction between user, LLM, and tools
  80. ### Logic Flow
  81. ```mermaid
  82. flowchart TD
  83. A[Start] --> B[Load Configuration]
  84. B --> C[Initialize Servers]
  85. C --> D[Discover Tools]
  86. D --> E[Format Tools for LLM]
  87. E --> F[Wait for User Input]
  88. F --> G{User Input}
  89. G --> H[Send Input to LLM]
  90. H --> I{LLM Decision}
  91. I -->|Tool Call| J[Execute Tool]
  92. I -->|Direct Response| K[Return Response to User]
  93. J --> L[Return Tool Result]
  94. L --> M[Send Result to LLM]
  95. M --> N[LLM Interprets Result]
  96. N --> O[Present Final Response to User]
  97. K --> O
  98. O --> F
  99. ```
  100. 1. **Initialization**:
  101. - Configuration loads environment variables and server settings
  102. - Servers are initialized with their respective tools
  103. - Tools are discovered and formatted for LLM understanding
  104. 2. **Runtime Flow**:
  105. - User input is received
  106. - Input is sent to LLM with context of available tools
  107. - LLM response is parsed:
  108. - If it's a tool call → execute tool and return result
  109. - If it's a direct response → return to user
  110. - Tool results are sent back to LLM for interpretation
  111. - Final response is presented to user
  112. 3. **Tool Integration**:
  113. - Tools are dynamically discovered from MCP servers
  114. - Tool descriptions are automatically included in system prompt
  115. - Tool execution is handled through standardized MCP protocol
  116. ## Contributing
  117. Feedback and contributions are welcome. If you encounter any issues or have suggestions for improvements, please create a new [issue](https://github.com/3choff/mcp-chatbot/issues) on the GitHub repository.
  118. If you'd like to contribute to the development of the project, feel free to submit a pull request with your changes.
  119. ## License
  120. This project is licensed under the [MIT License](https://github.com/3choff/mcp-chatbot/blob/main/LICENSE).

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.