Skip to main content
Glama
spacetimedb-mcp

spacetimedb-mcp

spacetimedb-mcp

Model Context Protocol (MCP) server for SpacetimeDB. Query databases, call reducers, inspect schemas, and manage your SpacetimeDB instances directly from your MCP-enabled AI assistant.

Features

  • šŸ” Query Schemas: Get detailed information about database tables and reducers

  • šŸ—„ļø Run SQL Queries: Execute SQL queries to inspect and modify data

  • ⚔ Call Reducers: Invoke reducer functions on your databases

  • šŸ“‹ View Logs: Fetch and parse database logs

  • āœ… Test Connections: Verify connectivity to your SpacetimeDB instance

Related MCP server: Database MCP Server

Installation

npm install spacetimedb-mcp

Configuration

Add the server to your mcp.json configuration file (typically located in your home directory under .config/mcp.json or similar, depending on your MCP client).

Basic Configuration (Global Installation)

If you've installed the package globally (npm install -g spacetimedb-mcp), use one of these methods:

Option 1: Use npx (Recommended)

{
  "mcpServers": {
    "spacetimedb": {
      "command": "npx",
      "args": ["-y", "spacetimedb-mcp"],
      "env": {
        "SPACETIMEDB_HOST": "http://localhost:3000",
        "SPACETIMEDB_TOKEN": "your-token-here",
        "SPACETIMEDB_DEFAULT_DATABASE": "strc"
      }
    }
  }
}

Option 2: Use the global package path

First, find your global node_modules path:

npm root -g

Then use that path in your config:

{
  "mcpServers": {
    "spacetimedb": {
      "command": "node",
      "args": ["C:/nvm4w/nodejs/node_modules/spacetimedb-mcp/dist/index.js"],
      "env": {
        "SPACETIMEDB_HOST": "http://localhost:3000",
        "SPACETIMEDB_TOKEN": "your-token-here",
        "SPACETIMEDB_DEFAULT_DATABASE": "strc"
      }
    }
  }
}

Note: Replace C:/nvm4w/nodejs/node_modules with your actual global npm root path from npm root -g.

Local Installation

If you prefer installing locally in your project:

npm install spacetimedb-mcp

Then configure:

{
  "mcpServers": {
    "spacetimedb": {
      "command": "node",
      "args": ["node_modules/spacetimedb-mcp/dist/index.js"],
      "env": {
        "SPACETIMEDB_HOST": "http://localhost:3000",
        "SPACETIMEDB_TOKEN": "your-token-here",
        "SPACETIMEDB_DEFAULT_DATABASE": "strc"
      }
    }
  }
}

Environment Variables

Variable

Required

Default

Description

SPACETIMEDB_HOST

No

http://localhost:3000

The base URL of your SpacetimeDB instance

SPACETIMEDB_TOKEN

Yes

-

Authentication token (Bearer token)

SPACETIMEDB_DEFAULT_DATABASE

No

-

Default database name to use when not specified in tool calls

Tip: You can use spacetime login show --token to get your authentication token.

Available Tools

test_connection

Test the connection to the SpacetimeDB instance.

Example:

{
  "tool": "test_connection"
}

Response:

{
  "status": "connected",
  "host": "http://localhost:3000"
}

get_schema

Get the schema of a database, including all tables and reducers.

Parameters:

  • database (string, optional): Database name (uses default if not specified)

Example:

{
  "tool": "get_schema",
  "arguments": {
    "database": "strc"
  }
}

Response: Formatted schema showing tables with columns and reducers with parameters.

sql_query

Run a SQL query against the database.

Parameters:

  • database (string, optional): Database name (uses default if not specified)

  • query (string, required): SQL query to execute

  • format (string, optional): Output format (json or markdown, default json)

Example:

{
  "tool": "sql_query",
  "arguments": {
    "database": "strc",
    "query": "SELECT * FROM users LIMIT 10",
    "format": "markdown"
  }
}

