@nicnocquee/dataqueue 1.32.0 → 1.34.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.
@@ -0,0 +1,175 @@
1
+ #!/usr/bin/env node
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
+ import { z } from 'zod';
5
+ import fs from 'fs';
6
+ import path from 'path';
7
+ import { fileURLToPath } from 'url';
8
+
9
+ var __filename = fileURLToPath(import.meta.url);
10
+ var __dirname = path.dirname(__filename);
11
+ function loadDocsContent(docsPath = path.join(__dirname, "../ai/docs-content.json")) {
12
+ const raw = fs.readFileSync(docsPath, "utf-8");
13
+ return JSON.parse(raw);
14
+ }
15
+ function scorePageForQuery(page, queryTerms) {
16
+ const titleLower = page.title.toLowerCase();
17
+ const descLower = page.description.toLowerCase();
18
+ const contentLower = page.content.toLowerCase();
19
+ let score = 0;
20
+ for (const term of queryTerms) {
21
+ if (titleLower.includes(term)) score += 10;
22
+ if (descLower.includes(term)) score += 5;
23
+ const contentMatches = contentLower.split(term).length - 1;
24
+ score += Math.min(contentMatches, 10);
25
+ }
26
+ return score;
27
+ }
28
+ function extractExcerpt(content, queryTerms, maxLength = 500) {
29
+ const lower = content.toLowerCase();
30
+ let earliestIndex = -1;
31
+ for (const term of queryTerms) {
32
+ const idx = lower.indexOf(term);
33
+ if (idx !== -1 && (earliestIndex === -1 || idx < earliestIndex)) {
34
+ earliestIndex = idx;
35
+ }
36
+ }
37
+ if (earliestIndex === -1) {
38
+ return content.slice(0, maxLength);
39
+ }
40
+ const start = Math.max(0, earliestIndex - 100);
41
+ const end = Math.min(content.length, start + maxLength);
42
+ let excerpt = content.slice(start, end);
43
+ if (start > 0) excerpt = "..." + excerpt;
44
+ if (end < content.length) excerpt = excerpt + "...";
45
+ return excerpt;
46
+ }
47
+ async function startMcpServer(deps = {}) {
48
+ const pages = loadDocsContent(deps.docsPath);
49
+ const server = new McpServer({
50
+ name: "dataqueue-docs",
51
+ version: "1.0.0"
52
+ });
53
+ server.resource("llms-txt", "dataqueue://llms.txt", async () => {
54
+ const llmsPath = path.join(
55
+ __dirname,
56
+ "../ai/skills/dataqueue-core/SKILL.md"
57
+ );
58
+ let content;
59
+ try {
60
+ content = fs.readFileSync(llmsPath, "utf-8");
61
+ } catch {
62
+ content = pages.map((p) => `## ${p.title}
63
+
64
+ Slug: ${p.slug}
65
+
66
+ ${p.description}`).join("\n\n");
67
+ }
68
+ return { contents: [{ uri: "dataqueue://llms.txt", text: content }] };
69
+ });
70
+ server.tool(
71
+ "list-doc-pages",
72
+ "List all available DataQueue documentation pages with titles and descriptions.",
73
+ {},
74
+ async () => {
75
+ const listing = pages.map((p) => ({
76
+ slug: p.slug,
77
+ title: p.title,
78
+ description: p.description
79
+ }));
80
+ return {
81
+ content: [
82
+ { type: "text", text: JSON.stringify(listing, null, 2) }
83
+ ]
84
+ };
85
+ }
86
+ );
87
+ server.tool(
88
+ "get-doc-page",
89
+ "Fetch a specific DataQueue doc page by slug. Returns full page content as markdown.",
90
+ {
91
+ slug: z.string().describe('The doc page slug, e.g. "usage/add-job" or "api/job-queue"')
92
+ },
93
+ async ({ slug }) => {
94
+ const page = pages.find((p) => p.slug === slug);
95
+ if (!page) {
96
+ return {
97
+ content: [
98
+ {
99
+ type: "text",
100
+ text: `Page not found: "${slug}". Use list-doc-pages to see available slugs.`
101
+ }
102
+ ],
103
+ isError: true
104
+ };
105
+ }
106
+ const header = page.description ? `# ${page.title}
107
+
108
+ > ${page.description}
109
+
110
+ ` : `# ${page.title}
111
+
112
+ `;
113
+ return {
114
+ content: [{ type: "text", text: header + page.content }]
115
+ };
116
+ }
117
+ );
118
+ server.tool(
119
+ "search-docs",
120
+ "Full-text search across all DataQueue documentation pages. Returns matching sections with page titles and content excerpts.",
121
+ {
122
+ query: z.string().describe('Search query, e.g. "cron scheduling" or "waitForToken"')
123
+ },
124
+ async ({ query }) => {
125
+ const queryTerms = query.toLowerCase().split(/\s+/).filter((t) => t.length > 1);
126
+ if (queryTerms.length === 0) {
127
+ return {
128
+ content: [
129
+ { type: "text", text: "Please provide a search query." }
130
+ ],
131
+ isError: true
132
+ };
133
+ }
134
+ const scored = pages.map((page) => ({
135
+ page,
136
+ score: scorePageForQuery(page, queryTerms)
137
+ })).filter((r) => r.score > 0).sort((a, b) => b.score - a.score).slice(0, 5);
138
+ if (scored.length === 0) {
139
+ return {
140
+ content: [
141
+ {
142
+ type: "text",
143
+ text: `No results for "${query}". Try different keywords or use list-doc-pages to browse.`
144
+ }
145
+ ]
146
+ };
147
+ }
148
+ const results = scored.map((r) => {
149
+ const excerpt = extractExcerpt(r.page.content, queryTerms);
150
+ return `## ${r.page.title} (${r.page.slug})
151
+
152
+ ${r.page.description}
153
+
154
+ ${excerpt}`;
155
+ });
156
+ return {
157
+ content: [{ type: "text", text: results.join("\n\n---\n\n") }]
158
+ };
159
+ }
160
+ );
161
+ const transport = deps.transport ?? new StdioServerTransport();
162
+ await server.connect(transport);
163
+ return server;
164
+ }
165
+ var isDirectRun = process.argv[1] && (process.argv[1].endsWith("/mcp-server.js") || process.argv[1].endsWith("/mcp-server.cjs"));
166
+ if (isDirectRun) {
167
+ startMcpServer().catch((err) => {
168
+ console.error("Failed to start MCP server:", err);
169
+ process.exit(1);
170
+ });
171
+ }
172
+
173
+ export { extractExcerpt, loadDocsContent, scorePageForQuery, startMcpServer };
174
+ //# sourceMappingURL=mcp-server.js.map
175
+ //# sourceMappingURL=mcp-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/mcp-server.ts"],"names":[],"mappings":";;;;;;;;AAcA,IAAM,UAAA,GAAa,aAAA,CAAc,MAAA,CAAA,IAAA,CAAY,GAAG,CAAA;AAChD,IAAM,SAAA,GAAY,IAAA,CAAK,OAAA,CAAQ,UAAU,CAAA;AAUlC,SAAS,gBACd,QAAA,GAAmB,IAAA,CAAK,IAAA,CAAK,SA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cp-server.js","sourcesContent":["#!/usr/bin/env node\n\n/**\n * DataQueue MCP Server — exposes documentation search over stdio.\n * Run via: dataqueue-cli mcp\n */\n\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\nimport { z } from 'zod';\nimport fs from 'fs';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\ninterface DocPage {\n slug: string;\n title: string;\n description: string;\n content: string;\n}\n\n/** @internal Loads docs-content.json from the ai/ directory bundled with the package. */\nexport function loadDocsContent(\n docsPath: string = path.join(__dirname, '../ai/docs-content.json'),\n): DocPage[] {\n const raw = fs.readFileSync(docsPath, 'utf-8');\n return JSON.parse(raw) as DocPage[];\n}\n\n/** @internal Scores a doc page against a search query using simple term matching. */\nexport function scorePageForQuery(page: DocPage, queryTerms: string[]): number {\n const titleLower = page.title.toLowerCase();\n const descLower = page.description.toLowerCase();\n const contentLower = page.content.toLowerCase();\n\n let score = 0;\n for (const term of queryTerms) {\n if (titleLower.includes(term)) score += 10;\n if (descLower.includes(term)) score += 5;\n\n const contentMatches = contentLower.split(term).length - 1;\n score += Math.min(contentMatches, 10);\n }\n return score;\n}\n\n/** @internal Extracts a relevant excerpt around the first match of any query term. */\nexport function extractExcerpt(\n content: string,\n queryTerms: string[],\n maxLength = 500,\n): string {\n const lower = content.toLowerCase();\n let earliestIndex = -1;\n\n for (const term of queryTerms) {\n const idx = lower.indexOf(term);\n if (idx !== -1 && (earliestIndex === -1 || idx < earliestIndex)) {\n earliestIndex = idx;\n }\n }\n\n if (earliestIndex === -1) {\n return content.slice(0, maxLength);\n }\n\n const start = Math.max(0, earliestIndex - 100);\n const end = Math.min(content.length, start + maxLength);\n let excerpt = content.slice(start, end);\n\n if (start > 0) excerpt = '...' + excerpt;\n if (end < content.length) excerpt = excerpt + '...';\n\n return excerpt;\n}\n\n/**\n * Creates and starts the DataQueue MCP server over stdio.\n *\n * @param deps - Injectable dependencies for testing.\n */\nexport async function startMcpServer(\n deps: {\n docsPath?: string;\n transport?: InstanceType<typeof StdioServerTransport>;\n } = {},\n): Promise<McpServer> {\n const pages = loadDocsContent(deps.docsPath);\n\n const server = new McpServer({\n name: 'dataqueue-docs',\n version: '1.0.0',\n });\n\n server.resource('llms-txt', 'dataqueue://llms.txt', async () => {\n const llmsPath = path.join(\n __dirname,\n '../ai/skills/dataqueue-core/SKILL.md',\n );\n let content: string;\n try {\n content = fs.readFileSync(llmsPath, 'utf-8');\n } catch {\n content = pages\n .map((p) => `## ${p.title}\\n\\nSlug: ${p.slug}\\n\\n${p.description}`)\n .join('\\n\\n');\n }\n return { contents: [{ uri: 'dataqueue://llms.txt', text: content }] };\n });\n\n server.tool(\n 'list-doc-pages',\n 'List all available DataQueue documentation pages with titles and descriptions.',\n {},\n async () => {\n const listing = pages.map((p) => ({\n slug: p.slug,\n title: p.title,\n description: p.description,\n }));\n return {\n content: [\n { type: 'text' as const, text: JSON.stringify(listing, null, 2) },\n ],\n };\n },\n );\n\n server.tool(\n 'get-doc-page',\n 'Fetch a specific DataQueue doc page by slug. Returns full page content as markdown.',\n {\n slug: z\n .string()\n .describe('The doc page slug, e.g. \"usage/add-job\" or \"api/job-queue\"'),\n },\n async ({ slug }) => {\n const page = pages.find((p) => p.slug === slug);\n if (!page) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `Page not found: \"${slug}\". Use list-doc-pages to see available slugs.`,\n },\n ],\n isError: true,\n };\n }\n const header = page.description\n ? `# ${page.title}\\n\\n> ${page.description}\\n\\n`\n : `# ${page.title}\\n\\n`;\n return {\n content: [{ type: 'text' as const, text: header + page.content }],\n };\n },\n );\n\n server.tool(\n 'search-docs',\n 'Full-text search across all DataQueue documentation pages. Returns matching sections with page titles and content excerpts.',\n {\n query: z\n .string()\n .describe('Search query, e.g. \"cron scheduling\" or \"waitForToken\"'),\n },\n async ({ query }) => {\n const queryTerms = query\n .toLowerCase()\n .split(/\\s+/)\n .filter((t) => t.length > 1);\n\n if (queryTerms.length === 0) {\n return {\n content: [\n { type: 'text' as const, text: 'Please provide a search query.' },\n ],\n isError: true,\n };\n }\n\n const scored = pages\n .map((page) => ({\n page,\n score: scorePageForQuery(page, queryTerms),\n }))\n .filter((r) => r.score > 0)\n .sort((a, b) => b.score - a.score)\n .slice(0, 5);\n\n if (scored.length === 0) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `No results for \"${query}\". Try different keywords or use list-doc-pages to browse.`,\n },\n ],\n };\n }\n\n const results = scored.map((r) => {\n const excerpt = extractExcerpt(r.page.content, queryTerms);\n return `## ${r.page.title} (${r.page.slug})\\n\\n${r.page.description}\\n\\n${excerpt}`;\n });\n\n return {\n content: [{ type: 'text' as const, text: results.join('\\n\\n---\\n\\n') }],\n };\n },\n );\n\n const transport = deps.transport ?? new StdioServerTransport();\n await server.connect(transport);\n return server;\n}\n\nconst isDirectRun =\n process.argv[1] &&\n (process.argv[1].endsWith('/mcp-server.js') ||\n process.argv[1].endsWith('/mcp-server.cjs'));\n\nif (isDirectRun) {\n startMcpServer().catch((err) => {\n console.error('Failed to start MCP server:', err);\n process.exit(1);\n });\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nicnocquee/dataqueue",
3
- "version": "1.32.0",
3
+ "version": "1.34.0",
4
4
  "description": "PostgreSQL or Redis-backed job queue for Node.js applications with support for serverless environments",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -14,9 +14,11 @@
