MCP Command and Search Server

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Integrations

  • Integrates with Brave Search API to fetch web data based on user queries determined by the LLM

  • Uses Ollama as a Large Language Model provider to determine user intent and route requests

基于 MCP 的命令执行器和 Brave Search 客户端-服务器应用程序

概述

该项目实现了一个**客户端-服务器架构,使用 MCP(模型上下文协议)来处理用户提示,使用大型语言模型 (LLM)**确定其意图,并将其路由到适当的服务进行执行。该系统由两个主要组件组成:

  • **客户端:**处理用户输入,将其发送给 LLM,并根据 LLM 的决定将请求转发到适当的服务器。
  • **服务器:**根据 LLM 的 JSON 响应中指定的工具处理请求。它要么执行系统命令,要么使用 Brave Search API 获取 Web 数据。

LLM 会判断用户请求是需要执行命令还是网页搜索。如果提示不明确,LLM 会询问后续问题,然后生成结构化的**JSON 响应,**其中会指定工具名称( command_executionfetch_web_data )及其所需参数。

流程图

在职的

  1. **用户输入:**用户在 CLI 中输入提示。
  2. **客户端处理:**客户端将提示转发给 LLM。
  3. 法学硕士决定:
    • 如果意图不明确,LLM 会询问后续问题。
    • 它生成一个指定工具名称和所需参数的 JSON 响应。
  4. 客户端路由:
    • 如果工具是command_execution
      • 请求被发送到命令服务器
      • 命令服务器使用 Python 的subprocess模块执行命令。
      • 返回成功或失败的响应。
    • 如果该工具是fetch_web_data
      • 该请求被发送到Fetch Web Data Server
      • 服务器查询Brave Search API以获取相关结果。
      • 搜索结果返回给客户端。
  5. **客户端响应:**客户端通过 CLI 将最终响应发送回用户。

先决条件

安装

1. 克隆存储库

git clone -https://github.com/mjunaid46/mcp cd mcp

2.创建虚拟环境并激活

# Create a virtual environment uv venv # Activate virtual environment # On Unix or MacOS: source .venv/bin/activate # On Windows: .venv\Scripts\activate

3.安装依赖项

pip install -r requirements.txt python -m ensurepip

4.配置LLM模型

使用 Ollama 模型

  1. 按照Ollama 安装指南中的说明安装 Ollama CLI 工具。
  2. 然后,检查 Ollama:
    ollama list
  3. 在客户端命令中指定模型(llama3或llama2):
    uv run client/client.py server/command_server.py server/web_server.py ollama llama3

使用 Groq 模型

  1. 创建一个.env文件来存储 Groq 的 API Key:
    touch .env
  2. 将您的 Groq 的 API 密钥添加到.env文件:
    GROQ_API_KEY=<your_groq_api_key_here>

5.配置 Brave Search API

将您的 Brave 的 API 密钥添加到.env文件:

BRAVE_SEARCH_API_KEY=<your_brave_search_api_key_here>

跑步

  • 使用 Ollama 模型
uv run client/client.py server/command_server.py server/web_server.py ollama llama3
  • 使用 Groq 模型
uv run client/client.py server/command_server.py server/web_server.py groq

测试

向客户端发出查询(例如, touch test.txtcreate text file with testrm test.txt file等)

# Try the below prompts one by one to test. What is the capital of Pakistan. What is MCP? Create a file in my present working directory

🚀 Docker 项目设置指南

📌 运行代码的步骤

1️⃣ 克隆 Git 存储库

git clone https://github.com/mjunaid46/mcp/ cd mcp

2️⃣ 编辑模型选择配置

修改config.ini文件,指定模型类型和名称:

[settings] model_type = ollama # Change to "groq" if using Groq model_name = llama3 # Update model name if needed

3️⃣ 构建 Docker 容器

docker-compose build

4️⃣ 运行模型客户端

docker-compose run pull-model-client
-
security - not tested
F
license - not found
-
quality - not tested

通过大型语言模型 (LLM) 解释用户意图,有助于执行系统命令并使用 Brave Search API 检索网络数据。

  1. Overview
    1. Flow Diagram
      1. Working
        1. Prerequisites
          1. Installation
            1. 1. Clone the repository
            2. 2. Create a virtual environment and activate it
            3. 3. Install dependencies
            4. 4. Configure the LLM Model
            5. 5. Configure the Brave Search API
          2. Run
            1. Test
              1. 🚀 Docker Project Setup Guide
                1. 📌 Steps to Run the Code
              ID: beox7u7a9u