Skip to content

Commit 76bbe51

Browse files
committed
fix: remove system schemas from table list
1 parent 8bbf0dd commit 76bbe51

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

packages/mcp-server-supabase/src/pg-meta/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import columnsSql from './columns.sql';
33
import extensionsSql from './extensions.sql';
44
import tablesSql from './tables.sql';
55

6+
export const DEFAULT_SYSTEM_SCHEMAS = [
7+
'information_schema',
8+
'pg_catalog',
9+
'pg_toast',
10+
];
11+
612
/**
713
* Generates the SQL query to list tables in the database.
814
*/
@@ -19,6 +25,8 @@ export function listTablesSql(schemas: string[] = []) {
1925

2026
if (schemas.length > 0) {
2127
sql += ` where schema in (${schemas.map((s) => `'${s}'`).join(',')})`;
28+
} else {
29+
sql += ` where schema not in (${DEFAULT_SYSTEM_SCHEMAS.map((s) => `'${s}'`).join(',')})`;
2230
}
2331

2432
return sql;

packages/mcp-server-supabase/src/server.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,46 @@ describe('tools', () => {
705705
);
706706
});
707707

708+
test('listing all tables excludes system schemas', async () => {
709+
const { callTool } = await setup();
710+
711+
const org = await createOrganization({
712+
name: 'My Org',
713+
plan: 'free',
714+
allowed_release_channels: ['ga'],
715+
});
716+
717+
const project = await createProject({
718+
name: 'Project 1',
719+
region: 'us-east-1',
720+
organization_id: org.id,
721+
});
722+
project.status = 'ACTIVE_HEALTHY';
723+
724+
const result = await callTool({
725+
name: 'list_tables',
726+
arguments: {
727+
project_id: project.id,
728+
},
729+
});
730+
731+
expect(result).not.toEqual(
732+
expect.arrayContaining([
733+
expect.objectContaining({ schema: 'pg_catalog' }),
734+
])
735+
);
736+
737+
expect(result).not.toEqual(
738+
expect.arrayContaining([
739+
expect.objectContaining({ schema: 'information_schema' }),
740+
])
741+
);
742+
743+
expect(result).not.toEqual(
744+
expect.arrayContaining([expect.objectContaining({ schema: 'pg_toast' })])
745+
);
746+
});
747+
708748
test('list extensions', async () => {
709749
const { callTool } = await setup();
710750

0 commit comments

Comments
 (0)