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
- Install the MCP server globally:
npm install -g @topgunbuild/mcp-server
- Configure Claude Desktop by editing
~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"topgun": {
"command": "npx",
"args": ["@topgunbuild/mcp-server"],
"env": {
"TOPGUN_URL": "ws://localhost:8080"
}
}
}
} -
Restart Claude Desktop
-
Try asking: “Show me all tasks in my TopGun database”
Cursor Setup
Add the following to .cursor/config.json in your workspace:
{
"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:
| Tool | Description |
|---|---|
topgun_list_maps | List all available maps |
topgun_query | Query data with filters and sorting |
topgun_mutate | Create, update, or delete records |
topgun_search | Hybrid search (BM25 full-text + exact) |
topgun_subscribe | Watch for real-time changes |
topgun_schema | Get schema information about a map |
topgun_stats | Connection and map statistics |
topgun_explain | Explain 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:
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:
# 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
| Endpoint | Method | Description |
|---|---|---|
/health | GET | Health check |
/mcp | GET | Server info |
/mcp/events | GET | SSE connection for streaming |
/mcp | POST | Stateless tool calls |
Configuration Reference
| Option | Type | Default | Description |
|---|---|---|---|
topgunUrl | string | ws://localhost:8080 | TopGun server WebSocket URL |
authToken | string | - | Authentication token |
allowedMaps | string[] | all | Restrict access to specific maps |
enableMutations | boolean | true | Allow write operations |
enableSubscriptions | boolean | true | Allow real-time subscriptions |
defaultLimit | number | 10 | Default query result limit |
maxLimit | number | 100 | Maximum query result limit |
subscriptionTimeoutSeconds | number | 60 | Subscription timeout |
debug | boolean | false | Enable debug logging |
Environment Variables
| Variable | Description |
|---|---|
TOPGUN_URL | TopGun server URL |
TOPGUN_TOKEN | Authentication token |
TOPGUN_MAPS | Comma-separated allowed maps |
TOPGUN_MCP_PORT | HTTP port (with —http) |
TOPGUN_DEBUG | Enable debug (true/false) |
Security Best Practices
- Restrict Maps: Use
allowedMapsto limit which data the AI can access - Read-Only Mode: Set
enableMutations: falsefor read-only access - Authentication: Always use auth tokens in production
- 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,
});