Set up the MCP server

Connect an AI coding tool to the PubNub Model Context Protocol (MCP) server so it can work on your PubNub account from plain-language requests. Once connected, the tool can:

  • Create and configure apps and keysets.
  • Look up current SDK and Chat SDK documentation, and SDK migration guides.
  • Read usage metrics and Insights analytics.
  • Publish and subscribe, read message history, and query Presence and App Context data.
  • Manage Functions and Illuminate resources.

Use the hosted server at https://mcp.pubnub.com if your tool supports remote MCP servers. You sign in with your PubNub account and there's nothing to install. If your tool only runs local servers, run the server locally instead. For how the two differ, see MCP server. For what each tool does, see Available MCP tools.

Before you start​

Confirm you have:

Connect to the hosted server​

Select your tool. Each flow ends with a PubNub sign-in page. Select the organization to authorize and click Allow access. The connection gets the same permissions your user has in that organization.

If you previously used the local server, remove its entry from your tool's configuration first.

  1. Open the VS Code install link, select Open in Visual Studio Code, then click Install.

    To add the server by hand instead, add it to .vscode/mcp.json in your project, or to your user configuration with the MCP: Open User Configuration command:

    {
    "servers": {
    "PubNub": {
    "type": "http",
    "url": "https://mcp.pubnub.com"
    }
    }
    }
  2. Sign in when prompted.

Learn more in VS Code documentation.

Local server configuration​

The local server is the @pubnub/mcp npm package. Your AI tool starts it on your machine and it authenticates with a PubNub API key instead of a sign-in. It exposes the same tools as the hosted server.

Before you start with the local server​

Confirm you have:

  • Node.js version 20.0.0 or higher (node --version to check). Claude Desktop runs the server through Docker instead, so it needs Docker.
  • A PubNub API key with read and write access to apps and keysets, and read access to secret keys. Anything the key can do, the AI tool can do, so grant only the permissions you want the AI tool to have.
Store your API key securely

Store the API key in a secure location such as a secrets manager, environment variable, or encrypted configuration file. Never commit API keys to source control.

To get the API key, you need to have or create a service integration.

  1. Log in to the Admin Portal.

  2. Navigate to Organization settings → API Management.

  3. Find the Service Integration (or create a new one) to create an API key for.

  4. Click + Generate API Key.

  5. In the dialog that appears, choose the expiration date for the API key.

  6. Click Generate API Key and copy the generated API key, as you won't be able to view it again.

Local server environment variables​

Set these in the env block of the server entry.

VariableRequiredDescription
PUBNUB_API_KEYNo, but most tools need itService Integration API key. Without it, only the documentation tools and the real-time tools you pass a publish and subscribe key to work. App, keyset, usage, Insights, Illuminate, and Functions tools need it.
MCP_ANALYTICS_DISABLEDNoSet to true to turn off the usage analytics the server reports.

Add the local server to your tool​

Your AI tool saves its MCP configuration as a plain-text file, so any API key you type into that file stays on disk. Keep the key out of project files that you commit to version control. Where a tool supports it, the examples below read the key from an environment variable or a prompt instead. Otherwise, add the entry to your user-level configuration and replace <your-pubnub-api-key> with your API key.

Add the following to .vscode/mcp.json in your project, or to your user configuration with the MCP: Open User Configuration command. VS Code prompts for the key when the server first starts, and doesn't write it to the file:

{
"inputs": [
{
"type": "promptString",
"id": "pubnub-api-key",
"description": "PubNub API key",
"password": true
}
],
"servers": {
"PubNub": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@pubnub/mcp@latest"],
"env": {
show all 20 lines

Verify the connection​

Ask your AI tool to use a PubNub tool, for example "List my PubNub keysets" or "Publish a test message to the channel test." A working connection returns real account data or a publish timetoken, not an error about a missing or unavailable tool.

If the tool can't reach the server:

  • Check the configuration file for syntax errors, then restart the tool.
  • If a hosted connection that used to work stops, it probably expired. Hosted connections expire automatically. Sign in again the same way you set it up.
  • If your organization is missing from the sign-in page, ask an Account Owner or Account Admin to allow MCP connections in organization settings.

Next steps​

Was this page useful?

Last updated on