PubNub MCP Server

by pubnub
Integrations
  • Provides formatted SDK documentation for PubNub's JavaScript SDK, allowing developers to access reference materials for methods like subscribe() and publish() from within Cursor IDE.

  • Supports PubNub functionality through Node.js, allowing users to publish messages to channels, subscribe to channels, fetch message history, and retrieve presence information.

  • Offers access to PubNub's Python SDK documentation, enabling users to fetch docs for methods like publish() directly through Cursor IDE.

用于 Cursor IDE 的 PubNub 模型上下文协议 (MCP) 服务器

此存储库提供了一个基于 CLI 的模型上下文协议 (MCP) 服务器,该服务器将 PubNub SDK 文档和 PubNub API 资源公开给 LLM 驱动的工具。这提高了 LLM AI 代理理解和与 PubNub SDK 和 API 交互的能力。

示例提示

  • “编写一个 PubNub 应用程序,让用户可以通过 PubNub 内置的多用户聊天观看流媒体视频。”
  • “编写一个 PubNub 应用程序,通过地图按需配送杂货。”
  • “编写一个 PubNub 应用程序来实时跟踪包裹的位置。”
  • “编写一个 PubNub 应用程序,实时显示天气预报。”
  • “编写一个 PubNub 应用程序,让用户与朋友一起玩多人游戏。”
  • “编写一个 PubNub 应用程序,显示实时股票价格和新闻更新。”
  • “编写一个 PubNub 应用程序,让用户创建并与朋友分享播放列表。”
  • “构建一个 PubNub JavaScript 应用程序,订阅my_channel频道并将消息记录到控制台。”
  • “向my_channel频道发布一条消息,内容为Hello, PubNub! 。”
  • “向我展示subscribe()的 PubNub JavaScript SDK 文档。”
  • “列出所有可用的 PubNub 函数。”
  • “获取publish()方法的 Python SDK 文档。”
  • “获取test频道的消息历史记录。”
  • test频道和default频道组的存在信息(占用率和 UUID)。”

