> hypequery

Programmatic usage

Start the Hypequery MCP server from a Node process.

Use createMCPServer when you want to start the MCP server from your own Node process instead of using the CLI.

import { createMCPServer } from '@hypequery/mcp';
import { createDatasetClient } from '@hypequery/datasets';
import { createQueryBuilder } from '@hypequery/clickhouse';
import { datasets } from './datasets/index.js';

const db = createQueryBuilder({
  url: process.env.CLICKHOUSE_URL!,
  username: process.env.CLICKHOUSE_USER!,
  password: process.env.CLICKHOUSE_PASSWORD!,
  database: process.env.CLICKHOUSE_DATABASE!,
});

const analytics = createDatasetClient({ queryBuilder: db });

const server = await createMCPServer({
  datasets,
  analytics,
  name: 'analytics-mcp',
  version: '1.0.0',
});

// The server is now running over stdio.

createMCPServer returns the server instance after calling start(). The stdio transport is intended for MCP clients that launch and manage the process.

Tenant-scoped servers

If registered datasets have tenantKey, pass a trusted tenantId when creating the MCP server.

const server = await createMCPServer({
  datasets,
  analytics,
  tenantId: 'tenant_123',
});

The server forwards that value as dataset runtime tenant context for query_dataset and query_metric.

Stop the server

If your application owns the lifecycle, call stop().

await server.stop();

Config shape

The programmatic API accepts the same core inputs as the CLI config, plus optional server metadata and tenant scope.

type MCPServerConfig = {
  datasets: Record<string, Record<string, unknown>>;
  analytics: DatasetClient;
  name?: string;
  version?: string;
  tenantId?: string;
};

On this page