Uses InfluxDB Line Protocol for inserting data into QuestDB tables with automatic schema creation and type mapping
QuestDB MCP Server
A Model Context Protocol (MCP) server for QuestDB that enables AI assistants to interact with QuestDB databases through tools for querying and inserting data.
Features
Query Execution: Execute SELECT queries on QuestDB tables with structured output
Data Insertion: Insert data into QuestDB tables using the InfluxDB Line Protocol
Table Management: List tables and describe table schemas
Automatic Schema Creation: Tables and columns are created automatically on insert
Type Safety: Full TypeScript support with Zod schema validation
Structured Output: All tools return structured content with output schemas
MCP Logging: Integrated MCP logging messages for better observability
Error Handling: Comprehensive error handling with graceful degradation
Server Instructions: Built-in server instructions for AI assistants
Graceful Shutdown: Proper cleanup on SIGINT/SIGTERM signals
Prerequisites
Node.js v16 or newer
QuestDB instance running (see QuestDB Quick Start)
Installation
As a Package
Install from npm:
Note: This package is publicly available on npm. No authentication or configuration is required to install or use it.
From Source
Clone this repository or navigate to the project directory:
cd questdbmcpInstall dependencies:
npm installBuild the project:
npm run build
Configuration
The server can be configured using environment variables:
QUESTDB_HOST- QuestDB host (default:localhost)QUESTDB_PORT- QuestDB port (default:9000)QUESTDB_USERNAME- QuestDB username (optional, for authentication)QUESTDB_PASSWORD- QuestDB password (optional, for authentication)QUESTDB_AUTO_FLUSH_ROWS- Auto-flush after N rows (optional)QUESTDB_AUTO_FLUSH_INTERVAL- Auto-flush interval in milliseconds (optional)
Usage
This package can be used in two ways:
1. CLI Usage
Run the MCP server directly:
Or for development:
Or install globally:
2. Library Usage
Install as a dependency in your TypeScript project:
Basic Usage
Custom Configuration
Using with Custom Transport
Accessing Internal Components
Creating Custom Tools
Shutdown
TypeScript Types
All types are exported and available for use:
Available Tools
1. query
Execute a SQL SELECT query on QuestDB.
Parameters:
query(string, required): The SQL query to execute (SELECT queries only)format(string, optional): Output format -jsonorcsv(default:json)
Example:
2. insert
Insert data into a QuestDB table. Tables and columns are created automatically if they don't exist.
Parameters:
table(string, required): The name of the table to insert intodata(object, required): An object containing the data to insertKeys are column names
Values are the data (strings, numbers, booleans)
Use
timestampkey for explicit timestamp (milliseconds since epoch)If
timestampis not provided, the current time is used
Example:
3. list_tables
List all tables in the QuestDB database.
Parameters: None
4. describe_table
Get the schema of a specific table.
Parameters:
table(string, required): The name of the table to describe
Example:
QuestDB Setup
Quick Start with Docker
Quick Start with Homebrew (macOS)
The QuestDB Web Console will be available at: http://localhost:9000
Development
Building
Type Checking
Development Mode
Data Types
The insert tool automatically maps JavaScript types to QuestDB types:
String →
SYMBOL(indexed string type)Number (integer) →
LONGNumber (float) →
DOUBLEBoolean →
BOOLEANTimestamp →
TIMESTAMP(when using thetimestampfield)
Security Notes
Only SELECT queries are allowed through the
querytool for safetyThe server uses the QuestDB REST API for queries and the InfluxDB Line Protocol for inserts
Authentication is supported via username/password if your QuestDB instance requires it
Examples
Inserting Trade Data
Querying Data
Listing Tables
License
MIT