14
14
  "files": [
15
15
  "dist/",
16
16
  "src/",
17
- "migrations/"
17
+ "migrations/",
18
+ "ai/"
18
19
  ],
19
20
  "scripts": {
21
+ "prebuild": "npx tsx ai/build-docs-content.ts && npx tsx ai/build-llms-full.ts",
20
22
  "build": "tsup",
21
23
  "ci": "npm run build && npm run check-format && npm run check-exports && npm run lint && npm run test",
22
24
  "lint": "tsc",
@@ -24,6 +26,7 @@
24
26
  "format": "prettier --write .",
25
27
  "check-format": "prettier --check .",
26
28
  "check-exports": "attw --pack .",
29
+ "build:docs-content": "npx tsx ai/build-docs-content.ts && npx tsx ai/build-llms-full.ts",
27
30
  "dev": "tsup --watch",
28
31
  "migrate": "node-pg-migrate -d $PG_DATAQUEUE_DATABASE -m ./migrations"
29
32
  },
@@ -43,9 +46,11 @@
43
46
  "directory": "packages/dataqueue"
44
47
  },
45
48
  "dependencies": {
49
+ "@modelcontextprotocol/sdk": "^1.26.0",
46
50
  "croner": "^10.0.1",
47
51
  "pg": "^8.0.0",
48
- "pg-connection-string": "^2.9.1"
52
+ "pg-connection-string": "^2.9.1",
53
+ "zod": "^3.25.67"
49
54
  },
