3M

3choff/mcp-chatbot

Developer tools

Эта страница переведена автоматически. Технические детали смотрите в оригинале. Открыть оригинал

251 stars 29 forks Качество 68 Тренд 18MIT

3choff/mcp-чатбот — это кандидат на MCP-сервер, импортированный из https://github.com/3choff/mcp-chatbot.

Обзор

3choff/mcp-чатбот — это кандидат на MCP-сервер, импортированный из https://github.com/3choff/mcp-chatbot.

Обзор (машинный перевод)

Этот пример чат-бота демонстрирует, как интегрировать протокол Model Context Protocol (MCP) в простой чат-бот CLI. Реализация демонстрирует гибкость MCP, поддерживая несколько инструментов через серверы MCP, и совместима с любым поставщиком LLM, который следует стандартам OpenAI API.

Если этот проект вам полезен, не забудьте ⭐ поставить репозиторий звездой или купить мне ☕ кофе.

Ключевые особенности

  • LLM Provider Flexibility: Работает с любой LLM, которая соответствует стандартам OpenAI API (протестирована на Llama 3.2 90b на Groq и GPT-4o mini на GitHub Marketplace).
  • Динамическая интеграция инструментов: Инструменты объявляются в системной подсказке, обеспечивая максимальную совместимость между различными LLM.
  • Server Configuration: поддерживает несколько MCP-серверов через простой JSON-файл конфигурации, например приложение Claude Desktop.

Требования

  • Python 3.10
  • python-dotenv
  • requests
  • mcp
  • uvicorn

Установка

  1. Клонировать репозиторий:

  2. Установите зависимости:

  3. Настройте переменные среды:

Создайте файл .env в корневой директории и добавьте свой API-ключ:

  1. Настраивать серверы:

'servers_config.

Эта страница переведена автоматически. Технические детали смотрите в оригинале.

README

Показан фрагмент оригинального README. Открыть оригинал.

MCP Chatbot

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.

If you find this project helpful, don’t forget to ⭐ star the repository or buy me a ☕ coffee.

Key Features

  • 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).
  • 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 like the Claude Desktop App.

Requirements

  • Python 3.10
  • python-dotenv
  • requests
  • mcp
  • uvicorn

Installation

  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"
          }
        }
      }
    }
    

Usage

  1. Run the client:

    python main.py
    
  2. Interact with the assistant:

    The assistant will automatically detect available tools and can respond to queries based on the tools provided by the configured servers.

  3. Exit the session:

    Type quit or exit to end the session.

Architecture

  • Tool Discovery: Tools are automatically discovered from configured servers.
  • System Prompt: Tools are dynamically included in the system prompt, allowing the LLM to understand available capabilities.
  • Server Integration: Supports any MCP-compatible server, tested with various server implementations including Uvicorn and Node.js.

Class Structure

  • Configuration: Manages environment variables and server configurations
Открыть полный README на GitHub

Установка

uvx mcp-server-sqlite --db-path ./test.db
Новичок в MCP? Начните с руководства на mcpskill.org →

Конфигурация

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