Claude Integration

Integrate NoLag MCP with Claude to build real-time applications through natural conversation.

Setup with Claude Desktop

Step 1: Install MCP Server

npm install -g @nolag/mcp-server

Step 2: Configure Claude Desktop

Add NoLag to your Claude Desktop configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "nolag": {
      "command": "npx",
      "args": ["@nolag/mcp-server"],
      "env": {
        "NOLAG_API_KEY": "your-api-key-here"
      }
    }
  }
}

Step 3: Restart Claude Desktop

Restart Claude Desktop to load the new MCP server. You should see "nolag" in the available tools.

Setup with Claude Code (CLI)

For Claude Code CLI users, add the MCP server to your project:

// .claude/mcp.json
{
  "servers": {
    "nolag": {
      "command": "npx",
      "args": ["@nolag/mcp-server"],
      "env": {
        "NOLAG_API_KEY": "${NOLAG_API_KEY}"
      }
    }
  }
}

Set your API key as an environment variable:

export NOLAG_API_KEY="your-api-key-here"

Example Conversations

Creating a Chat Application

You:

I want to build a chat application with NoLag. Can you set up the infrastructure for me? I need a general chat room and private messaging between users.

Claude:

I'll set up a NoLag project for your chat application. Let me create the infrastructure:

*Uses nolag_create_project, nolag_create_app, nolag_create_topic*

I've created:

  • Project: "Chat App"
  • App: "chat-main"
  • Topics: "chat/general", "chat/private/{userId}"

Would you like me to generate the client code next?

Generating Client Code

You:

Yes, generate React TypeScript code for subscribing to the general chat and displaying messages.

Claude:

*Uses nolag_generate_code*

Here's your React component:

import { useEffect, useState, useRef } from 'react'
import { NoLag } from '@nolag/js-sdk'

interface ChatMessage {
  id: string
  sender: string
  text: string
  timestamp: number
}

export function ChatRoom() {
  const [messages, setMessages] = useState<ChatMessage[]>([])
  const clientRef = useRef<ReturnType<typeof NoLag> | null>(null)

  useEffect(() => {
    const connect = async () => {
      const client = NoLag(process.env.NEXT_PUBLIC_NOLAG_TOKEN!)
      clientRef.current = client

      client.on('connect', () => {
        // Set presence after connecting
        client.setPresence({ username: 'current-user' })

        // Subscribe to chat topic
        client.subscribe('chat/general')
      })

      // Listen for messages
      client.on('chat/general', (data: ChatMessage) => {
        setMessages(prev => [...prev, data])
      })

      await client.connect()
    }

    connect()
    return () => { clientRef.current?.disconnect() }
  }, [])

  const sendMessage = (text: string) => {
    clientRef.current?.emit('chat/general', {
      id: crypto.randomUUID(),
      sender: 'current-user',
      text,
      timestamp: Date.now()
    })
  }

  return (
    <div>
      {messages.map(msg => (
        <div key={msg.id}>
          <strong>{msg.sender}:</strong> {msg.text}
        </div>
      ))}
    </div>
  )
}

Debugging Issues

You:

My messages aren't being delivered. Can you check what's happening with my chat/general topic?

Claude:

*Uses nolag_get_connections, nolag_subscribe, nolag_get_metrics*

I checked your topic and found:

  • Active connections: 3
  • Messages in last hour: 0
  • Last message: 2 hours ago

It looks like messages are being published but not reaching subscribers. Let me check the ACL configuration...

Best Practices

Be Specific

Give Claude detailed context about your application:

Less Effective

"Set up NoLag for my app"

More Effective

"Set up NoLag for a multiplayer game with rooms for up to 4 players, real-time position updates at 60fps, and a lobby system"

Iterate on Code

Ask Claude to refine generated code:

  • "Add error handling to this code"
  • "Optimize for mobile with offline support"
  • "Add TypeScript types for the message payloads"

Use for Learning

Ask Claude to explain NoLag concepts:

  • "Explain when I should use QoS 2 vs QoS 1"
  • "What's the best topic structure for a social feed?"
  • "How do I handle reconnection gracefully?"

Limitations

  • MCP tools have rate limits - avoid bulk operations
  • Long-running subscriptions are not supported - use for inspection only
  • API key permissions determine available operations

Next Steps