50
55
  "devDependencies": {
51
56
  "@arethetypeswrong/cli": "^0.18.2",
@@ -76,6 +81,7 @@
76
81
  }
77
82
  },
78
83
  "bin": {
79
- "dataqueue-cli": "./cli.cjs"
84
+ "dataqueue-cli": "./cli.cjs",
85
+ "dataqueue-mcp": "./dist/mcp-server.js"
80
86
  }
81
87
  }
package/src/cli.test.ts CHANGED
@@ -22,6 +22,11 @@ function makeDeps() {
22
22
  exit: vi.fn(),
23
23
  spawnSyncImpl: vi.fn(() => makeSpawnSyncReturns(0)),
24
24
  migrationsDir: '/migrations',
25
+ runInitImpl: vi.fn(),
26
+ runInstallSkillsImpl: vi.fn(),
27
+ runInstallRulesImpl: vi.fn(async () => {}),
28
+ runInstallMcpImpl: vi.fn(async () => {}),
29
+ startMcpServerImpl: vi.fn(async () => ({}) as any),
25
30
  } satisfies CliDeps;
26
31
  }
27
32
 
@@ -34,20 +39,30 @@ describe('runCli', () => {
34
39
 
35
40
  it('prints usage and exits with code 1 for no command', () => {
36
41
  runCli(['node', 'cli.js'], deps);
37
- expect(deps.log).toHaveBeenCalledWith(
38
- 'Usage: dataqueue-cli migrate [--envPath <path>] [-s <schema> | --schema <schema>]',
39
- );
42
+ expect(deps.log).toHaveBeenCalledWith('Usage:');
43
+ expect(deps.log).toHaveBeenCalledWith(' dataqueue-cli init');
40
44
  expect(deps.exit).toHaveBeenCalledWith(1);
41
45
  });
42
46
 
43
47
  it('prints usage and exits with code 1 for unknown command', () => {
44
48
  runCli(['node', 'cli.js', 'unknown'], deps);
45
- expect(deps.log).toHaveBeenCalledWith(
46
- 'Usage: dataqueue-cli migrate [--envPath <path>] [-s <schema> | --schema <schema>]',
47
- );
49
+ expect(deps.log).toHaveBeenCalledWith('Usage:');
50
+ expect(deps.log).toHaveBeenCalledWith(' dataqueue-cli init');
48
51
  expect(deps.exit).toHaveBeenCalledWith(1);
49
52
  });
50
53
 
54
+ it('routes init command to runInitImpl', () => {
55
+ runCli(['node', 'cli.js', 'init'], deps);
56
+ expect(deps.runInitImpl).toHaveBeenCalledWith(
57
+ expect.objectContaining({
58
+ log: deps.log,
59
+ error: deps.error,
60
+ exit: deps.exit,
61
+ }),
62
+ );
63
+ expect(deps.spawnSyncImpl).not.toHaveBeenCalled();
64
+ });
65
+
51
66
  it('calls spawnSyncImpl with correct args for migrate', () => {
52
67
  runCli(['node', 'cli.js', 'migrate'], deps);
53
68
  expect(deps.spawnSyncImpl).toHaveBeenCalledWith(
@@ -127,4 +142,65 @@ describe('runCli', () => {
127
142
  runCli(['node', 'cli.js', 'migrate'], deps);
128
143
  expect(deps.exit).toHaveBeenCalledWith(1);
129
144
  });
145
+
146
+ it('routes install-skills command to runInstallSkillsImpl', () => {
147
+ // Act
148
+ runCli(['node', 'cli.js', 'install-skills'], deps);
149
+
150
+ // Assert
151
+ expect(deps.runInstallSkillsImpl).toHaveBeenCalledWith(
152
+ expect.objectContaining({
153
+ log: deps.log,
154
+ error: deps.error,
155
+ exit: deps.exit,
156
+ }),
157
+ );
158
+ });
159
+
160
+ it('routes install-rules command to runInstallRulesImpl', () => {
161
+ // Act
162
+ runCli(['node', 'cli.js', 'install-rules'], deps);
163
+
164
+ // Assert
165
+ expect(deps.runInstallRulesImpl).toHaveBeenCalledWith(
166
+ expect.objectContaining({
167
+ log: deps.log,
168
+ error: deps.error,
169
+ exit: deps.exit,
170
+ }),
171
+ );
172
+ });
173
+
174
+ it('routes install-mcp command to runInstallMcpImpl', () => {
175
+ // Act
176
+ runCli(['node', 'cli.js', 'install-mcp'], deps);
177
+
178
+ // Assert
179
+ expect(deps.runInstallMcpImpl).toHaveBeenCalledWith(
180
+ expect.objectContaining({
181
+ log: deps.log,
182
+ error: deps.error,
183
+ exit: deps.exit,
184
+ }),
185
+ );
186
+ });
187
+
188
+ it('routes mcp command to startMcpServerImpl', () => {
189
+ // Act
190
+ runCli(['node', 'cli.js', 'mcp'], deps);
191
+
192
+ // Assert
193
+ expect(deps.startMcpServerImpl).toHaveBeenCalled();
194
+ });
195
+
196
+ it('shows new commands in usage output', () => {
197
+ // Act
198
+ runCli(['node', 'cli.js'], deps);
199
+
200
+ // Assert
201
+ expect(deps.log).toHaveBeenCalledWith(' dataqueue-cli install-skills');
202
+ expect(deps.log).toHaveBeenCalledWith(' dataqueue-cli install-rules');
203
+ expect(deps.log).toHaveBeenCalledWith(' dataqueue-cli install-mcp');
204
+ expect(deps.log).toHaveBeenCalledWith(' dataqueue-cli mcp');
205
+ });
130
206
  });
package/src/cli.ts CHANGED
@@ -2,6 +2,14 @@
2
2
  import { spawnSync, SpawnSyncReturns } from 'child_process';
3
3
  import path from 'path';
4
4
  import { fileURLToPath } from 'url';
5
+ import { InitDeps, runInit } from './init-command.js';
6
+ import {
7
+ runInstallSkills,
8
+ InstallSkillsDeps,
9
+ } from './install-skills-command.js';
10
+ import { runInstallRules, InstallRulesDeps } from './install-rules-command.js';
11
+ import { runInstallMcp, InstallMcpDeps } from './install-mcp-command.js';
12
+ import { startMcpServer } from './mcp-server.js';
5
13
 
6
14
  const __filename = fileURLToPath(import.meta.url);
7
15
  const __dirname = path.dirname(__filename);
@@ -12,25 +20,50 @@ export interface CliDeps {
12
20
  exit?: (code: number) => void;
13
21
  spawnSyncImpl?: (...args: any[]) => SpawnSyncReturns<any>;
14
22
  migrationsDir?: string;
23
+ initDeps?: InitDeps;
24
+ runInitImpl?: (deps?: InitDeps) => void;
25
+ installSkillsDeps?: InstallSkillsDeps;
26
+ runInstallSkillsImpl?: (deps?: InstallSkillsDeps) => void;
27
+ installRulesDeps?: InstallRulesDeps;
28
+ runInstallRulesImpl?: (deps?: InstallRulesDeps) => Promise<void>;
29
+ installMcpDeps?: InstallMcpDeps;
30
+ runInstallMcpImpl?: (deps?: InstallMcpDeps) => Promise<void>;
31
+ startMcpServerImpl?: typeof startMcpServer;
15
32
  }
16
33
 
17
34
  export function runCli(
18
35
  argv: string[],
19
36
  {
20
37
  log = console.log,
38
+ error = console.error,
21
39
  exit = (code: number) => process.exit(code),
22
40
  spawnSyncImpl = spawnSync,
23
41
  migrationsDir = path.join(__dirname, '../migrations'),
42
+ initDeps,
43
+ runInitImpl = runInit,
44
+ installSkillsDeps,
45
+ runInstallSkillsImpl = runInstallSkills,
46
+ installRulesDeps,
47
+ runInstallRulesImpl = runInstallRules,
48
+ installMcpDeps,
49
+ runInstallMcpImpl = runInstallMcp,
50
+ startMcpServerImpl = startMcpServer,
24
51
  }: CliDeps = {},
25
52
  ): void {
26
53
  const [, , command, ...restArgs] = argv;
27
54
 
28
55
  function printUsage() {
56
+ log('Usage:');
29
57
  log(
30
- 'Usage: dataqueue-cli migrate [--envPath <path>] [-s <schema> | --schema <schema>]',
58
+ ' dataqueue-cli migrate [--envPath <path>] [-s <schema> | --schema <schema>]',
31
59
  );
60
+ log(' dataqueue-cli init');
61
+ log(' dataqueue-cli install-skills');
62
+ log(' dataqueue-cli install-rules');
63
+ log(' dataqueue-cli install-mcp');
64
+ log(' dataqueue-cli mcp');
32
65
  log('');
33
- log('Options:');
66
+ log('Options for migrate:');
34
67
  log(
35
68
  ' --envPath <path> Path to a .env file to load environment variables (passed to node-pg-migrate)',
36
69
  );
@@ -38,16 +71,13 @@ export function runCli(
38
71
  ' -s, --schema <schema> Set the schema to use (passed to node-pg-migrate)',
39
72
  );
40
73
  log('');
41
- log('Notes:');
74
+ log('AI tooling commands:');
75
+ log(' install-skills Install DataQueue skill files for AI assistants');
76
+ log(' install-rules Install DataQueue agent rules for AI clients');
42
77
  log(
43
- ' - The PG_DATAQUEUE_DATABASE environment variable must be set to your Postgres connection string.',
44
- );
45
- log(
46
- ' - For managed Postgres (e.g., DigitalOcean) with SSL, set PGSSLMODE=require and PGSSLROOTCERT to your CA .crt file.',
47
- );
48
- log(
49
- ' Example: PGSSLMODE=require NODE_EXTRA_CA_CERTS=/absolute/path/to/ca.crt PG_DATAQUEUE_DATABASE=... npx dataqueue-cli migrate',
78
+ ' install-mcp Configure the DataQueue MCP server for AI clients',
50
79
  );
80
+ log(' mcp Start the DataQueue MCP server (stdio)');
51
81
  exit(1);
52
82
  }
53
83
 
@@ -89,6 +119,39 @@ export function runCli(
89
119
  { stdio: 'inherit' },
90
120
  );
91
121
  exit(result.status ?? 1);
122
+ } else if (command === 'init') {
123
+ runInitImpl({
124
+ log,
125
+ error,
126
+ exit,
127
+ ...initDeps,
128
+ });
129
+ } else if (command === 'install-skills') {
130
+ runInstallSkillsImpl({
131
+ log,
132
+ error,
133
+ exit,
134
+ ...installSkillsDeps,
135
+ });
136
+ } else if (command === 'install-rules') {
137
+ runInstallRulesImpl({
138
+ log,
139
+ error,
140
+ exit,
141
+ ...installRulesDeps,
142
+ });
143
+ } else if (command === 'install-mcp') {
144
+ runInstallMcpImpl({
145
+ log,
146
+ error,
147
+ exit,
148
+ ...installMcpDeps,
149
+ });
150
+ } else if (command === 'mcp') {
151
+ startMcpServerImpl().catch((err) => {
152
+ error('Failed to start MCP server:', err);
153
+ exit(1);
154
+ });
92
155
  } else {
93
156
  printUsage();
94
157
  }