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

Command Executor 및 Brave Search를 위한 MCP 기반 클라이언트-서버 앱

개요

이 프로젝트는 MCP(Model Context Protocol)를 사용하여 사용자 프롬프트를 처리하고, 대규모 언어 모델(LLM)을 사용하여 의도를 파악하며, 실행을 위해 적절한 서비스로 라우팅하는 클라이언트-서버 아키텍처를 구현합니다. 이 시스템은 두 가지 주요 구성 요소로 구성됩니다.

  • 클라이언트: 사용자 입력을 처리하고 이를 LLM으로 전송한 다음 LLM의 결정에 따라 해당 서버로 요청을 전달합니다.
  • 서버: LLM JSON 응답에 지정된 도구 기반 요청을 처리합니다. 시스템 명령을 실행하거나 Brave Search API를 사용하여 웹 데이터를 가져옵니다.

LLM은 사용자 요청에 명령 실행이 필요한지, 아니면 웹 검색이 필요한지 판단합니다. 프롬프트가 명확하지 않은 경우, LLM은 도구 이름( command_execution 또는 fetch_web_data )과 필요한 인수를 명시하는 구조화된 JSON 응답을 생성하기 전에 후속 질문을 합니다.

흐름도

일하고 있는

  1. 사용자 입력: 사용자가 CLI에 프롬프트를 입력합니다.
  2. 클라이언트 처리: 클라이언트가 프롬프트를 LLM에 전달합니다.
  3. LLM 결정:
    • 의도가 불분명한 경우 LLM은 후속 질문을 합니다.
    • 도구 이름과 필요한 인수를 지정하는 JSON 응답을 생성합니다.
  4. 클라이언트 라우팅:
    • 도구가 command_execution 인 경우:
      • 요청은 명령 서버 로 전송됩니다.
      • 명령 서버는 Python의 subprocess 모듈을 사용하여 명령을 실행합니다.
      • 성공 또는 실패 응답이 반환됩니다.
    • 도구가 fetch_web_data 인 경우:
      • 요청은 Fetch Web Data Server 로 전송됩니다.
      • 서버는 Brave Search API 에 관련 결과를 쿼리합니다.
      • 검색 결과가 클라이언트에게 반환됩니다.
  5. 클라이언트 응답: 클라이언트는 CLI를 통해 최종 응답을 사용자에게 다시 보냅니다.

필수 조건

설치

1. 저장소를 복제합니다.

지엑스피1

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. Groq의 API 키를 저장하기 위해 .env 파일을 만듭니다.
    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.txt , create text file with test , rm 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