1
1
import { createMcpServer , type Tool } from '@supabase/mcp-utils' ;
2
+ import { z } from 'zod' ;
2
3
import packageJson from '../package.json' with { type : 'json' } ;
3
4
import { createContentApiClient } from './content-api/index.js' ;
4
5
import type { SupabasePlatform } from './platform/types.js' ;
6
+ import { getAccountTools } from './tools/account-tools.js' ;
5
7
import { getBranchingTools } from './tools/branching-tools.js' ;
6
8
import { getDatabaseOperationTools } from './tools/database-operation-tools.js' ;
7
9
import { getDebuggingTools } from './tools/debugging-tools.js' ;
8
10
import { getDevelopmentTools } from './tools/development-tools.js' ;
9
11
import { getDocsTools } from './tools/docs-tools.js' ;
10
12
import { getEdgeFunctionTools } from './tools/edge-function-tools.js' ;
11
- import { getAccountTools } from './tools/account-tools.js' ;
12
13
import { getStorageTools } from './tools/storage-tools.js' ;
13
14
14
15
const { version } = packageJson ;
@@ -53,42 +54,28 @@ export type SupabaseMcpServerOptions = {
53
54
* Features to enable.
54
55
* Options: 'account', 'branching', 'database', 'debug', 'development', 'docs', 'functions', 'storage'
55
56
*/
56
- features ?: string [ ] ;
57
+ features ?: FeatureGroup [ ] ;
57
58
} ;
58
59
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' ,
71
62
'account' ,
72
- 'branching' ,
73
63
'database' ,
74
64
'debug' ,
75
65
'development' ,
76
- 'docs' ,
77
66
'functions' ,
67
+ 'branching' ,
78
68
'storage' ,
79
- ] as const ;
69
+ ] ) ;
80
70
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 [ ] = [
85
74
'docs' ,
86
- 'functions' ,
87
- ] ;
88
- const DEFAULT_PROJECT_FEATURES : FeatureGroup [ ] = [
75
+ 'account' ,
89
76
'database' ,
90
77
'debug' ,
91
- 'docs ' ,
78
+ 'development ' ,
92
79
'functions' ,
93
80
] ;
94
81
@@ -106,22 +93,9 @@ export function createSupabaseMcpServer(options: SupabaseMcpServerOptions) {
106
93
107
94
const contentApiClientPromise = createContentApiClient ( contentApiUrl ) ;
108
95
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 ) ) ;
125
99
126
100
const server = createMcpServer ( {
127
101
name : 'supabase' ,
@@ -136,7 +110,7 @@ export function createSupabaseMcpServer(options: SupabaseMcpServerOptions) {
136
110
const tools : Record < string , Tool > = { } ;
137
111
138
112
// Add feature-based tools
139
- if ( enabledFeatures . has ( 'account' ) && ! projectId ) {
113
+ if ( ! projectId && enabledFeatures . has ( 'account' ) ) {
140
114
Object . assign ( tools , getAccountTools ( { platform } ) ) ;
141
115
}
142
116
0 commit comments