Skip to content

Commit c492a40

Browse files
committed
add tools based on features
1 parent d9a2db9 commit c492a40

File tree

2 files changed

+76
-13
lines changed

2 files changed

+76
-13
lines changed

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

Lines changed: 69 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,31 @@ export type SupabaseMcpServerOptions = {
4848
* Executes database queries in read-only mode if true.
4949
*/
5050
readOnly?: boolean;
51+
52+
/**
53+
* Features to enable.
54+
* Options: 'account', 'branching', 'database', 'debug', 'development', 'docs', 'functions', 'storage'
55+
*/
56+
features?: string[];
5157
};
5258

59+
export type FeatureGroup = 'account' | 'branching' | 'database' | 'debug' | 'development' | 'docs' | 'functions' | 'storage';
60+
61+
// Single source of truth for valid feature values
62+
export const VALID_FEATURES: readonly FeatureGroup[] = [
63+
'account',
64+
'branching',
65+
'database',
66+
'debug',
67+
'development',
68+
'docs',
69+
'functions',
70+
'storage'
71+
] as const;
72+
73+
const DEFAULT_ACCOUNT_FEATURES: FeatureGroup[] = ['account', 'database', 'debug', 'docs', 'functions'];
74+
const DEFAULT_PROJECT_FEATURES: FeatureGroup[] = ['database', 'debug', 'docs', 'functions'];
75+
5376
/**
5477
* Creates an MCP server for interacting with Supabase.
5578
*/
@@ -58,11 +81,27 @@ export function createSupabaseMcpServer(options: SupabaseMcpServerOptions) {
5881
platform,
5982
projectId,
6083
readOnly,
84+
features,
6185
contentApiUrl = 'https://supabase.com/docs/api/graphql',
6286
} = options;
6387

6488
const contentApiClientPromise = createContentApiClient(contentApiUrl);
6589

90+
const enabledFeatures = new Set<FeatureGroup>();
91+
92+
if (features && features.length > 0) {
93+
// Use explicitly provided features
94+
features.forEach(feature => {
95+
if (VALID_FEATURES.includes(feature as FeatureGroup)) {
96+
enabledFeatures.add(feature as FeatureGroup);
97+
}
98+
});
99+
} else {
100+
// Use defaults based on mode
101+
const defaultFeatures = projectId ? DEFAULT_PROJECT_FEATURES : DEFAULT_ACCOUNT_FEATURES;
102+
defaultFeatures.forEach(feature => enabledFeatures.add(feature));
103+
}
104+
66105
const server = createMcpServer({
67106
name: 'supabase',
68107
version,
@@ -75,21 +114,38 @@ export function createSupabaseMcpServer(options: SupabaseMcpServerOptions) {
75114
const contentApiClient = await contentApiClientPromise;
76115
const tools: Record<string, Tool> = {};
77116

78-
// Add account-level tools only if projectId is not provided
79-
if (!projectId) {
80-
Object.assign(tools, getProjectManagementTools({ platform }));
117+
// Add feature-based tools
118+
if (enabledFeatures.has('account') && !projectId) {
119+
Object.assign(tools, getAccountTools({ platform }));
120+
}
121+
122+
if (enabledFeatures.has('branching')) {
123+
Object.assign(tools, getBranchingTools({ platform, projectId }));
81124
}
82125

83-
// Add project-level tools
84-
Object.assign(
85-
tools,
86-
getDatabaseOperationTools({ platform, projectId, readOnly }),
87-
getEdgeFunctionTools({ platform, projectId }),
88-
getDebuggingTools({ platform, projectId }),
89-
getDevelopmentTools({ platform, projectId }),
90-
getBranchingTools({ platform, projectId }),
91-
getDocsTools({ contentApiClient })
92-
);
126+
if (enabledFeatures.has('database')) {
127+
Object.assign(tools, getDatabaseOperationTools({ platform, projectId, readOnly }));
128+
}
129+
130+
if (enabledFeatures.has('debug')) {
131+
Object.assign(tools, getDebuggingTools({ platform, projectId }));
132+
}
133+
134+
if (enabledFeatures.has('development')) {
135+
Object.assign(tools, getDevelopmentTools({ platform, projectId }));
136+
}
137+
138+
if (enabledFeatures.has('docs')) {
139+
Object.assign(tools, getDocsTools({ contentApiClient }));
140+
}
141+
142+
if (enabledFeatures.has('functions')) {
143+
Object.assign(tools, getEdgeFunctionTools({ platform, projectId }));
144+
}
145+
146+
if (enabledFeatures.has('storage')) {
147+
Object.assign(tools, getStorageTools({ platform, projectId }));
148+
}
93149

94150
return tools;
95151
},

packages/mcp-server-supabase/src/transports/stdio.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ async function main() {
1616
['read-only']: readOnly,
1717
['api-url']: apiUrl,
1818
['version']: showVersion,
19+
['features']: features,
1920
},
2021
} = parseArgs({
2122
options: {
@@ -35,6 +36,9 @@ async function main() {
3536
['version']: {
3637
type: 'boolean',
3738
},
39+
['features']: {
40+
type: 'string',
41+
},
3842
},
3943
});
4044

@@ -46,6 +50,8 @@ async function main() {
4650
// Use access token from CLI argument or environment variable
4751
const accessToken = cliAccessToken ?? process.env.SUPABASE_ACCESS_TOKEN;
4852

53+
const featureList = features?.split(',') ?? [];
54+
4955
if (!accessToken) {
5056
console.error(
5157
'Please provide a personal access token (PAT) with the --access-token flag or set the SUPABASE_ACCESS_TOKEN environment variable'
@@ -62,6 +68,7 @@ async function main() {
6268
platform,
6369
projectId,
6470
readOnly,
71+
features: featureList,
6572
});
6673

6774
const transport = new StdioServerTransport();

0 commit comments

Comments
 (0)