这需要 Node.js (>= 18) 和 npm ( https://nodejs.org/ ) npx将自动获取并运行最新的 MCP 服务器。

先决条件

  • Node.js(>= 18)和 npm
  • 带有 MCP 支持的 Cursor IDE
  • (可选)用于现场示例的 PubNub 帐户和 API 密钥

安装

在本地运行 PubNub MCP 服务器或通过 npx 将其添加到 Cursor IDE 的首选方法:

npx -y @pubnub/mcp

配置

光标必须处于代理模式才能使用 MCP 服务器。

Cursor IDE 通过 JSON 配置文件发现 MCP 服务器。您可以全局或按项目配置 PubNub MCP 服务器。

全局配置

编辑或创建~/.cursor/mcp.json

{ "mcpServers": { "pubnub": { "command": "npx", "args": ["-y", "@pubnub/mcp"], "env": { "PUBNUB_PUBLISH_KEY": "YOUR_PUBLISH_KEY", "PUBNUB_SUBSCRIBE_KEY": "YOUR_SUBSCRIBE_KEY" } } } }

项目配置

在您的项目目录中,创建.cursor/mcp.json

{ "mcpServers": { "pubnub": { "command": "npx", "args": ["-y", "@pubnub/mcp"], "env": { "PUBNUB_PUBLISH_KEY": "YOUR_PUBLISH_KEY", "PUBNUB_SUBSCRIBE_KEY": "YOUR_SUBSCRIBE_KEY" } } } }

基于 Docker 的配置

如果您希望通过 Docker 运行 MCP 服务器,请将您的 PubNub 密钥设置为环境变量:

export PUBNUB_PUBLISH_KEY=YOUR_PUBLISH_KEY export PUBNUB_SUBSCRIBE_KEY=YOUR_SUBSCRIBE_KEY

然后配置你的~/.cursor/mcp.json (或者你项目中的.cursor/mcp.json ):

{ "mcpServers": { "pubnub": { "command": "docker", "args": [ "run", "-i", "-e", "PUBNUB_PUBLISH_KEY", "-e", "PUBNUB_SUBSCRIBE_KEY", "pubnub/pubnub-mcp-server" ] } } }
  • command指定启动 MCP 服务器的可执行文件。
  • args指定传递给命令的参数。
  • env为服务器进程设置环境变量。

在 Cursor IDE 中使用

  1. 重新启动 Cursor IDE 或打开一个新会话。
  2. 打开 MCP 设置窗格并验证pubnub服务器是否列在可用工具和资源下。
  3. 在聊天中,调用可用资源:
    • pubnub://docs/javascript — 获取 PubNub JavaScript SDK 文档
    • pubnub://docs/python — 获取 PubNub Python SDK 文档
    • pubnub://docs/java — 获取 PubNub Java SDK 文档
    • pubnub://functions — 列出 PubNub 函数(来自resources/pubnub_functions.md静态内容)
  4. 在出现提示时批准资源执行,或在受信任资源的设置中启用自动运行

克劳德·科德

## Install the MCP server if you have node >= 18 claude mcp add pubnub -e PUBNUB_PUBLISH_KEY=your_publish_key -e PUBNUB_SUBSCRIBE_KEY=your_subscribe_key -- npx -y @pubnub/mcp ## Install the MCP server if you have node < 18 and need to point to the full path of node claude mcp add pubnub -e PUBNUB_PUBLISH_KEY=your_publish_key -e PUBNUB_SUBSCRIBE_KEY=your_subscribe_key -- /Users/stephen/.nvm/versions/node/v22.14.0/bin/node /Users/stephen/Projects/mcp-pubnub/index.js ## Install the MCP server using Docker # Ensure your PubNub keys are set as environment variables: export PUBNUB_PUBLISH_KEY=your_publish_key export PUBNUB_SUBSCRIBE_KEY=your_subscribe_key # Depending on your machine’s CPU architecture, you may need to specify the target platform. # For example: # docker run --platform linux/arm64 -i pubnub/pubnub-mcp-server # docker run --platform linux/amd64 -i pubnub/pubnub-mcp-server claude mcp add pubnub -- docker run -i \ -e PUBNUB_PUBLISH_KEY=$PUBNUB_PUBLISH_KEY \ -e PUBNUB_SUBSCRIBE_KEY=$PUBNUB_SUBSCRIBE_KEY \ pubnub/pubnub-mcp-server

输出将是:

Added stdio MCP server pubnub with command: npx -y @pubnub/mcp to local config

示例提示

claude "publish a message 'hi' to the 'my_channel' pubnub channel."
claude "publish a message 'hi' to the 'my_channel' pubnub channel." ╭───────────────────────────────────────────────────╮ │ ✻ Welcome to Claude Code research preview! │ │ │ │ /help for help, /status for your current setup │ │ │ │ cwd: /Users/stephen/Projects/mcp-pubnub │ ╰───────────────────────────────────────────────────╯ ※ Tip: Press Option+Enter to send a multi-line message > publish a message 'hi' to the 'my_channel' pubnub channel. ⏺ I'll publish a message to the PubNub channel for you. ⏺ pubnub:publish_pubnub_message (MCP)(channel: "my_channel", message: "hi")… ⎿  Message published successfully. Timetoken: 17467422499409217 ⏺ Message published successfully to "my_channel".

使用以下命令删除 MCP 服务器:

claude mcp remove pubnub

使用 Claude Desktop

如果您更喜欢 Claude Desktop 中基于 Docker 的 MCP 服务器:

  1. 确保您的 PubNub 密钥已导出到您的 shell 中:
    export PUBNUB_PUBLISH_KEY=your_publish_key export PUBNUB_SUBSCRIBE_KEY=your_subscribe_key
  2. 在 Claude Desktop 的工具部分,添加一个名为pubnub的新工具。
  3. 命令设置为docker
  4. 参数设置为:
    [ "run", "-i", "-e", "PUBNUB_PUBLISH_KEY", "-e", "PUBNUB_SUBSCRIBE_KEY", "pubnub/pubnub-mcp-server" ]

**注意:**在某些机器上(例如 Apple Silicon),您可能需要指定 Docker 平台。请在 Arguments 数组中的"run"后立即插入--platform linux/arm64 (或--platform linux/amd64 )。例如:

[ "run", "--platform", "linux/arm64", "-i", "-e", "PUBNUB_PUBLISH_KEY", "-e", "PUBNUB_SUBSCRIBE_KEY", "pubnub/pubnub-mcp-server" ]
  1. 保存配置。

Claude Desktop 将通过 Docker 调用 PubNub MCP 服务器容器。

执照

本项目遵循 MIT 许可证。详情请参阅LICENSE文件。

故障排除

  • 必须处于代理模式才能使用 MCP 服务器。
  • 验证 Node.js 和 npm 安装。
  • 确保index.js具有执行权限。
  • 检查commandargsenv设置是否正确。
  • 查看 Cursor IDE 日志以查找 MCP 启动错误。

直接 JSON-RPC 命令行用法

您可以使用 JSON-RPC v2.0 直接通过 STDIN/STDOUT 调用 MCP 服务器。请确保您的 PubNub 密钥已在环境中设置,例如:

PUBNUB_PUBLISH_KEY=YOUR_PUBLISH_KEY \ PUBNUB_SUBSCRIBE_KEY=YOUR_SUBSCRIBE_KEY \ node index.js

服务器运行后(或使用一次性调用),通过将 JSON 管道传输到node index.js来发送请求。示例:

# 1) List available tools echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' \ | node index.js # 2) Read PubNub JavaScript SDK documentation echo '{"jsonrpc":"2.0","id":2,"method":"tools/call","params": {"name":"read_pubnub_sdk_docs","arguments":{"language":"javascript"}}}' \ | node index.js # 3) Read PubNub Functions Resource docs (static Markdown) echo '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"read_pubnub_resources","arguments":{"document":"pubnub_functions"}}}' \ | node index.js

快速 JSON-RPC 示例

以下是使用 STDIN/STDOUT 获取 PubNub SDK 文档并发布消息的简化 JSON-RPC v2.0 命令行示例。

1)获取 PubNub JavaScript SDK 文档

