Skip to content

Commit 148cf7f

Browse files
committed
feat: use zod to validate feature groups
1 parent b756a1b commit 148cf7f

File tree

2 files changed

+18
-44
lines changed

2 files changed

+18
-44
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import type { InitData } from '@supabase/mcp-utils';
12
import { z } from 'zod';
23
import { AWS_REGION_CODES } from '../regions.js';
3-
import type { InitData } from '@supabase/mcp-utils';
44

55
export const v1StorageBucketResponseSchema = z.object({
66
id: z.string(),
@@ -169,7 +169,7 @@ export type SupabasePlatform = {
169169
options: ApplyMigrationOptions
170170
): Promise<void>;
171171

172-
// Project management
172+
// Account
173173
listOrganizations(): Promise<Pick<Organization, 'id' | 'name'>[]>;
174174
getOrganization(organizationId: string): Promise<Organization>;
175175
listProjects(): Promise<Project[]>;

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

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { createMcpServer, type Tool } from '@supabase/mcp-utils';
2+
import { z } from 'zod';
23
import packageJson from '../package.json' with { type: 'json' };
34
import { createContentApiClient } from './content-api/index.js';
45
import type { SupabasePlatform } from './platform/types.js';
6+
import { getAccountTools } from './tools/account-tools.js';
57
import { getBranchingTools } from './tools/branching-tools.js';
68
import { getDatabaseOperationTools } from './tools/database-operation-tools.js';
79
import { getDebuggingTools } from './tools/debugging-tools.js';
810
import { getDevelopmentTools } from './tools/development-tools.js';
911
import { getDocsTools } from './tools/docs-tools.js';
1012
import { getEdgeFunctionTools } from './tools/edge-function-tools.js';
11-
import { getAccountTools } from './tools/account-tools.js';
1213
import { getStorageTools } from './tools/storage-tools.js';
1314

1415
const { version } = packageJson;
@@ -53,42 +54,28 @@ export type SupabaseMcpServerOptions = {
5354
* Features to enable.
5455
* Options: 'account', 'branching', 'database', 'debug', 'development', 'docs', 'functions', 'storage'
5556
*/
56-
features?: string[];
57+
features?: FeatureGroup[];
5758
};
5859

59-
export type FeatureGroup =
60-
| 'account'
61-
| 'branching'
62-
| 'database'
63-
| 'debug'
64-
| 'development'
65-
| 'docs'
66-
| 'functions'
67-
| 'storage';
68-
69-
// Single source of truth for valid feature values
70-
export const VALID_FEATURES: readonly FeatureGroup[] = [
60+
const featureGroupSchema = z.enum([
61+
'docs',
7162
'account',
72-
'branching',
7363
'database',
7464
'debug',
7565
'development',
76-
'docs',
7766
'functions',
67+
'branching',
7868
'storage',
79-
] as const;
69+
]);
8070

81-
const DEFAULT_ACCOUNT_FEATURES: FeatureGroup[] = [
82-
'account',
83-
'database',
84-
'debug',
71+
export type FeatureGroup = z.infer<typeof featureGroupSchema>;
72+
73+
const DEFAULT_FEATURES: FeatureGroup[] = [
8574
'docs',
86-
'functions',
87-
];
88-
const DEFAULT_PROJECT_FEATURES: FeatureGroup[] = [
75+
'account',
8976
'database',
9077
'debug',
91-
'docs',
78+
'development',
9279
'functions',
9380
];
9481

@@ -106,22 +93,9 @@ export function createSupabaseMcpServer(options: SupabaseMcpServerOptions) {
10693

10794
const contentApiClientPromise = createContentApiClient(contentApiUrl);
10895

109-
const enabledFeatures = new Set<FeatureGroup>();
110-
111-
if (features && features.length > 0) {
112-
// Use explicitly provided features
113-
features.forEach((feature) => {
114-
if (VALID_FEATURES.includes(feature as FeatureGroup)) {
115-
enabledFeatures.add(feature as FeatureGroup);
116-
}
117-
});
118-
} else {
119-
// Use defaults based on mode
120-
const defaultFeatures = projectId
121-
? DEFAULT_PROJECT_FEATURES
122-
: DEFAULT_ACCOUNT_FEATURES;
123-
defaultFeatures.forEach((feature) => enabledFeatures.add(feature));
124-
}
96+
const enabledFeatures = z
97+
.set(featureGroupSchema)
98+
.parse(new Set(features ?? DEFAULT_FEATURES));
12599

126100
const server = createMcpServer({
127101
name: 'supabase',
@@ -136,7 +110,7 @@ export function createSupabaseMcpServer(options: SupabaseMcpServerOptions) {
136110
const tools: Record<string, Tool> = {};
137111

138112
// Add feature-based tools
139-
if (enabledFeatures.has('account') && !projectId) {
113+
if (!projectId && enabledFeatures.has('account')) {
140114
Object.assign(tools, getAccountTools({ platform }));
141115
}
142116

0 commit comments

Comments
 (0)