@daylight-labs/sharedb-mcp 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.
@@ -0,0 +1,175 @@
1
+ export interface Database {
2
+ id: string;
3
+ name: string;
4
+ display_name: string;
5
+ environment: string;
6
+ created_at: string;
7
+ }
8
+ export interface SchemaChange {
9
+ id: string;
10
+ database_id: string;
11
+ migration_id: string | null;
12
+ change_type: string;
13
+ table_name: string;
14
+ column_name: string | null;
15
+ ddl: string;
16
+ reverse_ddl: string | null;
17
+ is_reversible: boolean;
18
+ change_order: number;
19
+ created_at: string;
20
+ }
21
+ export interface Migration {
22
+ id: string;
23
+ database_id: string;
24
+ version: number;
25
+ description: string;
26
+ status: string;
27
+ applied_at: string;
28
+ rolled_back_at: string | null;
29
+ }
30
+ export interface ColumnInfo {
31
+ column_name: string;
32
+ data_type: string;
33
+ is_nullable: boolean;
34
+ column_default: string | null;
35
+ }
36
+ export interface TableSchema {
37
+ table_name: string;
38
+ columns: ColumnInfo[];
39
+ indexes: Array<{
40
+ index_name: string;
41
+ column_name: string;
42
+ is_unique: boolean;
43
+ is_primary: boolean;
44
+ }>;
45
+ constraints: Array<{
46
+ constraint_name: string;
47
+ constraint_type: string;
48
+ column_name: string | null;
49
+ foreign_table_name: string | null;
50
+ foreign_column_name: string | null;
51
+ }>;
52
+ rls_enabled: boolean;
53
+ rls_policies: Array<{
54
+ policy_name: string;
55
+ command: string;
56
+ using_expression: string | null;
57
+ with_check_expression: string | null;
58
+ roles: string[];
59
+ }>;
60
+ }
61
+ export interface DatabaseSchema {
62
+ database: string;
63
+ tables: TableSchema[];
64
+ functions: Array<{
65
+ function_name: string;
66
+ return_type: string;
67
+ arguments: string;
68
+ }>;
69
+ message?: string;
70
+ }
71
+ export interface PostgRESTInfo {
72
+ postgrestUrl: string | null;
73
+ status: string;
74
+ port?: number;
75
+ containerName?: string;
76
+ startedAt?: string;
77
+ }
78
+ export declare const api: {
79
+ databases: {
80
+ list: () => Promise<{
81
+ databases: Database[];
82
+ }>;
83
+ get: (id: string) => Promise<{
84
+ database: Database;
85
+ }>;
86
+ create: (data: {
87
+ name: string;
88
+ displayName: string;
89
+ environment: string;
90
+ }) => Promise<{
91
+ database: Database;
92
+ }>;
93
+ schema: (id: string) => Promise<DatabaseSchema>;
94
+ tableDetails: (dbId: string, table: string) => Promise<TableSchema>;
95
+ rlsPolicies: (id: string) => Promise<{
96
+ policies: Array<{
97
+ table_name: string;
98
+ policy_name: string;
99
+ command: string;
100
+ using_expression: string | null;
101
+ with_check_expression: string | null;
102
+ roles: string[];
103
+ }>;
104
+ }>;
105
+ functions: (id: string) => Promise<{
106
+ functions: Array<{
107
+ function_name: string;
108
+ return_type: string;
109
+ arguments: string;
110
+ definition: string;
111
+ }>;
112
+ }>;
113
+ postgrest: (id: string) => Promise<PostgRESTInfo>;
114
+ startPostgrest: (id: string) => Promise<PostgRESTInfo & {
115
+ message: string;
116
+ }>;
117
+ restartPostgrest: (id: string) => Promise<PostgRESTInfo & {
118
+ message: string;
119
+ }>;
120
+ };
121
+ changes: {
122
+ list: (dbId: string) => Promise<{
123
+ changes: SchemaChange[];
124
+ }>;
125
+ stage: (dbId: string, operation: string, params: Record<string, unknown>) => Promise<{
126
+ staged: SchemaChange[];
127
+ }>;
128
+ preview: (dbId: string) => Promise<{
129
+ preview: {
130
+ database: string;
131
+ changeCount: number;
132
+ hasIrreversibleChanges: boolean;
133
+ summary: Array<{
134
+ type: string;
135
+ table: string;
136
+ column: string | null;
137
+ reversible: boolean;
138
+ }>;
139
+ ddlStatements: string[];
140
+ } | null;
141
+ message?: string;
142
+ }>;
143
+ apply: (dbId: string, description?: string) => Promise<{
144
+ migration: Migration;
145
+ }>;
146
+ unstage: (dbId: string, changeId: string) => Promise<{
147
+ deleted: SchemaChange;
148
+ }>;
149
+ };
150
+ migrations: {
151
+ list: (dbId: string) => Promise<{
152
+ migrations: Migration[];
153
+ }>;
154
+ get: (dbId: string, migrationId: string) => Promise<{
155
+ migration: Migration & {
156
+ changes: SchemaChange[];
157
+ };
158
+ }>;
159
+ rollback: (dbId: string, migrationId: string) => Promise<{
160
+ rolledBack: {
161
+ migrationId: string;
162
+ version: number;
163
+ changesReverted: number;
164
+ };
165
+ }>;
166
+ };
167
+ auth: {
168
+ config: () => Promise<{
169
+ endpoints: Record<string, string>;
170
+ jwtStructure: Record<string, string>;
171
+ sessionVariable: string;
172
+ helperFunction: string;
173
+ }>;
174
+ };
175
+ };
@@ -0,0 +1,65 @@
1
+ import { config } from './config.js';
2
+ async function request(path, options) {
3
+ const response = await fetch(`${config.adminApiUrl}${path}`, {
4
+ ...options,
5
+ headers: {
6
+ 'Content-Type': 'application/json',
7
+ Authorization: `Bearer ${config.token}`,
8
+ ...options?.headers,
9
+ },
10
+ });
11
+ if (!response.ok) {
12
+ const error = await response.json().catch(() => ({ error: 'Request failed' }));
13
+ throw new Error(error.error || `Request failed: ${response.status}`);
14
+ }
15
+ return response.json();
16
+ }
17
+ export const api = {
18
+ databases: {
19
+ list: () => request('/admin/databases'),
20
+ get: (id) => request(`/admin/databases/${id}`),
21
+ create: (data) => request('/admin/databases', {
22
+ method: 'POST',
23
+ body: JSON.stringify(data),
24
+ }),
25
+ schema: (id) => request(`/admin/databases/${id}/schema`),
26
+ tableDetails: (dbId, table) => request(`/admin/databases/${dbId}/schema/tables/${table}`),
27
+ rlsPolicies: (id) => request(`/admin/databases/${id}/schema/rls-policies`),
28
+ functions: (id) => request(`/admin/databases/${id}/schema/functions`),
29
+ postgrest: (id) => request(`/admin/databases/${id}/postgrest`),
30
+ startPostgrest: (id) => request(`/admin/databases/${id}/postgrest/start`, {
31
+ method: 'POST',
32
+ body: JSON.stringify({}),
33
+ }),
34
+ restartPostgrest: (id) => request(`/admin/databases/${id}/postgrest/restart`, {
35
+ method: 'POST',
36
+ body: JSON.stringify({}),
37
+ }),
38
+ },
39
+ changes: {
40
+ list: (dbId) => request(`/admin/databases/${dbId}/changes`),
41
+ stage: (dbId, operation, params) => request(`/admin/databases/${dbId}/changes`, {
42
+ method: 'POST',
43
+ body: JSON.stringify({ operation, params }),
44
+ }),
45
+ preview: (dbId) => request(`/admin/databases/${dbId}/changes/preview`, {
46
+ method: 'POST',
47
+ body: JSON.stringify({}),
48
+ }),
49
+ apply: (dbId, description) => request(`/admin/databases/${dbId}/changes/apply`, {
50
+ method: 'POST',
51
+ body: JSON.stringify({ description }),
52
+ }),
53
+ unstage: (dbId, changeId) => request(`/admin/databases/${dbId}/changes/${changeId}`, {
54
+ method: 'DELETE',
55
+ }),
56
+ },
57
+ migrations: {
58
+ list: (dbId) => request(`/admin/databases/${dbId}/migrations`),
59
+ get: (dbId, migrationId) => request(`/admin/databases/${dbId}/migrations/${migrationId}`),
60
+ rollback: (dbId, migrationId) => request(`/admin/databases/${dbId}/migrations/${migrationId}/rollback`, { method: 'POST' }),
61
+ },
62
+ auth: {
63
+ config: () => request('/admin/auth/config'),
64
+ },
65
+ };
@@ -0,0 +1,5 @@
1
+ export declare const config: {
2
+ adminApiUrl: string;
3
+ authApiUrl: string;
4
+ token: string;
5
+ };
package/dist/config.js ADDED
@@ -0,0 +1,5 @@
1
+ export const config = {
2
+ adminApiUrl: process.env.SHAREDB_API_URL || 'http://localhost:3002',
3
+ authApiUrl: process.env.SHAREDB_AUTH_URL || 'http://localhost:3000',
4
+ token: process.env.SHAREDB_TOKEN || '',
5
+ };
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env node
2
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
3
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
+ import { CallToolRequestSchema, ListToolsRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
5
+ import { schemaTools, handleSchemaTool } from './tools/schema.js';
6
+ import { migrationTools, handleMigrationTool } from './tools/migrations.js';
7
+ import { authTools, handleAuthTool } from './tools/auth.js';
8
+ import { dataTools, handleDataTool } from './tools/data.js';
9
+ import { resources, readResource } from './resources/index.js';
10
+ const server = new Server({
11
+ name: 'sharedb',
12
+ version: '0.1.0',
13
+ }, {
14
+ capabilities: {
15
+ tools: {},
16
+ resources: {},
17
+ },
18
+ });
19
+ const allTools = [...schemaTools, ...migrationTools, ...authTools, ...dataTools];
20
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
21
+ return { tools: allTools };
22
+ });
23
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
24
+ const { name, arguments: args } = request.params;
25
+ const schemaTool = schemaTools.find((t) => t.name === name);
26
+ if (schemaTool) {
27
+ return handleSchemaTool(name, args || {});
28
+ }
29
+ const migrationTool = migrationTools.find((t) => t.name === name);
30
+ if (migrationTool) {
31
+ return handleMigrationTool(name, args || {});
32
+ }
33
+ const authTool = authTools.find((t) => t.name === name);
34
+ if (authTool) {
35
+ return handleAuthTool(name, args || {});
36
+ }
37
+ const dataTool = dataTools.find((t) => t.name === name);
38
+ if (dataTool) {
39
+ return handleDataTool(name, args || {});
40
+ }
41
+ return {
42
+ content: [{ type: 'text', text: `Unknown tool: ${name}` }],
43
+ isError: true,
44
+ };
45
+ });
46
+ server.setRequestHandler(ListResourcesRequestSchema, async () => {
47
+ return { resources };
48
+ });
49
+ server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
50
+ const { uri } = request.params;
51
+ return readResource(uri);
52
+ });
53
+ async function main() {
54
+ const transport = new StdioServerTransport();
55
+ await server.connect(transport);
56
+ console.error('ShareDB MCP server running on stdio');
57
+ }
58
+ main().catch((error) => {
59
+ console.error('Fatal error:', error);
60
+ process.exit(1);
61
+ });
@@ -0,0 +1,13 @@
1
+ export declare const resources: {
2
+ uri: string;
3
+ name: string;
4
+ description: string;
5
+ mimeType: string;
6
+ }[];
7
+ export declare function readResource(uri: string): {
8
+ contents: Array<{
9
+ uri: string;
10
+ mimeType: string;
11
+ text: string;
12
+ }>;
13
+ };