@@ -48,8 +48,31 @@ export type SupabaseMcpServerOptions = {
48
48
* Executes database queries in read-only mode if true.
49
49
*/
50
50
readOnly ?: boolean ;
51
+
52
+ /**
53
+ * Features to enable.
54
+ * Options: 'account', 'branching', 'database', 'debug', 'development', 'docs', 'functions', 'storage'
55
+ */
56
+ features ?: string [ ] ;
51
57
} ;
52
58
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
+
53
76
/**
54
77
* Creates an MCP server for interacting with Supabase.
55
78
*/
@@ -58,11 +81,27 @@ export function createSupabaseMcpServer(options: SupabaseMcpServerOptions) {
58
81
platform,
59
82
projectId,
60
83
readOnly,
84
+ features,
61
85
contentApiUrl = 'https://supabase.com/docs/api/graphql' ,
62
86
} = options ;
63
87
64
88
const contentApiClientPromise = createContentApiClient ( contentApiUrl ) ;
65
89
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
+
66
105
const server = createMcpServer ( {
67
106
name : 'supabase' ,
68
107
version,
@@ -75,21 +114,38 @@ export function createSupabaseMcpServer(options: SupabaseMcpServerOptions) {
75
114
const contentApiClient = await contentApiClientPromise ;
76
115
const tools : Record < string , Tool > = { } ;
77
116
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 } ) ) ;
81
124
}
82
125
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
+ }
93
149
94
150
return tools ;
95
151
} ,
0 commit comments