PubNub MCP Server
The PubNub Model Context Protocol (MCP) Server is an open-source tool that enables AI-powered development environments to interact with PubNub's SDKs and global infrastructure. It allows you to build, use, and troubleshoot real-time applications faster by describing your app's behavior in natural language.
With the PubNub MCP Server, you can:
- Build real-time applications without extensive PubNub SDK knowledge
- Use AI-powered environments (like Cursor IDE, Claude Code, or Claude Desktop) to understand and implement PubNub APIs
- Access PubNub's resources dynamically, including SDK documentation and code examples
- Leverage AI agents as coding assistants to build, test, and troubleshoot your applications
For example, you can ask your AI coding assistant to build a real-time chat with presence or publish a message to a PubNub channel using plain English descriptions.
Prerequisites
Before you begin, ensure you have:
- A PubNub account
- One of the supported AI agents installed
- Basic familiarity with your chosen AI development environment
Supported AI agents
The PubNub MCP Server is compatible with:
Setup
To set up the PubNub MCP Server, follow these steps:
- Cursor IDE
- Claude Code
- Claude Desktop with Docker
To set up the PubNub MCP Server with Cursor IDE, follow these steps:
-
Create a PubNub account on the Admin Portal, and create a new app and keyset.
Sign up
Don't feel like leaving this page to sign up?
-
In your Cursor project, create or open the
.cursor/mcp.json
or~/.cursor/mcp.json
files and add your publish and subscribe keys:{
"mcpServers": {
"pubnub": {
"command": "npx",
"args": ["-y", "@pubnub/mcp"],
"env": {
"PUBNUB_SUBSCRIBE_KEY": "YOUR_SUBSCRIBE_KEY",
"PUBNUB_PUBLISH_KEY": "YOUR_PUBLISH_KEY"
}
}
}
}When you save the file, a notification is displayed.
-
In the prompt, click Enable. Then, navigate to Cursor Settings (the gear icon in top right corner) -> MCP, and check if
pubnub
is enabled. -
Ask the AI agent to build your PubNub-powered app for you by describing the functionality yourself or by using a sample prompt.
Agent mode
Make sure to use the Agent mode. Depending on your Cursor rules, you may also need to explicitly ask the AI agent to use the PubNub MCP server.
To set up the PubNub MCP Server with Claude Code, follow these steps:
-
Create a PubNub account on the Admin Portal, and create a new app and keyset.
Sign up
Don't feel like leaving this page to sign up?
-
In the directory of your choice, open the terminal, and run the following command where
your_publish_key
andyour_subscribe_key
are your publish and subscribe keys:claude mcp add pubnub \
-e PUBNUB_PUBLISH_KEY=your_publish_key \
-e PUBNUB_SUBSCRIBE_KEY=your_subscribe_key \
-- npx -y @pubnub/mcpAfter you run the command, the
Added stdio MCP server pubnub with command: npx -y @pubnub/mcp to local config
is displayed. -
In the terminal, run
claude mcp list
to check that the PubNub MCP server is added. -
Still in the terminal, run
claude
and Ask the AI agent to build your PubNub-powered app for you by describing the functionality yourself or by using a sample prompt.
To set up the PubNub MCP Server with Claude Desktop, follow these steps:
-
Create a PubNub account on the Admin Portal, and create a new app and keyset.
Sign up
Don't feel like leaving this page to sign up?
-
In the terminal, export your keys as environment variables where
your_publish_key
andyour_subscribe_key
are your publish and subscribe keys:
show all 16 lines# On Linux or MacOS
export PUBNUB_PUBLISH_KEY=your_publish_key
export PUBNUB_SUBSCRIBE_KEY=your_subscribe_key
# On Windows
set PUBNUB_PUBLISH_KEY=your_publish_key
set PUBNUB_SUBSCRIBE_KEY=your_subscribe_key
# For Bash, permanently
echo "export PUBNUB_PUBLISH_KEY=your_publish_key" >> ~/.bashrc
echo "export PUBNUB_SUBSCRIBE_KEY=your_subscribe_key" >> ~/.bashrc
# For Zsh, permanently
echo 'export PUBNUB_PUBLISH_KEY=your_publish_key' >> ~/.zshrc
echo 'export PUBNUB_SUBSCRIBE_KEY=your_subscribe_key' >> ~/.zshrc -
In Claude Desktop, navigate to Tools -> Add Tool.
-
Set the tool name to
pubnub
and the command todocker
. -
Set the tool arguments to the following:
show all 17 lines[
"run",
"-i",
"-e", "PUBNUB_PUBLISH_KEY",
"-e", "PUBNUB_SUBSCRIBE_KEY",
"pubnub/pubnub-mcp-server"
]
# For Apple Silicon or other platforms
[
"run",
"--platform", "linux/arm64",
"-i",
"-e", "PUBNUB_PUBLISH_KEY",
"-e", "PUBNUB_SUBSCRIBE_KEY",Save the tool configuration and confirm the tool is listed under your available Claude Desktop tools.
-
In Claude Desktop's chat, Ask the AI agent to build your PubNub-powered app for you by describing the functionality yourself or by using a sample prompt.
Sample prompts
Happy vibe coding!
- "Write a PubNub app that lets the user watch streaming videos with built-in multi-user chat with PubNub."
- "Write a PubNub app for on-demand delivery of groceries with a map."
- "Write a PubNub app that tracks the location of a package in real-time."
- "Write a PubNub app that shows the weather forecast in real-time."
- "Write a PubNub app that lets users play multiplayer games with friends."
- "Write a PubNub app that shows live stock prices and news updates."
- "Write a PubNub app that lets users create and share playlists with friends."
- "Build a PubNub JavaScript app that subscribes to the
my_channel
channel and logs messages to the console." - "Publish a message to the
my_channel
channel with the messageHello, PubNub!
." - "Show me the PubNub JavaScript SDK documentation for
subscribe()
." - "List all available PubNub Functions."
- "Fetch the Python SDK docs for the
publish()
method." - "Fetch the message history for the
test
channel." - "Retrieve presence information (occupancy and UUIDs) for the
test
channel and thedefault
channel group."