Skip to content

Commit 88b9e19

Browse files
committed
feat: storage tools
1 parent 9ae6e84 commit 88b9e19

File tree

4 files changed

+148
-1
lines changed

4 files changed

+148
-1
lines changed

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
type GetLogsOptions,
3131
type ResetBranchOptions,
3232
type SupabasePlatform,
33+
type StorageConfigUpdate,
3334
} from './index.js';
3435

3536
const { version } = packageJson;
@@ -600,6 +601,69 @@ export function createSupabaseApiPlatform(
600601

601602
assertSuccess(response, 'Failed to rebase branch');
602603
},
604+
605+
// Storage methods
606+
async listAllBuckets(project_id: string) {
607+
const response = await managementApiClient.GET(
608+
'/v1/projects/{ref}/storage/buckets',
609+
{
610+
params: {
611+
path: {
612+
ref: project_id,
613+
},
614+
},
615+
}
616+
);
617+
618+
assertSuccess(response, 'Failed to list storage buckets');
619+
620+
return response.data;
621+
},
622+
623+
async getStorageConfig(project_id: string) {
624+
const response = await managementApiClient.GET(
625+
'/v1/projects/{ref}/config/storage',
626+
{
627+
params: {
628+
path: {
629+
ref: project_id,
630+
},
631+
},
632+
}
633+
);
634+
635+
assertSuccess(response, 'Failed to get storage config');
636+
637+
return response.data;
638+
},
639+
640+
async updateStorageConfig(projectId: string, config: StorageConfigUpdate) {
641+
const response = await managementApiClient.PATCH(
642+
'/v1/projects/{ref}/config/storage',
643+
{
644+
params: {
645+
path: {
646+
ref: projectId,
647+
},
648+
},
649+
body: {
650+
fileSizeLimit: config.fileSizeLimit,
651+
features: {
652+
imageTransformation: {
653+
enabled: config.features.imageTransformation.enabled,
654+
},
655+
s3Protocol: {
656+
enabled: config.features.s3Protocol.enabled,
657+
},
658+
},
659+
},
660+
}
661+
);
662+
663+
assertSuccess(response, 'Failed to update storage config');
664+
665+
return response.data;
666+
},
603667
};
604668

605669
return platform;

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

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

5+
export const v1StorageBucketResponseSchema = z.object({
6+
id: z.string(),
7+
name: z.string(),
8+
owner: z.string(),
9+
created_at: z.string(),
10+
updated_at: z.string(),
11+
public: z.boolean(),
12+
});
13+
14+
export const storageConfigResponseSchema = z.object({
15+
fileSizeLimit: z.number(),
16+
features: z.object({
17+
imageTransformation: z.object({ enabled: z.boolean() }),
18+
s3Protocol: z.object({ enabled: z.boolean() }),
19+
}),
20+
});
21+
522
export const organizationSchema = z.object({
623
id: z.string(),
724
name: z.string(),
@@ -135,6 +152,10 @@ export type GenerateTypescriptTypesResult = z.infer<
135152
typeof generateTypescriptTypesResultSchema
136153
>;
137154

155+
export type StorageConfigResponse = z.infer<typeof storageConfigResponseSchema>;
156+
export type StorageConfigUpdate = z.infer<typeof storageConfigResponseSchema>;
157+
export type StorageBucketResponse = z.infer<typeof v1StorageBucketResponseSchema>;
158+
138159
export type SupabasePlatform = {
139160
init?(info: InitData): Promise<void>;
140161

@@ -186,4 +207,9 @@ export type SupabasePlatform = {
186207
mergeBranch(branchId: string): Promise<void>;
187208
resetBranch(branchId: string, options: ResetBranchOptions): Promise<void>;
188209
rebaseBranch(branchId: string): Promise<void>;
210+
211+
// Storage
212+
getStorageConfig(projectId: string): Promise<StorageConfigResponse>;
213+
updateStorageConfig(projectId: string, config: StorageConfigUpdate): Promise<void>;
214+
listAllBuckets(projectId: string): Promise<StorageBucketResponse[]>;
189215
};

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { getDebuggingTools } from './tools/debugging-tools.js';
77
import { getDevelopmentTools } from './tools/development-tools.js';
88
import { getEdgeFunctionTools } from './tools/edge-function-tools.js';
99
import { getProjectManagementTools } from './tools/project-management-tools.js';
10+
import { getStorageTools } from './tools/storage-tools.js';
1011

1112
const { version } = packageJson;
1213

@@ -57,7 +58,8 @@ export function createSupabaseMcpServer(options: SupabaseMcpServerOptions) {
5758
getEdgeFunctionTools({ platform, projectId }),
5859
getDebuggingTools({ platform, projectId }),
5960
getDevelopmentTools({ platform, projectId }),
60-
getBranchingTools({ platform, projectId })
61+
getBranchingTools({ platform, projectId }),
62+
getStorageTools({ platform, projectId })
6163
);
6264

6365
return tools;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { z } from 'zod';
2+
import type { SupabasePlatform } from '../platform/types.js';
3+
import { injectableTool } from './util.js';
4+
5+
export type StorageToolsOptions = {
6+
platform: SupabasePlatform;
7+
projectId?: string;
8+
};
9+
10+
export function getStorageTools({
11+
platform,
12+
projectId,
13+
}: StorageToolsOptions) {
14+
const project_id = projectId;
15+
16+
return {
17+
list_storage_buckets: injectableTool({
18+
description: 'Lists all storage buckets in a Supabase project.',
19+
parameters: z.object({
20+
project_id: z.string(),
21+
}),
22+
inject: { project_id },
23+
execute: async ({ project_id }) => {
24+
return await platform.listAllBuckets(project_id);
25+
},
26+
}),
27+
get_storage_config: injectableTool({
28+
description: 'Get the storage config for a Supabase project.',
29+
parameters: z.object({
30+
project_id: z.string(),
31+
}),
32+
inject: { project_id },
33+
execute: async ({ project_id }) => {
34+
return await platform.getStorageConfig(project_id);
35+
},
36+
}),
37+
update_storage_config: injectableTool({
38+
description: 'Update the storage config for a Supabase project.',
39+
parameters: z.object({
40+
project_id: z.string(),
41+
config: z.object({
42+
fileSizeLimit: z.number(),
43+
features: z.object({
44+
imageTransformation: z.object({ enabled: z.boolean() }),
45+
s3Protocol: z.object({ enabled: z.boolean() }),
46+
}),
47+
})
48+
}),
49+
inject: { project_id },
50+
execute: async ({ project_id, config }) => {
51+
return await platform.updateStorageConfig(project_id, config);
52+
},
53+
}),
54+
};
55+
}

0 commit comments

Comments
 (0)