Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"[typescript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[json]": {
"editor.defaultFormatter": "biomejs.biome"
}
}
45 changes: 8 additions & 37 deletions packages/mcp-server-supabase/src/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,48 +808,20 @@ describe('tools', () => {

expect(listTablesResult).toEqual([
{
bytes: 8192,
schema: 'public',
name: 'test',
rls_enabled: false,
rows: 0,
columns: [
{
check: null,
comment: null,
name: 'id',
data_type: 'integer',
default_value: null,
enums: [],
format: 'int4',
id: expect.stringMatching(/^\d+\.\d+$/),
options: ['identity', 'updatable'],
identity_generation: 'ALWAYS',
is_generated: false,
is_identity: true,
is_nullable: false,
is_unique: false,
is_updatable: true,
name: 'id',
ordinal_position: 1,
schema: 'public',
table: 'test',
table_id: expect.any(Number),
},
],
comment: null,
dead_rows_estimate: 0,
id: expect.any(Number),
live_rows_estimate: 0,
name: 'test',
primary_keys: [
{
name: 'id',
schema: 'public',
table_id: expect.any(Number),
table_name: 'test',
},
],
relationships: [],
replica_identity: 'DEFAULT',
rls_enabled: false,
rls_forced: false,
schema: 'public',
size: '8192 bytes',
primary_keys: ['id'],
},
]);
});
Expand Down Expand Up @@ -2390,8 +2362,7 @@ describe('project scoped tools', () => {
columns: [
expect.objectContaining({
name: 'id',
is_identity: true,
is_generated: false,
options: expect.arrayContaining(['identity']),
}),
],
}),
Expand Down
102 changes: 101 additions & 1 deletion packages/mcp-server-supabase/src/tools/database-operation-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,107 @@ export function getDatabaseOperationTools({
query,
read_only: readOnly,
});
const tables = data.map((table) => postgresTableSchema.parse(table));
const tables = data
.map((table) => postgresTableSchema.parse(table))
.map(
// Reshape to reduce token bloat
({
// Discarded fields
id,
bytes,
size,
rls_forced,
live_rows_estimate,
dead_rows_estimate,
replica_identity,

// Modified fields
columns,
primary_keys,
relationships,
comment,

// Passthrough rest
...table
}) => {
const foreign_key_constraints = relationships?.map(
({
constraint_name,
source_schema,
source_table_name,
source_column_name,
target_table_schema,
target_table_name,
target_column_name,
}) => ({
name: constraint_name,
source: `${source_schema}.${source_table_name}.${source_column_name}`,
target: `${target_table_schema}.${target_table_name}.${target_column_name}`,
})
);

return {
...table,
rows: live_rows_estimate,
columns: columns?.map(
({
// Discarded fields
id,
table,
table_id,
schema,
ordinal_position,

// Modified fields
default_value,
is_identity,
identity_generation,
is_generated,
is_nullable,
is_updatable,
is_unique,
check,
comment,
enums,

// Passthrough rest
...column
}) => {
const options: string[] = [];
if (is_identity) options.push('identity');
if (is_generated) options.push('generated');
if (is_nullable) options.push('nullable');
if (is_updatable) options.push('updatable');
if (is_unique) options.push('unique');

return {
...column,
options,

// Omit fields when empty
...(default_value !== null && { default_value }),
...(identity_generation !== null && {
identity_generation,
}),
...(enums.length > 0 && { enums }),
...(check !== null && { check }),
...(comment !== null && { comment }),
};
}
),
primary_keys: primary_keys?.map(
({ table_id, schema, table_name, ...primary_key }) =>
primary_key.name
),

// Omit fields when empty
...(comment !== null && { comment }),
...(foreign_key_constraints.length > 0 && {
foreign_key_constraints,
}),
};
}
);
return tables;
},
}),
Expand Down