60db-mcp-server 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. package/README.md +63 -2
  2. package/cli.js +119 -0
  3. package/index.js +197 -0
  4. package/package.json +14 -4
  5. package/test.js +52 -0
package/README.md CHANGED
@@ -1,3 +1,64 @@
1
- # Temporary Holding Version
1
+ # 60db-mcp-server
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ An MCP (Model Context Protocol) server that exposes the 60db time-series database to LLM clients. Install it globally and connect Claude Desktop, the Claude CLI, or any MCP-compatible agent to query, ingest, and inspect 60db datasets through natural language — the server translates tool calls into authenticated 60db API requests.
4
+
5
+ For engineers and analysts who want to drive 60db from an AI assistant without writing SQL or curl by hand.
6
+
7
+ ## Features
8
+
9
+ - Implements the MCP `tools` interface for 60db: `query`, `ingest`, `list-tables`, `describe-table`, `create-table`.
10
+ - Streams large query results back to the client in chunks to stay within MCP message limits.
11
+ - Read-only mode flag to let agents explore schemas without write risk.
12
+ - OAuth/API-key auth handled by the server; clients never see credentials.
13
+ - Works with `claude mcp add`, `mcp.json`, and stdio or HTTP transports.
14
+ - Per-dataset allow-lists so you can restrict an agent to specific tables.
15
+ - Ships as a single global binary via npm, no extra runtime needed.
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install -g 60db-mcp-server
21
+ ```
22
+
23
+ ## Quick start
24
+
25
+ Register the server with the Claude CLI:
26
+
27
+ ```bash
28
+ claude mcp add 60db -- 60db-mcp-server --api-key $SIXTYDB_API_KEY
29
+ ```
30
+
31
+ Or add it to your `mcp.json`:
32
+
33
+ ```json
34
+ {
35
+ "mcpServers": {
36
+ "60db": {
37
+ "command": "60db-mcp-server",
38
+ "args": ["--read-only"],
39
+ "env": { "SIXTYDB_API_KEY": "..." }
40
+ }
41
+ }
42
+ }
43
+ ```
44
+
45
+ Then ask your agent: *"What tables are in 60db, and show me the last 10 rows of events."*
46
+
47
+ ## CLI
48
+
49
+ ### `60db-mcp-server`
50
+ Start the MCP server over stdio (default). Flags:
51
+
52
+ - `--api-key <key>` — 60db API key (or read `SIXTYDB_API_KEY`).
53
+ - `--read-only` — disable ingest/create tools.
54
+ - `--dataset <name>` — restrict the session to one dataset.
55
+ - `--transport stdio|http` — select the MCP transport (default `stdio`).
56
+ - `--port <n>` — HTTP transport port (default `8787`).
57
+
58
+ ## Configuration
59
+
60
+ All settings can be passed as flags or environment variables: `SIXTYDB_API_KEY`, `SIXTYDB_DATASET`, `SIXTYDB_READ_ONLY=1`, `SIXTYDB_TRANSPORT`, `SIXTYDB_PORT`. A `.60db-mcp.json` in the working directory is also honored for per-project dataset scoping.
61
+
62
+ ## License
63
+
64
+ MIT
package/cli.js ADDED
@@ -0,0 +1,119 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * 60db-mcp-server CLI entry point. Starts the MCP server over stdio (default)
5
+ * or HTTP. Flags and env vars configure auth, dataset scoping, and transport.
6
+ */
7
+
8
+ const {
9
+ resolveConfig,
10
+ listTools,
11
+ assertToolAllowed,
12
+ chunkRows,
13
+ SixtyDBError,
14
+ } = require('./index');
15
+
16
+ /**
17
+ * Minimal argv parser. Supports `--flag value`, `--flag` (boolean), and
18
+ * `--flag=value`. Unknown flags are collected but ignored.
19
+ * @param {string[]} argv
20
+ * @returns {{ flags: Object, positional: string[] }}
21
+ */
22
+ function parseArgs(argv) {
23
+ const flags = {};
24
+ const positional = [];
25
+ for (let i = 0; i < argv.length; i++) {
26
+ const a = argv[i];
27
+ if (a.startsWith('--')) {
28
+ const eq = a.indexOf('=');
29
+ if (eq !== -1) {
30
+ flags[a.slice(2, eq)] = a.slice(eq + 1);
31
+ } else {
32
+ const name = a.slice(2);
33
+ const next = argv[i + 1];
34
+ if (!next || next.startsWith('--')) {
35
+ flags[name] = true;
36
+ } else {
37
+ flags[name] = next;
38
+ i++;
39
+ }
40
+ }
41
+ } else {
42
+ positional.push(a);
43
+ }
44
+ }
45
+ return { flags, positional };
46
+ }
47
+
48
+ function usage() {
49
+ return [
50
+ 'Usage: 60db-mcp-server [options]',
51
+ '',
52
+ 'Starts an MCP server exposing the 60db time-series database.',
53
+ '',
54
+ 'Options:',
55
+ ' --api-key <key> 60db API key (or SIXTYDB_API_KEY)',
56
+ ' --read-only disable ingest/create tools',
57
+ ' --dataset <name> restrict session to one dataset',
58
+ ' --transport stdio|http MCP transport (default stdio)',
59
+ ' --port <n> HTTP transport port (default 8787)',
60
+ ' --help, -h show this help',
61
+ ].join('\n');
62
+ }
63
+
64
+ /**
65
+ * Run the server. In stdio mode we keep the process alive and reply to
66
+ * incoming JSON-RPC lines; in HTTP mode we would bind a port. Both are
67
+ * stubbed here to a degree that is testable without a real MCP peer.
68
+ * @param {Object} opts
69
+ * @param {Object} opts.config Resolved server config.
70
+ * @param {Stream} [opts.stdin]
71
+ * @param {Stream} [opts.stdout]
72
+ * @returns {Promise<void>}
73
+ */
74
+ async function runServer({ config, stdin, stdout }) {
75
+ if (!config.apiKey) {
76
+ throw new SixtyDBError(
77
+ 'Missing 60db API key (set --api-key or SIXTYDB_API_KEY)',
78
+ 'NO_API_KEY'
79
+ );
80
+ }
81
+ const tools = listTools({ readOnly: config.readOnly });
82
+ if (stdout) {
83
+ stdout.write(
84
+ `60db-mcp-server: ${tools.length} tools, dataset=${config.dataset || '(default)'}, ` +
85
+ `transport=${config.transport}, readOnly=${config.readOnly}\n`
86
+ );
87
+ }
88
+ if (config.transport === 'http') {
89
+ // Bind is stubbed; real implementation would start an HTTP server here.
90
+ return;
91
+ }
92
+ // stdio mode: keep process alive for MCP peer to send requests.
93
+ return new Promise((resolve) => {
94
+ if (!stdin) resolve();
95
+ else stdin.on('end', resolve);
96
+ });
97
+ }
98
+
99
+ function main(argv) {
100
+ const { flags } = parseArgs(argv);
101
+ if (flags.help || flags.h) {
102
+ process.stdout.write(usage() + '\n');
103
+ return Promise.resolve(0);
104
+ }
105
+ const config = resolveConfig(flags);
106
+ assertToolAllowed('list-tables', config); // sanity check the config
107
+ return runServer({ config, stdin: process.stdin, stdout: process.stdout })
108
+ .then(() => 0)
109
+ .catch((err) => {
110
+ process.stderr.write(`${err.name}: ${err.message}\n`);
111
+ return 1;
112
+ });
113
+ }
114
+
115
+ if (require.main === module) {
116
+ main(process.argv.slice(2)).then((code) => process.exit(code));
117
+ }
118
+
119
+ module.exports = { parseArgs, runServer, usage, main };
package/index.js ADDED
@@ -0,0 +1,197 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * 60db-mcp-server
5
+ *
6
+ * Library core that exposes the 60db time-series database to MCP (Model
7
+ * Context Protocol) clients. The CLI (`cli.js`) wires this into an MCP
8
+ * transport; this module is responsible for tool definitions, request
9
+ * dispatch, and translation into authenticated 60db API requests.
10
+ */
11
+
12
+ /**
13
+ * Tools the MCP server exposes to clients. The `read-only` flag on the
14
+ * server config disables the write tools (`ingest`, `create-table`).
15
+ * @typedef {Object} ToolDef
16
+ * @property {string} name
17
+ * @property {string} description
18
+ * @property {Object} inputSchema JSON-Schema describing accepted args.
19
+ */
20
+
21
+ class SixtyDBError extends Error {
22
+ constructor(message, code) {
23
+ super(message);
24
+ this.name = 'SixtyDBError';
25
+ this.code = code || 'SIXTYDB_ERROR';
26
+ }
27
+ }
28
+
29
+ const READ_TOOLS = ['query', 'list-tables', 'describe-table'];
30
+ const WRITE_TOOLS = ['ingest', 'create-table'];
31
+ const ALL_TOOLS = [...READ_TOOLS, ...WRITE_TOOLS];
32
+
33
+ /**
34
+ * Build the list of MCP tools the server should advertise.
35
+ * @param {Object} [opts]
36
+ * @param {boolean} [opts.readOnly=false] Omit write tools when true.
37
+ * @param {string[]} [opts.allowedTables] Per-dataset allow-list.
38
+ * @returns {ToolDef[]}
39
+ */
40
+ function listTools(opts = {}) {
41
+ const { readOnly = false, allowedTables } = opts;
42
+ const tools = [
43
+ {
44
+ name: 'query',
45
+ description: 'Run a SQL query against 60db and return rows.',
46
+ inputSchema: {
47
+ type: 'object',
48
+ properties: {
49
+ sql: { type: 'string' },
50
+ limit: { type: 'number', default: 100 },
51
+ },
52
+ required: ['sql'],
53
+ },
54
+ },
55
+ {
56
+ name: 'list-tables',
57
+ description: 'List tables in the configured 60db dataset.',
58
+ inputSchema: { type: 'object', properties: {} },
59
+ },
60
+ {
61
+ name: 'describe-table',
62
+ description: 'Describe the schema of a single table.',
63
+ inputSchema: {
64
+ type: 'object',
65
+ properties: { table: { type: 'string' } },
66
+ required: ['table'],
67
+ },
68
+ },
69
+ {
70
+ name: 'ingest',
71
+ description: 'Ingest a batch of rows into a 60db table.',
72
+ inputSchema: {
73
+ type: 'object',
74
+ properties: {
75
+ table: { type: 'string' },
76
+ rows: { type: 'array', items: { type: 'object' } },
77
+ },
78
+ required: ['table', 'rows'],
79
+ },
80
+ },
81
+ {
82
+ name: 'create-table',
83
+ description: 'Create a new table in the 60db dataset.',
84
+ inputSchema: {
85
+ type: 'object',
86
+ properties: {
87
+ name: { type: 'string' },
88
+ columns: { type: 'array', items: { type: 'object' } },
89
+ },
90
+ required: ['name', 'columns'],
91
+ },
92
+ },
93
+ ];
94
+ return tools.filter((t) => {
95
+ if (readOnly && WRITE_TOOLS.includes(t.name)) return false;
96
+ return true;
97
+ });
98
+ }
99
+
100
+ /**
101
+ * Validate that a requested tool is allowed under the current server config.
102
+ * Throws SixtyDBError otherwise.
103
+ * @param {string} tool
104
+ * @param {Object} config Server config (readOnly, allowedTables).
105
+ */
106
+ function assertToolAllowed(tool, config = {}) {
107
+ if (!ALL_TOOLS.includes(tool)) {
108
+ throw new SixtyDBError(`Unknown tool: ${tool}`, 'UNKNOWN_TOOL');
109
+ }
110
+ if (config.readOnly && WRITE_TOOLS.includes(tool)) {
111
+ throw new SixtyDBError(
112
+ `Tool ${tool} is disabled in read-only mode`,
113
+ 'READ_ONLY'
114
+ );
115
+ }
116
+ if (
117
+ config.allowedTables &&
118
+ (tool === 'describe-table' || tool === 'ingest' || tool === 'create-table')
119
+ ) {
120
+ const table = config.allowedTables;
121
+ if (!table.includes(tool)) {
122
+ // allowedTables is a list of names; check the table arg at dispatch.
123
+ }
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Build the 60db REST URL for a given dataset + tool.
129
+ * @param {string} baseURL
130
+ * @param {string} dataset
131
+ * @param {string} tool
132
+ * @returns {string}
133
+ */
134
+ function buildApiUrl(baseURL, dataset, tool) {
135
+ const base = baseURL.replace(/\/$/, '');
136
+ return `${base}/v1/datasets/${encodeURIComponent(dataset)}/${tool.replace(/-/g, '_')}`;
137
+ }
138
+
139
+ /**
140
+ * Construct headers for an authenticated 60db request.
141
+ * @param {string} apiKey
142
+ * @returns {Object}
143
+ */
144
+ function authHeaders(apiKey) {
145
+ if (!apiKey) throw new SixtyDBError('Missing 60db API key', 'NO_API_KEY');
146
+ return {
147
+ Authorization: `Bearer ${apiKey}`,
148
+ 'Content-Type': 'application/json',
149
+ 'User-Agent': '60db-mcp-server/0.1.0',
150
+ };
151
+ }
152
+
153
+ /**
154
+ * Resolve server config from flags + environment, with precedence:
155
+ * explicit flags > env vars > defaults.
156
+ * @param {Object} flags
157
+ * @param {Object} env
158
+ * @returns {Object}
159
+ */
160
+ function resolveConfig(flags = {}, env = process.env) {
161
+ return {
162
+ apiKey: flags.apiKey || env.SIXTYDB_API_KEY || '',
163
+ readOnly: Boolean(flags.readOnly || env.SIXTYDB_READ_ONLY === '1'),
164
+ dataset: flags.dataset || env.SIXTYDB_DATASET || '',
165
+ transport: flags.transport || env.SIXTYDB_TRANSPORT || 'stdio',
166
+ port: Number(flags.port || env.SIXTYDB_PORT || 8787),
167
+ baseURL: flags.baseURL || env.SIXTYDB_BASE_URL || 'https://api.60db.io',
168
+ };
169
+ }
170
+
171
+ /**
172
+ * Split a large result set into chunks small enough to fit MCP message limits.
173
+ * @param {Array} rows
174
+ * @param {number} [chunkSize=200]
175
+ * @returns {Array<Array>}
176
+ */
177
+ function chunkRows(rows, chunkSize = 200) {
178
+ if (!Array.isArray(rows)) return [];
179
+ const out = [];
180
+ for (let i = 0; i < rows.length; i += chunkSize) {
181
+ out.push(rows.slice(i, i + chunkSize));
182
+ }
183
+ return out;
184
+ }
185
+
186
+ module.exports = {
187
+ SixtyDBError,
188
+ listTools,
189
+ assertToolAllowed,
190
+ buildApiUrl,
191
+ authHeaders,
192
+ resolveConfig,
193
+ chunkRows,
194
+ READ_TOOLS,
195
+ WRITE_TOOLS,
196
+ ALL_TOOLS,
197
+ };
package/package.json CHANGED
@@ -1,6 +1,16 @@
1
1
  {
2
2
  "name": "60db-mcp-server",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "MCP server that exposes the 60db time-series database to LLM clients.",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "60db-mcp-server": "cli.js"
8
+ },
9
+ "scripts": {
10
+ "test": "node test.js"
11
+ },
12
+ "keywords": [],
13
+ "author": "",
14
+ "license": "MIT",
15
+ "type": "commonjs"
16
+ }
package/test.js ADDED
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ const assert = require('node:assert');
4
+ const {
5
+ SixtyDBError,
6
+ listTools,
7
+ assertToolAllowed,
8
+ buildApiUrl,
9
+ authHeaders,
10
+ resolveConfig,
11
+ chunkRows,
12
+ } = require('./index');
13
+
14
+ assert.strictEqual(listTools().length, 5);
15
+ assert.strictEqual(listTools({ readOnly: true }).length, 3);
16
+ assert.ok(listTools({ readOnly: true }).every((t) => !['ingest', 'create-table'].includes(t.name)));
17
+
18
+ assert.throws(
19
+ () => assertToolAllowed('nope', {}),
20
+ /Unknown tool/
21
+ );
22
+ assert.throws(
23
+ () => assertToolAllowed('ingest', { readOnly: true }),
24
+ /read-only/
25
+ );
26
+ assert.doesNotThrow(() => assertToolAllowed('query', { readOnly: true }));
27
+
28
+ assert.strictEqual(
29
+ buildApiUrl('https://api.60db.io/', 'events', 'list-tables'),
30
+ 'https://api.60db.io/v1/datasets/events/list_tables'
31
+ );
32
+
33
+ assert.strictEqual(authHeaders('k').Authorization, 'Bearer k');
34
+ assert.throws(() => authHeaders(''), /Missing 60db API key/);
35
+
36
+ const cfg = resolveConfig(
37
+ { apiKey: 'k', dataset: 'ev', readOnly: true, port: '9000' },
38
+ { SIXTYDB_API_KEY: 'envk' }
39
+ );
40
+ assert.strictEqual(cfg.apiKey, 'k');
41
+ assert.strictEqual(cfg.dataset, 'ev');
42
+ assert.strictEqual(cfg.readOnly, true);
43
+ assert.strictEqual(cfg.port, 9000);
44
+ const envCfg = resolveConfig({}, { SIXTYDB_API_KEY: 'envk', SIXTYDB_READ_ONLY: '1' });
45
+ assert.strictEqual(envCfg.apiKey, 'envk');
46
+ assert.strictEqual(envCfg.readOnly, true);
47
+
48
+ assert.deepStrictEqual(chunkRows([1, 2, 3, 4, 5], 2), [[1, 2], [3, 4], [5]]);
49
+ assert.deepStrictEqual(chunkRows([], 2), []);
50
+ assert.ok(new SixtyDBError('x', 'C').code === 'C');
51
+
52
+ console.log('All tests passed.');