MCP代理与服务器生态系统

一个基于模型上下文协议(MCP)的先进演示系统,具备自主代理、浏览器自动化和多服务器编排功能,利用Groq的高性能推理提供无缝的代理体验。

  • by DarshanHegdeP
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 DarshanHegdeP/MCP

使用说明

🚀 MCP代理和服务器生态系统

最先进的演示 模型上下文协议(MCP),具有自主代理、浏览器自动化和多服务器编排功能。该生态系统利用Groq的高性能推理来提供无缝的代理体验。


🏗️ 架构概述

该系统以两种不同的模式运行。以下是交互式CLI和独立MCP服务器模式的精确技术架构。

🎯 1.MCP架构-直接CLI模式(app.py)

在这种模式下,用户直接与基于终端的代理交互,该代理在单个主机进程中处理推理和工具执行。

graph TD
    %% Color Definitions
    classDef blue fill:#3498db,stroke:#333,stroke-width:2px,color:#fff
    classDef lightblue fill:#87ceeb,stroke:#333,stroke-width:2px,color:#000
    classDef purple fill:#9b59b6,stroke:#333,stroke-width:2px,color:#fff
    classDef yellow fill:#f1c40f,stroke:#333,stroke-width:2px,color:#000
    classDef orange fill:#e67e22,stroke:#333,stroke-width:2px,color:#fff
    classDef red fill:#e74c3c,stroke:#333,stroke-width:2px,color:#fff
    classDef green fill:#2ecc71,stroke:#333,stroke-width:2px,color:#fff

    User["👤 User"]:::blue
    App["🖥️ app.py (CLI Interface)"]:::lightblue
    
    subgraph Host ["🟦 MCP Host (Application Space)"]
        direction TB
        subgraph AgentBox ["🟪 MCPAgent (Decision Maker)"]
            Agent["🤖 MCPAgent<br/>(Decision Maker: LLM + Planning)"]:::purple
            LLM["🧠 LLM (Groq - Llama 3.3)<br/>(Reasoning / Decision Making)"]:::purple
            Client["🔌 MCPClient<br/>(Tool Execution Layer / Connector)"]:::yellow
            Agent --- LLM
            Agent --- Client
        end
    end

    Config["📄 browser_mcp.json (Registry)"]:::orange
    
    subgraph ServersBox ["🟥 MCP Servers (Tool Providers)"]
        PW["🌐 Playwright MCP Server"]:::red
        AB["🏠 Airbnb MCP Server"]:::red
        DDG["🔍 DuckDuckGo MCP Server"]:::red
    end

    subgraph ToolsBox ["🟩 Tools Layer"]
        Tools["browser_navigate<br/>browser_click<br/>duckduckgo_search<br/>airbnb_search"]:::green
    end

    %% Logical Connections
    User --> App
    App --> Agent
    Client -->|reads config| Config
    Client --> PW
    Client --> AB
    Client --> DDG
    PW --> Tools
    AB --> Tools
    DDG --> Tools

🎯 2.MCP架构-服务器模式(server.py)

在这种模式下,项目本身充当MCP服务器,将其功能暴露给外部客户端,如VS Code Copilot。

graph TD
    %% Color Definitions
    classDef blue fill:#3498db,stroke:#333,stroke-width:2px,color:#fff
    classDef lightblue fill:#87ceeb,stroke:#333,stroke-width:2px,color:#000
    classDef purple fill:#9b59b6,stroke:#333,stroke-width:2px,color:#fff
    classDef yellow fill:#f1c40f,stroke:#333,stroke-width:2px,color:#000
    classDef orange fill:#e67e22,stroke:#333,stroke-width:2px,color:#fff
    classDef red fill:#e74c3c,stroke:#333,stroke-width:2px,color:#fff
    classDef green fill:#2ecc71,stroke:#333,stroke-width:2px,color:#fff

    Ext["🌐 External Client<br/>(Caller of MCP Server)"]:::blue
    
    subgraph ServerHost ["🟦 MCP Host (server.py)"]
        Server["⚙️ server.py (FastMCP Server)"]:::lightblue
        Task["🛠️ run_task(query)"]:::lightblue
        
        subgraph AgentBoxServer ["🟪 MCPAgent"]
            AgentS["🤖 MCPAgent<br/>(Decision Maker)"]:::purple
            LLMS["🧠 Groq LLM"]:::purple
            ClientS["🔌 MCPClient<br/>(Tool Connector)"]:::yellow
            AgentS --- LLMS
            AgentS --- ClientS
        end
    end

    ConfigS["📄 browser_mcp.json"]:::orange
    
    subgraph ServersBoxServer ["🟥 MCP Servers (Tool Providers)"]
        PWS["🌐 Playwright"]:::red
        ABS["🏠 Airbnb"]:::red
    end

    subgraph ToolsBoxServer ["🟩 Tools"]
        TS["browser, search, etc."]:::green
    end

    %% Logical Connections
    Ext -->|Calls run_task| Server
    Server --> Task
    Task --> AgentS
    ClientS -->|reads config| ConfigS
    ClientS --> PWS
    ClientS --> ABS
    PWS --> TS
    ABS --> TS

✨ 主要特点

  • ⚡ 高性能推理:由Groq's提供技术支持 llama-3.3-70b-versatile 用于近乎即时的推理。
  • 🌐 自主浏览器控制:与Playwright深度集成,用于导航和与网络交互。
  • 🔌 灵活的服务器协议:连接到任何标准MCP服务器,以实现可扩展的工具功能。
  • 📂 状态感知内存:(In app.py)维护对话状态以处理复杂的迭代请求。
  • 🛠️ 自定义服务器扩展:包括自己的 FastMCP 用于将代理工作流包装为可重用工具的服务器。

📂 项目结构

组成部分 责任
app.py 旗舰CLI聊天界面和代理控制器。
server.py A. FastMCP 服务器实现提供 run_task 工具。
browser_mcp.json 所有连接的MCP服务的核心注册表。
pyproject.toml 通过Python管理项目依赖关系 uv 工具。
.env 敏感API密钥的安全存储。

🛠️ 入门指南

1.环境设置

确保你有 紫外线 已安装和有效的Groq API密钥。

# Clone the environment variables
echo "GROQ_API_KEY=your_key_here" > .env

2.启动生态系统

您可以直接与代理交互或运行自定义服务器。

启动交互代理:

python app.py

显示自定义MCP服务器:

python server.py

📖 实现说明

生态系统建立在 mcp_use 库,将LangChain组件和模型上下文协议桥接起来。这 MCPAgent 配置有安全轨道,如 max_steps 以防止在自主执行期间出现无限循环。


🔥 MCP使单个代理能够通过标准化的服务器与多个工具提供商进行交互。


注:上一篇 mcp.json 被检测为缺失或冗余;所有核心配置现在都已整合到 browser_mcp.json.


由...制作❤️ MCP社区