基于 MCP 的命令执行器和 Brave Search 客户端-服务器应用程序
概述
该项目实现了一个**客户端-服务器架构,使用 MCP(模型上下文协议)来处理用户提示,使用大型语言模型 (LLM)**确定其意图,并将其路由到适当的服务进行执行。该系统由两个主要组件组成:
- **客户端:**处理用户输入,将其发送给 LLM,并根据 LLM 的决定将请求转发到适当的服务器。
- **服务器:**根据 LLM 的 JSON 响应中指定的工具处理请求。它要么执行系统命令,要么使用 Brave Search API 获取 Web 数据。
LLM 会判断用户请求是需要执行命令还是网页搜索。如果提示不明确,LLM 会询问后续问题,然后生成结构化的**JSON 响应,**其中会指定工具名称( command_execution
或fetch_web_data
)及其所需参数。
流程图
在职的
- **用户输入:**用户在 CLI 中输入提示。
- **客户端处理:**客户端将提示转发给 LLM。
- 法学硕士决定:
- 如果意图不明确,LLM 会询问后续问题。
- 它生成一个指定工具名称和所需参数的 JSON 响应。
- 客户端路由:
- 如果工具是
command_execution
:- 请求被发送到命令服务器。
- 命令服务器使用 Python 的
subprocess
模块执行命令。 - 返回成功或失败的响应。
- 如果该工具是
fetch_web_data
:- 该请求被发送到Fetch Web Data Server 。
- 服务器查询Brave Search API以获取相关结果。
- 搜索结果返回给客户端。
- 如果工具是
- **客户端响应:**客户端通过 CLI 将最终响应发送回用户。
先决条件
- Python 3.x
- pip(Python 包管理器)
- 虚拟环境设置(可选,但推荐)
- 安装 UV/UVX: UV 安装指南
- Brave Search API: Brave Search API 密钥
- 以下任何法学硕士学位:
安装
1. 克隆存储库
2.创建虚拟环境并激活
3.安装依赖项
4.配置LLM模型
使用 Ollama 模型
- 按照Ollama 安装指南中的说明安装 Ollama CLI 工具。
- 然后,检查 Ollama:
- 在客户端命令中指定模型(llama3或llama2):
使用 Groq 模型
- 创建一个
.env
文件来存储 Groq 的 API Key: - 将您的 Groq 的 API 密钥添加到
.env
文件:
5.配置 Brave Search API
将您的 Brave 的 API 密钥添加到.env
文件:
跑步
- 使用 Ollama 模型
- 使用 Groq 模型
测试
向客户端发出查询(例如, touch test.txt
、 create text file with test
、 rm test.txt file
等)
🚀 Docker 项目设置指南
📌 运行代码的步骤
1️⃣ 克隆 Git 存储库
2️⃣ 编辑模型选择配置
修改config.ini文件,指定模型类型和名称:
3️⃣ 构建 Docker 容器
4️⃣ 运行模型客户端
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
通过大型语言模型 (LLM) 解释用户意图,有助于执行系统命令并使用 Brave Search API 检索网络数据。
Related Resources
Related MCP Servers
- AsecurityAlicenseAqualityFacilitates integration of Brave Search functionalities with AI assistants through the Model Context Protocol, enabling web and local searches using the Brave Search API.Last updated -24PythonMIT License
- -securityFlicense-qualityEnables LLMs to perform sophisticated web searches through proxy servers using Tavily's API, supporting comprehensive web searches, direct question answering, and recent news article retrieval with AI-extracted content.Last updated -1Python
- AsecurityAlicenseAqualityEnables extracting data from websites using natural language prompts, allowing users to specify exactly what content they want in plain English and returning structured JSON data.Last updated -11,3794TypeScriptMIT License
- -securityAlicense-qualityProvides AI-powered web search capabilities using Tavily's search API, enabling LLMs to perform sophisticated web searches, get direct answers to questions, and search recent news articles.Last updated -53PythonMIT License