Response: Query results with schema and rows.

(Publishing section removed)

describe_database

Get metadata about a database.

Parameters:

  • database (string, optional): Database name (uses default if not specified)

Example:

{
  "tool": "describe_database",
  "arguments": {
    "database": "strc"
  }
}

Response: Database metadata as JSON.

get_database_identity

Get the identity for a database name.

Parameters:

  • database (string, optional): Database name (uses default if not specified)

Example:

{
  "tool": "get_database_identity",
  "arguments": {
    "database": "strc"
  }
}

Response: Identity string for the database.

delete_database

Delete a database.

Parameters:

  • database (string, optional): Database name (uses default if not specified)

Example:

{
  "tool": "delete_database",
  "arguments": {
    "database": "strc"
  }
}

Response: Result from the delete operation.

list_databases

List databases owned by an identity.

Parameters:

  • identity (string, required): SpacetimeDB identity

Example:

{
  "tool": "list_databases",
  "arguments": {
    "identity": "0xabc123"
  }
}

Response: Array of database addresses.

add_database_alias

Add a friendly alias to a database identity.

Parameters:

  • identity (string, required): Database identity

  • name (string, required): Alias to add

Example:

{
  "tool": "add_database_alias",
  "arguments": {
    "identity": "0xabc123",
    "name": "chat-app"
  }
}

Response: Result from the alias creation.

get_database_aliases

List aliases for a database identity.

Parameters:

  • identity (string, required): Database identity

Example:

{
  "tool": "get_database_aliases",
  "arguments": {
    "identity": "0xabc123"
  }
}

Response: Array of aliases.

call_reducer

Call a reducer function on the database.

Parameters:

  • database (string, optional): Database name (uses default if not specified)

  • reducer (string, required): Name of the reducer function

  • args (array, required): Arguments for the reducer as a JSON array

Example:

{
  "tool": "call_reducer",
  "arguments": {
    "database": "strc",
    "reducer": "CreateUser",
    "args": [
      "username_123",
      "user@example.com"
    ]
  }
}

Response: Result from the reducer call (may be empty for void returns).

get_logs

Get recent logs from the database.

Parameters:

  • database (string, optional): Database name (uses default if not specified)

  • count (number, optional): Number of log lines to fetch (default: 50)

Example:

{
  "tool": "get_logs",
  "arguments": {
    "database": "strc",
    "count": 20
  }
}

Response: Formatted log lines with timestamps, levels, and messages.

Usage Examples

Getting Started

  1. Install the package:

    npm install spacetimedb-mcp
  2. Configure your mcp.json with your SpacetimeDB credentials

  3. Restart your MCP client (e.g., Cursor, Claude Desktop)

  4. Start using the tools through your AI assistant!

Common Workflows

Inspect Database Schema:

Use get_schema to see all tables and reducers in the database

Query Data:

Use sql_query to SELECT data from tables

Create Entities:

Use call_reducer to invoke reducer functions like CreateUser

Monitor Activity:

Use get_logs to see recent database activity

Troubleshooting

Connection Errors

If you see connection errors:

  1. Verify SPACETIMEDB_HOST is correct

  2. Check that your SpacetimeDB instance is running

  3. Ensure SPACETIMEDB_TOKEN is valid

Authentication Errors

If you get 401/403 errors:

  • Verify your SPACETIMEDB_TOKEN is a valid Bearer token

  • Check token permissions for the database operations

Database Not Found

If you see 404 errors for database operations:

  • Verify the database name is correct

  • Check that the database exists on your SpacetimeDB instance

  • Ensure your token has access to the database

SQL Parser Errors

Some SQL queries may not be supported. The parser has limitations on:

  • Complex ORDER BY clauses

  • Certain WHERE clause formats

  • Some advanced SQL features

Try simplifying your queries if you encounter parser errors.

Development

Building

npm run build

This compiles TypeScript source files to dist/index.js.

Testing

npm test

Publishing