echo '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"read_pubnub_sdk_docs","arguments":{"language":"javascript"}}}' | node index.js

2)向 PubNub 频道发布消息

PUBNUB_PUBLISH_KEY=demo \ PUBNUB_SUBSCRIBE_KEY=demo \ echo '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"publish_pubnub_message","arguments":{"channel":"my_channel","message":"Hello, PubNub MCP JSON-RPC!"}}}' \ | node index.js

You must be authenticated.

A
security – no known vulnerabilities
F
license - not found
A
quality - confirmed to work

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

基于 CLI 的模型上下文协议服务器,将 PubNub SDK 文档和函数资源公开给 Cursor IDE 等 LLM 驱动的工具,使用户能够获取文档并通过自然语言提示与 PubNub 频道进行交互。

  1. 示例提示
    1. 先决条件
      1. 安装
        1. 配置
          1. 全局配置
          2. 项目配置
          3. 基于 Docker 的配置
        2. 在 Cursor IDE 中使用
          1. 克劳德·科德
            1. 示例提示
          2. 使用 Claude Desktop
            1. 执照
              1. 故障排除
                1. 直接 JSON-RPC 命令行用法
                  1. 快速 JSON-RPC 示例
                    1. 1)获取 PubNub JavaScript SDK 文档
                    2. 2)向 PubNub 频道发布消息

                  Related MCP Servers

                  • -
                    security
                    F
                    license
                    -
                    quality
                    A simple Model Context Protocol server that enables searching and retrieving relevant documentation snippets from Langchain, Llama Index, and OpenAI official documentation.
                    Last updated -
                    Python
                    • Apple
                    • Linux
                  • -
                    security
                    F
                    license
                    -
                    quality
                    A customized MCP server that enables integration between LLM applications and documentation sources, providing AI-assisted access to LangGraph and Model Context Protocol documentation.
                    Last updated -
                    Python
                    • Linux
                    • Apple
                  • A
                    security
                    A
                    license
                    A
                    quality
                    A Model Context Protocol server that loads multiple OpenAPI specifications and exposes them to LLM-powered IDE integrations, enabling AI to understand and work with your APIs directly in development tools like Cursor.
                    Last updated -
                    7
                    292
                    7
                    TypeScript
                    MIT License

                  View all related MCP servers

                  MCP directory API

                  We provide all the information about MCP servers via our MCP API.

                  curl -X GET 'https://glama.ai/api/mcp/v1/servers/pubnub/pubnub-mcp-server'

                  If you have feedback or need assistance with the MCP directory API, please join our Discord server