@spooky-sync/cli 0.0.1-canary.37 → 0.0.1-canary.370

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.
@@ -1,204 +0,0 @@
1
- import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- import { z } from 'zod';
3
- import { BRIDGE_METHODS } from './protocol.js';
4
- function json(data) {
5
- return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
6
- }
7
- export function createServer(bridge, surreal) {
8
- const server = new McpServer({
9
- name: 'sp00ky-devtools',
10
- version: '0.0.1',
11
- });
12
- // --- Tools ---
13
- server.tool('list_connections', 'List browser tabs connected to Sp00ky DevTools', {}, async () => {
14
- return json({ connected: bridge.isConnected, tabs: bridge.getConnectedTabs() });
15
- });
16
- server.tool('get_state', 'Get the full Sp00ky DevTools state (events, queries, auth, database)', { tabId: z.number().optional().describe('Browser tab ID (uses first connected tab if omitted)') }, async ({ tabId }) => {
17
- if (!bridge.isConnected) {
18
- throw new Error('No extension connected. get_state requires the Sp00ky DevTools browser extension.');
19
- }
20
- const result = await bridge.request(BRIDGE_METHODS.GET_STATE, {}, tabId);
21
- return json(result);
22
- });
23
- server.tool('run_query', 'Execute a SurrealQL query against the database', {
24
- query: z.string().describe('SurrealQL query to execute'),
25
- target: z.enum(['local', 'remote']).optional().default('remote').describe('Query target: local or remote database'),
26
- tabId: z.number().optional().describe('Browser tab ID'),
27
- }, async ({ query, target, tabId }) => {
28
- if (bridge.isConnected) {
29
- const result = await bridge.request(BRIDGE_METHODS.RUN_QUERY, { query, target }, tabId);
30
- return json(result);
31
- }
32
- if (surreal) {
33
- const result = await surreal.query(query);
34
- return json(result);
35
- }
36
- throw new Error('No extension connected and no direct database configured. Set SURREAL_URL or connect the browser extension.');
37
- });
38
- server.tool('list_tables', 'List all database tables', { tabId: z.number().optional().describe('Browser tab ID') }, async ({ tabId }) => {
39
- if (bridge.isConnected) {
40
- const state = (await bridge.request(BRIDGE_METHODS.GET_STATE, {}, tabId));
41
- const tables = state?.database?.tables ?? [];
42
- return json(tables);
43
- }
44
- if (surreal) {
45
- const result = await surreal.query('INFO FOR DB;');
46
- const info = result;
47
- const tables = info?.[0]?.result?.tables ?? info?.[0]?.tables ?? {};
48
- return json(Object.keys(tables));
49
- }
50
- throw new Error('No extension connected and no direct database configured.');
51
- });
52
- server.tool('get_table_data', 'Fetch records from a database table', {
53
- tableName: z.string().describe('Name of the table'),
54
- limit: z.number().optional().default(100).describe('Max number of records to return'),
55
- tabId: z.number().optional().describe('Browser tab ID'),
56
- }, async ({ tableName, limit, tabId }) => {
57
- if (bridge.isConnected) {
58
- const result = await bridge.request(BRIDGE_METHODS.GET_TABLE_DATA, { tableName }, tabId);
59
- return json(result);
60
- }
61
- if (surreal) {
62
- const result = await surreal.query(`SELECT * FROM \`${tableName}\` LIMIT ${limit};`);
63
- return json(result);
64
- }
65
- throw new Error('No extension connected and no direct database configured.');
66
- });
67
- server.tool('update_table_row', 'Update a record in a database table', {
68
- tableName: z.string().optional().describe('Name of the table (used when browser extension is connected)'),
69
- recordId: z.string().describe('Record ID to update (e.g. "users:abc123")'),
70
- updates: z.record(z.unknown()).describe('Fields to update'),
71
- tabId: z.number().optional().describe('Browser tab ID'),
72
- }, async ({ tableName, recordId, updates, tabId }) => {
73
- if (bridge.isConnected) {
74
- const result = await bridge.request(BRIDGE_METHODS.UPDATE_TABLE_ROW, { tableName, recordId, updates }, tabId);
75
- return json(result);
76
- }
77
- if (surreal) {
78
- const result = await surreal.query(`UPDATE ${recordId} MERGE ${JSON.stringify(updates)};`);
79
- return json(result);
80
- }
81
- throw new Error('No extension connected and no direct database configured.');
82
- });
83
- server.tool('delete_table_row', 'Delete a record from a database table', {
84
- tableName: z.string().optional().describe('Name of the table (used when browser extension is connected)'),
85
- recordId: z.string().describe('Record ID to delete (e.g. "users:abc123")'),
86
- tabId: z.number().optional().describe('Browser tab ID'),
87
- }, async ({ tableName, recordId, tabId }) => {
88
- if (bridge.isConnected) {
89
- const result = await bridge.request(BRIDGE_METHODS.DELETE_TABLE_ROW, { tableName, recordId }, tabId);
90
- return json(result);
91
- }
92
- if (surreal) {
93
- const result = await surreal.query(`DELETE ${recordId};`);
94
- return json(result);
95
- }
96
- throw new Error('No extension connected and no direct database configured.');
97
- });
98
- server.tool('get_active_queries', 'Get all active live queries and their data', { tabId: z.number().optional().describe('Browser tab ID') }, async ({ tabId }) => {
99
- if (bridge.isConnected) {
100
- const state = (await bridge.request(BRIDGE_METHODS.GET_STATE, {}, tabId));
101
- return json(state?.activeQueries ?? []);
102
- }
103
- if (surreal) {
104
- const result = await surreal.query('SELECT * FROM _00_query;');
105
- return json(result);
106
- }
107
- throw new Error('No extension connected and no direct database configured.');
108
- });
109
- server.tool('get_events', 'Get event history, optionally filtered by type', {
110
- eventType: z.string().optional().describe('Filter by event type'),
111
- limit: z.number().optional().default(50).describe('Max number of events to return'),
112
- tabId: z.number().optional().describe('Browser tab ID'),
113
- }, async ({ eventType, limit, tabId }) => {
114
- if (bridge.isConnected) {
115
- const state = (await bridge.request(BRIDGE_METHODS.GET_STATE, {}, tabId));
116
- let events = state?.eventsHistory ?? [];
117
- if (eventType) {
118
- events = events.filter((e) => e.eventType === eventType);
119
- }
120
- if (limit) {
121
- events = events.slice(-limit);
122
- }
123
- return json(events);
124
- }
125
- if (surreal) {
126
- const result = await surreal.query(`SELECT * FROM _00_events ORDER BY timestamp DESC LIMIT ${limit};`);
127
- return json(result);
128
- }
129
- throw new Error('No extension connected and no direct database configured.');
130
- });
131
- server.tool('get_auth_state', 'Get the current authentication state', { tabId: z.number().optional().describe('Browser tab ID') }, async ({ tabId }) => {
132
- if (!bridge.isConnected) {
133
- throw new Error('No extension connected. get_auth_state requires the Sp00ky DevTools browser extension.');
134
- }
135
- const state = (await bridge.request(BRIDGE_METHODS.GET_STATE, {}, tabId));
136
- return json(state?.auth ?? null);
137
- });
138
- server.tool('clear_history', 'Clear the event history', { tabId: z.number().optional().describe('Browser tab ID') }, async ({ tabId }) => {
139
- if (!bridge.isConnected) {
140
- throw new Error('No extension connected. clear_history requires the Sp00ky DevTools browser extension.');
141
- }
142
- await bridge.request(BRIDGE_METHODS.CLEAR_HISTORY, {}, tabId);
143
- return { content: [{ type: 'text', text: 'History cleared.' }] };
144
- });
145
- // --- Resources ---
146
- server.resource('state', 'sp00ky://state', { description: 'Full Sp00ky DevTools state' }, async (uri) => {
147
- if (!bridge.isConnected) {
148
- throw new Error('No extension connected. State resource requires the browser extension.');
149
- }
150
- const state = await bridge.request(BRIDGE_METHODS.GET_STATE);
151
- return { contents: [{ uri: uri.href, mimeType: 'application/json', text: JSON.stringify(state, null, 2) }] };
152
- });
153
- server.resource('tables', 'sp00ky://tables', { description: 'List of database tables' }, async (uri) => {
154
- if (bridge.isConnected) {
155
- const state = (await bridge.request(BRIDGE_METHODS.GET_STATE));
156
- const tables = state?.database?.tables ?? [];
157
- return { contents: [{ uri: uri.href, mimeType: 'application/json', text: JSON.stringify(tables, null, 2) }] };
158
- }
159
- if (surreal) {
160
- const result = await surreal.query('INFO FOR DB;');
161
- const info = result;
162
- const tables = info?.[0]?.result?.tables ?? info?.[0]?.tables ?? {};
163
- return { contents: [{ uri: uri.href, mimeType: 'application/json', text: JSON.stringify(Object.keys(tables), null, 2) }] };
164
- }
165
- throw new Error('No extension connected and no direct database configured.');
166
- });
167
- server.resource('table-data', new ResourceTemplate('sp00ky://tables/{tableName}', { list: undefined }), { description: 'Contents of a specific database table' }, async (uri, variables) => {
168
- const tableName = variables.tableName;
169
- if (bridge.isConnected) {
170
- const result = await bridge.request(BRIDGE_METHODS.GET_TABLE_DATA, { tableName });
171
- return { contents: [{ uri: uri.href, mimeType: 'application/json', text: JSON.stringify(result, null, 2) }] };
172
- }
173
- if (surreal) {
174
- const result = await surreal.query(`SELECT * FROM \`${tableName}\` LIMIT 100;`);
175
- return { contents: [{ uri: uri.href, mimeType: 'application/json', text: JSON.stringify(result, null, 2) }] };
176
- }
177
- throw new Error('No extension connected and no direct database configured.');
178
- });
179
- server.resource('queries', 'sp00ky://queries', { description: 'Active live queries' }, async (uri) => {
180
- if (bridge.isConnected) {
181
- const state = (await bridge.request(BRIDGE_METHODS.GET_STATE));
182
- const queries = state?.activeQueries ?? [];
183
- return { contents: [{ uri: uri.href, mimeType: 'application/json', text: JSON.stringify(queries, null, 2) }] };
184
- }
185
- if (surreal) {
186
- const result = await surreal.query('SELECT * FROM _00_query;');
187
- return { contents: [{ uri: uri.href, mimeType: 'application/json', text: JSON.stringify(result, null, 2) }] };
188
- }
189
- throw new Error('No extension connected and no direct database configured.');
190
- });
191
- server.resource('events', 'sp00ky://events', { description: 'Event history' }, async (uri) => {
192
- if (bridge.isConnected) {
193
- const state = (await bridge.request(BRIDGE_METHODS.GET_STATE));
194
- const events = state?.eventsHistory ?? [];
195
- return { contents: [{ uri: uri.href, mimeType: 'application/json', text: JSON.stringify(events, null, 2) }] };
196
- }
197
- if (surreal) {
198
- const result = await surreal.query('SELECT * FROM _00_events ORDER BY timestamp DESC LIMIT 50;');
199
- return { contents: [{ uri: uri.href, mimeType: 'application/json', text: JSON.stringify(result, null, 2) }] };
200
- }
201
- throw new Error('No extension connected and no direct database configured.');
202
- });
203
- return server;
204
- }
@@ -1,13 +0,0 @@
1
- export interface SurrealConfig {
2
- url: string;
3
- namespace: string;
4
- database: string;
5
- username: string;
6
- password: string;
7
- }
8
- export declare class SurrealClient {
9
- private config;
10
- private authHeader;
11
- constructor(config: SurrealConfig);
12
- query(surql: string): Promise<unknown[]>;
13
- }
@@ -1,27 +0,0 @@
1
- export class SurrealClient {
2
- config;
3
- authHeader;
4
- constructor(config) {
5
- this.config = config;
6
- this.authHeader =
7
- 'Basic ' + Buffer.from(`${config.username}:${config.password}`).toString('base64');
8
- }
9
- async query(surql) {
10
- const res = await fetch(`${this.config.url}/sql`, {
11
- method: 'POST',
12
- headers: {
13
- 'Content-Type': 'application/json',
14
- Authorization: this.authHeader,
15
- 'surreal-ns': this.config.namespace,
16
- 'surreal-db': this.config.database,
17
- Accept: 'application/json',
18
- },
19
- body: surql,
20
- });
21
- if (!res.ok) {
22
- const text = await res.text();
23
- throw new Error(`SurrealDB query failed (${res.status}): ${text}`);
24
- }
25
- return res.json();
26
- }
27
- }
@@ -1,51 +0,0 @@
1
- import { platform as s, arch as l } from "os";
2
- import { dirname as y, resolve as a } from "path";
3
- import { existsSync as e } from "fs";
4
- import { fileURLToPath as k } from "url";
5
- import { createRequire as d } from "module";
6
- const x = k(import.meta.url), m = y(x), f = {
7
- "darwin-arm64": "@spooky-sync/cli-darwin-arm64",
8
- "darwin-x64": "@spooky-sync/cli-darwin-x64",
9
- "linux-arm64": "@spooky-sync/cli-linux-arm64",
10
- "linux-x64": "@spooky-sync/cli-linux-x64",
11
- "win32-x64": "@spooky-sync/cli-win32-x64"
12
- };
13
- function w() {
14
- const r = `${s()}-${l()}`, o = f[r];
15
- if (!o) return;
16
- const n = s() === "win32" ? "spooky.exe" : "spooky";
17
- try {
18
- const t = d(import.meta.url).resolve(`${o}/package.json`);
19
- return a(y(t), n);
20
- } catch {
21
- return;
22
- }
23
- }
24
- function _() {
25
- const r = s() === "win32" ? "spooky.exe" : "spooky", o = w();
26
- if (o && e(o))
27
- return o;
28
- const n = a(m, "../target/release", r);
29
- if (e(n))
30
- return n;
31
- const i = a(m, "..", r);
32
- if (e(i))
33
- return i;
34
- const t = a(process.cwd(), r);
35
- if (e(t))
36
- return t;
37
- const p = `${s()}-${l()}`, c = f[p], u = c ? `
38
- Try installing the platform package: npm install ${c}` : `
39
- Your platform (${p}) is not supported.`;
40
- throw new Error(
41
- `Could not find spooky binary. Checked paths:
42
- - Platform package (${c ?? "none"})
43
- - ${n}
44
- - ${i}
45
- - ${t}
46
- ` + u
47
- );
48
- }
49
- export {
50
- _ as f
51
- };
@@ -1,8 +0,0 @@
1
- "use strict";const n=require("os"),r=require("path"),c=require("fs"),d=require("url"),m=require("module");var o=typeof document<"u"?document.currentScript:null;const h=d.fileURLToPath(typeof document>"u"?require("url").pathToFileURL(__filename).href:o&&o.tagName.toUpperCase()==="SCRIPT"&&o.src||new URL("resolve-binary-CFmJcXEj.cjs",document.baseURI).href),p=r.dirname(h),y={"darwin-arm64":"@spooky-sync/cli-darwin-arm64","darwin-x64":"@spooky-sync/cli-darwin-x64","linux-arm64":"@spooky-sync/cli-linux-arm64","linux-x64":"@spooky-sync/cli-linux-x64","win32-x64":"@spooky-sync/cli-win32-x64"};function k(){const t=`${n.platform()}-${n.arch()}`,e=y[t];if(!e)return;const s=n.platform()==="win32"?"spooky.exe":"spooky";try{const i=m.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:o&&o.tagName.toUpperCase()==="SCRIPT"&&o.src||new URL("resolve-binary-CFmJcXEj.cjs",document.baseURI).href).resolve(`${e}/package.json`);return r.resolve(r.dirname(i),s)}catch{return}}function x(){const t=n.platform()==="win32"?"spooky.exe":"spooky",e=k();if(e&&c.existsSync(e))return e;const s=r.resolve(p,"../target/release",t);if(c.existsSync(s))return s;const a=r.resolve(p,"..",t);if(c.existsSync(a))return a;const i=r.resolve(process.cwd(),t);if(c.existsSync(i))return i;const u=`${n.platform()}-${n.arch()}`,l=y[u],f=l?`
2
- Try installing the platform package: npm install ${l}`:`
3
- Your platform (${u}) is not supported.`;throw new Error(`Could not find spooky binary. Checked paths:
4
- - Platform package (${l??"none"})
5
- - ${s}
6
- - ${a}
7
- - ${i}
8
- `+f)}exports.findBinary=x;