Manual publish helper (builds, tests, packs, publishes):

npm run publish-release

Project Structure

spacetimedb-mcp/
ā”œā”€ā”€ src/
│   ā”œā”€ā”€ client.ts         # SpacetimeDB HTTP client
│   ā”œā”€ā”€ index.ts          # CLI entry point
│   ā”œā”€ā”€ server.ts         # MCP server wiring
│   └── types.ts          # Shared type definitions
ā”œā”€ā”€ dist/
│   └── index.js          # Compiled output
ā”œā”€ā”€ tests/
│   ā”œā”€ā”€ client.test.ts    # Client unit tests
│   └── server-handlers.test.ts # Server handler unit tests
ā”œā”€ā”€ package.json
ā”œā”€ā”€ tsconfig.json
ā”œā”€ā”€ vitest.config.ts
└── README.md

Requirements

  • Node.js >= 18.0.0

  • Access to a SpacetimeDB instance

  • Valid SpacetimeDB authentication token

License

MIT

Available Tools

12 tools
add_database_aliasC

Add a friendly alias to a database identity.

Inputs: name (required), identity (required).

call_reducerC

Call a reducer function on the database.

Inputs: args (required), reducer (required), database (required).

delete_databaseC

Delete a database.

Inputs: database (required).

describe_databaseC

Get metadata about a database.

Inputs: database (required).

get_database_aliasesC

List aliases for a database identity.

Inputs: identity (required).

get_database_identityC

Get the identity for a database name.

Inputs: database (required).

get_logsC

Get recent logs from the database.

Inputs: database (required), count.

get_schemaC

Get the tables and reducers (functions) of a database.

Inputs: database (required).

list_databasesB

List databases owned by an identity.

Inputs: identity (required).

publish_databaseC

Publish or update a database using the spacetime CLI.

Inputs: database (required), project_path (required), clear_data.

sql_queryC

Run a SQL query against the database to inspect or modify data.

Inputs: query (required), database (required), format.

test_connectionB

Test the connection to the SpacetimeDB instance.

Inputs: no named parameters.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.2/5.0

    Scored across 12 tools

    Disambiguation4/5

    Most tools target clearly distinct actions or resources, such as publishing, deleting, listing, testing connection, and calling reducers. The main overlap is between describe_database and get_schema/get_database_identity, since 'metadata about a database' could be read broadly enough to include structure or identity details. Descriptions mostly resolve this, but the boundary is not perfectly sharp.

    Naming Consistency4/5

    The tool set uses snake_case throughout and almost every name follows a verb_noun pattern, such as list_databases, delete_database, and get_logs. The main deviation is sql_query, which is a noun-style name rather than a strict verb_noun form like run_sql_query. This is a minor inconsistency in an otherwise predictable naming scheme.

    Tool Count5/5

    Twelve tools is well within a reasonable range for a database management MCP server. Each tool appears to earn its place by covering a distinct administrative action, including connection testing, schema inspection, querying, publishing, access metadata, aliases, reducers, and logs. There is no obvious padding or missing major capability at this count.

    Completeness4/5

    The surface covers most of the SpacetimeDB lifecycle: publish/update, describe, list, delete, inspect schema, query data, call reducers, manage aliases, and retrieve logs. The main minor gap is alias lifecycle symmetry, since aliases can be added and listed but not removed. Overall the core workflows are covered with only small omissions.

    Maintenance

    ActivityNo data
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables LLMs and agents to interact with relational databases (SQL Server, MySQL, PostgreSQL) through MCP tools. Supports executing queries, inserting records, listing tables, and exposing database schemas with secure credential management.
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides universal database operations for AI assistants through MCP, supporting 40+ databases including PostgreSQL, MySQL, MongoDB, Redis, and SQLite with built-in introspection tools for schema exploration.
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants to manage and query SQLite databases through MCP tools, supporting CRUD operations, schema management, and saved views.
      4 npm
      MIT