SM

stepanogil/mcp-sse-demo

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

36 stars 6 forks 质量 43 趋势 0

该仓库演示使用模型上下文协议(MCP)配合服务器发送事件(SSE)与 Zapier MCP 服务器交互,通过 AI 代理访问 Gmail 功能。

概览

该仓库演示使用模型上下文协议(MCP)配合服务器发送事件(SSE)与 Zapier MCP 服务器交互,通过 AI 代理访问 Gmail 功能。 它展示了如何将远程托管的MCP服务器与你选择的LLM集成(即不通过Claude桌面应用或光标) 更新:SSE 正在被弃用,取而代之的是 Stremable HTTP。我通过 FastMCP 添加了一个示例。笔记本在此 该项目使用OpenAI模型(gpt-4o-mini)来理解用户请求,判断是否需要Gmail操作(工具),并通过Zapier MCP服务器执行。 * mcp_clients/zapier_mcp_client.py:包含 GmailMCPClient 类,负责通过 SSE 连接 Zapier MCP 服务器、列出可用工具并管理连接。* chat.py:聊天应用逻辑。它初始化 GmailMCPClient,连接 Zapier 服务器,检索工具,执行工具调用,并将工具输出传递给 LLM 进行综合。(i.

概述(AI 翻译)

该仓库演示使用模型上下文协议(MCP)配合服务器发送事件(SSE)与 Zapier MCP 服务器交互,通过 AI 代理访问 Gmail 功能。

它展示了如何将远程托管的MCP服务器与你选择的LLM集成(即不通过Claude桌面应用或光标)

更新:SSE 正在被弃用,取而代之的是 Stremable HTTP。我通过 FastMCP 添加了一个示例。笔记本在此

概述

该项目使用 OpenAI 模型(gpt-4o-mini)来理解用户请求,判断是否需要 Gmail 操作(工具),并通过 Zapier MCP 服务器执行。

关键文件

  • mcp_clients/zapier_mcp_client.py:包含负责通过SSE连接Zapier MCP服务器、列出可用工具和管理连接的GmailMCPClient类。
  • chat.py:聊天应用逻辑。它初始化GmailMCPClient,连接Zapier服务器,检索工具,执行工具调用,并将工具输出传递给LLM进行综合。(即熟悉的函数调用模式)

先修条件

  • Python 3.8+
  • OpenAI API 密钥
  • 带有MCP访问权限的Zapier账户

布置

  1. 克隆仓库:

本页由 AI 翻译,技术细节请以原文为准。

README

MCP SSE Demo

This repository demonstrates using the Model Context Protocol (MCP) with Server-Sent Events (SSE) to interact with a Zapier MCP server, enabling access to Gmail functionalities through an AI agent.

It illustrates integrating a remotely hosted MCP server with your LLM of choice (i.e. not via the Claude desktop app or Cursor)

Update: SSE is being deprecated in favor of Stremable HTTP. I’ve added an example using this via FastMCP. Notebook here

Overview

The project uses an OpenAI model (gpt-4o-mini) to understand user requests, determine if a Gmail action (tool) is needed, and execute it via the Zapier MCP server.

Key Files

  • mcp_clients/zapier_mcp_client.py: Contains the GmailMCPClient class responsible for connecting to the Zapier MCP server over SSE, listing available tools, and managing the connection.
  • chat.py: The chat application logic. It initializes the GmailMCPClient, connects to the Zapier server, retrieves tools, execute the tool call and pass the tool output to the LLM for synthesis. (i.e. the familiar function calling pattern)

Prerequisites

  • Python 3.8+
  • OpenAI API key
  • Zapier account with MCP access

Setup

  1. Clone the repository:

    git clone 
    cd 
    
  2. Create a virtual environment and install dependencies:

    python -m venv .venv
    source .venv/bin/activate
    pip install openai python-dotenv mcp nest_asyncio fastmcp
    
  3. Create a .env file:

    touch .env
    
  4. Add your credentials to the .env file:

    OPENAI_API_KEY="sk-proj-..."
    ZAPIER_URL="https://actions.zapier.com/mcp/YOUR_SECRET_KEY/sse"
    ZAPIER_URL_FASTMCP="https://mcp.zapier.com/api/mcp/s/your-secret-key/mcp"
    
    
  5. Enable the Zapier actions you want to call as tools

    via https://actions.zapier.com/settings/mcp/

    This demo uses Gmail: Find Email

Usage

The chat.py script provides an async chat(user_input) function. You can import and use this function in your own script or an interactive environment i.e. Jupyter notebook to interact with the chatbot.

Example in a Python script):

import asyncio
from chat import chat

async def main():
    user_query = "Check my latest email."
    response = await chat(user_query)
    print(response)

if __name__ == "__main__":
    asyncio.run(main())

Example in Jupyter notebook

Example using the FastMCP framework (tool discovery and invocation)

在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →