DocsGuidesMCP Server

MCP Server

The MCP (Model Context Protocol) Server enables AI assistants like Claude Desktop and Cursor to interact with your TopGun database through natural language. Query, mutate, and search your data without writing code.

AI Integration

Connect Claude, Cursor, and other MCP-compatible AI tools to your data.

Natural Language

Query and modify data using plain English instead of writing code.

Secure by Default

Restrict maps, disable mutations, and use auth tokens for production.

What is MCP?

MCP (Model Context Protocol) is Anthropic’s open protocol for connecting AI assistants to external data sources. It provides a standardized way for AI tools to:

  • Query data from your TopGun maps
  • Mutate data (create, update, delete)
  • Search using hybrid BM25 + exact matching
  • Subscribe to real-time changes
  • Inspect schema and statistics

Installation

npm install @topgunbuild/mcp-server
# or
pnpm add @topgunbuild/mcp-server

Claude Desktop Setup

  1. Install the MCP server globally:
npm install -g @topgunbuild/mcp-server
  1. Configure Claude Desktop by editing ~/Library/Application Support/Claude/claude_desktop_config.json:
claude_desktop_config.json
{
  "mcpServers": {
    "topgun": {
      "command": "npx",
      "args": ["@topgunbuild/mcp-server"],
      "env": {
        "TOPGUN_URL": "ws://localhost:8080"
      }
    }
  }
}
  1. Restart Claude Desktop

  2. Try asking: “Show me all tasks in my TopGun database”

Cursor Setup

Add the following to .cursor/config.json in your workspace:

.cursor/config.json
{
  "mcp": {
    "servers": {
      "topgun": {
        "command": "npx",
        "args": ["@topgunbuild/mcp-server"],
        "env": {
          "TOPGUN_URL": "ws://localhost:8080"
        }
      }
    }
  }
}

Available Tools

The MCP server exposes these tools to AI assistants:

ToolDescription
topgun_list_mapsList all available maps
topgun_queryQuery data with filters and sorting
topgun_mutateCreate, update, or delete records
topgun_searchHybrid search (BM25 full-text + exact)
topgun_subscribeWatch for real-time changes
topgun_schemaGet schema information about a map
topgun_statsConnection and map statistics
topgun_explainExplain query execution plan

Example Prompts

Once configured, you can use natural language:

  • “Show me all tasks with status ‘done’”
  • “Create a new task called ‘Review PR #123’ with high priority”
  • “Find tasks mentioning authentication”
  • “What fields does the users map have?”
  • “Watch for new high-priority tasks”

Programmatic Usage

For custom integrations, you can use the server programmatically:

src/mcp/server.ts
import { TopGunMCPServer } from '@topgunbuild/mcp-server';

const server = new TopGunMCPServer({
  topgunUrl: 'ws://localhost:8080',
  authToken: process.env.TOPGUN_TOKEN,
  allowedMaps: ['tasks', 'users', 'projects'],
  enableMutations: true,
  enableSubscriptions: true,
  defaultLimit: 10,
  maxLimit: 100,
  debug: false,
});

await server.start();

CLI Options

topgun-mcp [options]

Options:
  --url, -u <url>         TopGun server URL (default: ws://localhost:8080)
  --token, -t <token>     Authentication token
  --maps, -m <maps>       Comma-separated list of allowed maps
  --no-mutations          Disable mutation operations
  --no-subscriptions      Disable subscription operations
  --http                  Start HTTP transport instead of stdio
  --port, -p <port>       HTTP port (default: 3000)
  --debug, -d             Enable debug logging
  --help, -h              Show help
  --version, -v           Show version

HTTP Transport

For web-based MCP clients or custom integrations, start the server with HTTP transport:

Terminal
# Start MCP server with HTTP transport
topgun-mcp --http --port 3000

# With authentication and restricted maps
topgun-mcp --http --port 3000 \
  --url ws://production.example.com:8080 \
  --token $TOPGUN_TOKEN \
  --maps tasks,users \
  --no-mutations

HTTP Endpoints

EndpointMethodDescription
/healthGETHealth check
/mcpGETServer info
/mcp/eventsGETSSE connection for streaming
/mcpPOSTStateless tool calls

Configuration Reference

OptionTypeDefaultDescription
topgunUrlstringws://localhost:8080TopGun server WebSocket URL
authTokenstring-Authentication token
allowedMapsstring[]allRestrict access to specific maps
enableMutationsbooleantrueAllow write operations
enableSubscriptionsbooleantrueAllow real-time subscriptions
defaultLimitnumber10Default query result limit
maxLimitnumber100Maximum query result limit
subscriptionTimeoutSecondsnumber60Subscription timeout
debugbooleanfalseEnable debug logging

Environment Variables

VariableDescription
TOPGUN_URLTopGun server URL
TOPGUN_TOKENAuthentication token
TOPGUN_MAPSComma-separated allowed maps
TOPGUN_MCP_PORTHTTP port (with —http)
TOPGUN_DEBUGEnable debug (true/false)

Security Best Practices

  1. Restrict Maps: Use allowedMaps to limit which data the AI can access
  2. Read-Only Mode: Set enableMutations: false for read-only access
  3. Authentication: Always use auth tokens in production
  4. Local Execution: The MCP server runs locally—data never leaves your machine
// Production-safe configuration
const server = new TopGunMCPServer({
  topgunUrl: 'wss://production.example.com',
  authToken: process.env.TOPGUN_TOKEN,
  allowedMaps: ['public-tasks', 'public-users'], // Restrict access
  enableMutations: false, // Read-only
  enableSubscriptions: false,
  maxLimit: 50,
});