Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/mcp-server-supabase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
},
"devDependencies": {
"@ai-sdk/anthropic": "catalog:",
"hono": "^4.7.10",
"@ai-sdk/mcp": "catalog:",
"@electric-sql/pglite": "^0.2.17",
"@modelcontextprotocol/sdk": "catalog:",
Expand Down
4 changes: 3 additions & 1 deletion packages/mcp-server-supabase/src/management-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ import type { paths } from './types.js';
export function createManagementApiClient(
baseUrl: string,
accessToken: string,
headers: Record<string, string> = {}
headers: Record<string, string> = {},
fetch?: (request: Request) => Response | Promise<Response>
) {
return createClient<paths>({
baseUrl,
headers: {
Authorization: `Bearer ${accessToken}`,
...headers,
},
fetch: fetch ? (request) => Promise.resolve(fetch(request)) : undefined,
});
}

Expand Down
35 changes: 35 additions & 0 deletions packages/mcp-server-supabase/src/platform/api-platform.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Hono } from 'hono';
import { describe, expect, test } from 'vitest';
import { createSupabaseApiPlatform } from './api-platform.js';

describe('createSupabaseApiPlatform with custom fetch', () => {
test('routes management API calls through custom fetch handler', async () => {
const projects = [
{
id: 'proj1',
ref: 'proj1',
name: 'Test Project',
organization_id: 'org1',
organization_slug: 'org1',
status: 'ACTIVE_HEALTHY',
created_at: new Date().toISOString(),
region: 'us-east-1',
},
];

const app = new Hono().get('/v1/projects', (c) => c.json(projects));

const platform = createSupabaseApiPlatform({
accessToken: 'test-token',
fetch: app.fetch.bind(app),
});

if (!platform.account) {
throw new Error('account should be defined on the API platform');
}

const result = await platform.account.listProjects();
expect(result).toHaveLength(1);
expect(result[0]?.name).toBe('Test Project');
});
});
15 changes: 12 additions & 3 deletions packages/mcp-server-supabase/src/platform/api-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ export type SupabaseApiPlatformOptions = {
* The API URL for the Supabase Management API.
*/
apiUrl?: string;

/**
* Custom fetch implementation. Useful for in-process transports (e.g. a
* Hono app's `app.fetch`) so callers can avoid binding a real TCP port.
*/
fetch?: (request: Request) => Response | Promise<Response>;
};

/**
Expand All @@ -65,13 +71,15 @@ export type SupabaseApiPlatformOptions = {
export function createSupabaseApiPlatform(
options: SupabaseApiPlatformOptions
): SupabasePlatform {
const { accessToken, apiUrl } = options;
const { accessToken, apiUrl, fetch } = options;

const managementApiUrl = apiUrl ?? 'https://api.supabase.com';

let managementApiClient = createManagementApiClient(
managementApiUrl,
accessToken
accessToken,
{},
fetch
);

const account: AccountOperations = {
Expand Down Expand Up @@ -788,7 +796,8 @@ export function createSupabaseApiPlatform(
accessToken,
{
'User-Agent': `supabase-mcp/${version} (${clientInfo.name}/${clientInfo.version})`,
}
},
fetch
);
},
account,
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading