Iterable MCP 服务器

Iterable MCP 服务器是一个模型上下文协议(MCP)服务器,使AI系统能够直接与Iterable API交互,提供获取联系人列表、按列表名称检索用户和按电子邮件获取用户详细信息的功能,通过标准化AI通信简化数据驱动的营销操作。

  • by Sami-A
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 Sami-A/iterable-mcp

使用说明

可迭代MCP服务器

自定义可迭代MCP是一种模型上下文协议(MCP)服务器,它使人工智能系统能够直接与Iterable API交互。它提供了工具来获取联系人列表、通过列表名称检索用户,以及从您的Iterable帐户中通过电子邮件获取用户详细信息。 通过将Iterable的营销数据与AI驱动的工作流程相结合,这台MCP服务器使智能代理能够安全地访问、分析并自动化Iterable中的与营销活动相关的操作,通过标准化的AI通信简化了数据驱动的营销运营。

描述

服务器是使用(某种技术/框架/语言等)构建的 @modelcontextprotocol/sdk 并提供了一组工具,这些工具可以被MCP客户端或MCP检查器调用。它使用 axios 向Iterable API发送HTTP请求,并且 zod 用于输入验证。环境变量通过 dotenv。

先决条件

  • 一个可迭代的API密钥

安装

  1. 克隆仓库(如适用)或确保您已获取项目文件。
  2. 导航到项目目录:
    cd mcp-iterable
    
  3. 安装依赖项:
    npm install
    

配置

  1. 创建一个 .env 项目目录根目录下的文件(mcp-iterable/.env)。
  2. 将您的Iterable API密钥添加到 .env 文件:
    ITERABLE_API_KEY=your_iterable_api_key_here
    
    替换 your_iterable_api_key_here 使用您实际的API密钥。

构建项目

要将TypeScript代码编译成JavaScript,请运行:

npm run build

这将把代码编译成 build 目录并使服务器可执行。

运行服务器

项目构建完成后,您可以使用以下命令启动MCP服务器:

npm start

你应该在控制台看到一条消息,指示“Iterable MCP 服务器正在 stdio 上运行”。

可用工具

服务器提供了以下工具:

  1. get_iterable_lists

    • 描述:从Iterable API获取所有列表的列表。
    • 输入:无
    • 输出:一个包含列表数组的JSON字符串。
  2. get_iterable_users_by_list_name

    • 描述:使用列表名称从特定的Iterable列表中获取用户。
    • 输入:
      • listName (字符串,必填):要从中获取用户的列表名称。
    • 输出:一个包含指定列表中用户的JSON字符串。
  3. get_iterable_user_by_email

    • 描述:通过电子邮件从Iterable中获取用户。
    • 输入:
      • email (字符串,必填):要获取的用户的电子邮件地址。
    • 输出:一个包含用户详细信息的JSON字符串。

与MCP Inspector配合使用

您可以使用模型上下文协议检查器与该服务器进行交互。

  1. 确保服务器已构建完成(npm run build)。
  2. 运行检查器:
    npm run inspector
    
    这将启动MCP Inspector,然后您可以连接到 iterable-mcp-server 通过提供构建好的服务器可执行文件的路径(build/index.js)。 然后,你可以调用可用的工具并查看它们的响应。

VS Code MCP 配置

要在VS Code中直接使用此服务器(例如,用于诸如 @iterable 在聊天中),你需要在你的VS Code中进行配置 settings.json 文件。您可以通过在命令面板中运行“首选项:打开用户设置(JSON)”命令来打开此文件。

添加或更新 mcp.servers 配置如下:

{
  // ... other settings ...
  "mcp": {
    "servers": {
      // ... other server configurations ...
      "IterableCustom": {
        "type": "stdio",
        "command": "node", // Or the absolute path to node if not in PATH
        "args": [
          "path/to/your/mcp-iterable/index.js" // Ensure this path is correct for your system
        ],
        "env": {
          // It's recommended to set ITERABLE_API_KEY in your shell environment or .env file
          // rather than directly in settings.json for security reasons.
          // If you must set it here, ensure your settings.json is not committed to version control.
          // "ITERABLE_API_KEY": "your_iterable_api_key_here"
        }
      }
    }
  }
}

重要提示:

  • 替换 "path/to/your/mcp-iterable/index.js" (文件或程序等)的实际绝对路径 index.js 在你构建的项目文件中(通常在 build 或者 dist 运行后生成的文件夹 npm run build)。
  • 它是 强烈推荐 来管理你的 ITERABLE_API_KEY 使用 .env 如“配置”部分所述,通过文件设置,或者在您的shell中将其设置为环境变量。服务器被设计为从(指定位置)获取它 process.env.ITERABLE_API_KEY避免直接在代码中硬编码敏感密钥 settings.json 如果可能的话。
  • 更新后 settings.json为了使更改生效,您可能需要重新启动 VS Code。

项目结构

.
├── index.js                # Main entry point for the server (e.g., run via `npm start`)
├── package.json            # Project metadata and dependencies
├── README.md               # This file
├── tsconfig.json           # TypeScript configuration (if using TypeScript)
├── .env                    # Environment variables (needs to be created by user)
├── config/
│   ├── api-configs.js      # Axios default configurations and API key setup
│   └── intialize-env.js    # Environment variable initialization (dotenv)
├── mcp/
│   ├── mcp-server.js       # MCP server setup and initialization
│   └── tools.js            # Definitions of the tools exposed by the server
├── services/
│   ├── fetch-iterable-lists.js # Service function to fetch lists from Iterable
│   ├── get-user-by-email.js    # Service function to get user by email
│   ├── get-users-email-by-list-id.js # Service function to get users by list ID/name
│   └── index.js              # Exports service functions
├── types/
│   └── schema.js           # Zod schemas for tool input validation
└── util/
    └── handel-error.js     # Utility for error handling (Note: 'handel' might be a typo for 'handle')

这个 README.md 为你的项目提供了良好的概览。