Files
Barry Roodt 90a0bcdcfe feat(studio): bump @supabase/mcp-server-supabase to 0.20.0 and pass schemas to type generation (#54139)
## Problem

Self-hosted Studio still uses `@supabase/mcp-server-supabase` 0.17.0,
two releases behind even before
[0.20.0](https://github.com/supabase/mcp/releases/tag/mcp-server-supabase-v0.20.0).

## Solution

Bump `^0.17.0` to `^0.20.0` in `apps/studio/package.json` and update the
lockfile, which takes `@supabase/mcp-utils` from 0.10.0 to 0.11.1. The
platform interface only gained optional arguments, so the bump itself
compiles without changes.

- The debugging group gains `get_issues`, which covers security and
performance checks on self-hosted. It reports the health check as
unavailable because self-hosted has no health advisors.
- `generate_typescript_types` now accepts an optional `schemas`
parameter. Without this fix, self-hosted would silently ignore it and
could return types for different schemas than the caller requested.
`lib/api/self-hosted/mcp.ts` now passes `schemas` to
`generateTypescriptTypes` in `lib/api/self-hosted/generate-types.ts`,
which sends it to pg-meta as `included_schemas`. When the caller omits
`schemas`, self-hosted still uses the schemas PostgREST exposes. Tests
in `generate-types.test.ts` and `mcp.test.ts` cover both cases.

The MCP Apps support from 0.18.0 and 0.19.0 stays off because Studio
doesn’t opt in.

## Review instructions

1. Confirm CI passes.
2. With self-hosted Studio running, connect an MCP client to `/api/mcp`
and confirm `tools/list` includes `get_issues`.
3. Call `generate_typescript_types` with `schemas: ["auth"]` (or another
schema PostgREST doesn’t expose) and confirm it returns types only for
the requested schema.

Closes [AI-1582](https://linear.app/supabase/issue/AI-1582)
2026-11-27 15:09:38 +02:00

228 lines
6.8 KiB
TypeScript

import {
createFeedbackOperations,
type FeedbackOperationsOptions,
type SupabasePlatform,
} from '@supabase/mcp-server-supabase'
import {
ApiKey,
ApiKeyType,
ApplyMigrationOptions,
DatabaseOperations,
DebuggingOperations,
DevelopmentOperations,
ExecuteSqlOptions,
FeedbackOperations,
QueryLogsOptions,
} from '@supabase/mcp-server-supabase/platform'
import { isFeatureEnabled, type Feature } from 'common/enabled-features'
import { getEnabledFeaturesOverrideDisabledList } from 'common/enabled-features/overrides'
import { DEFAULT_EXPOSED_SCHEMAS } from './constants'
import { generateTypescriptTypes } from './generate-types'
import { getLints } from './lints'
import { retrieveAnalyticsData } from './logs'
import { applyAndTrackMigrations, listMigrationVersions } from './migrations'
import { executeQuery } from './query'
import { getProjectSettings } from './settings'
import { isStudioError } from '@/lib/errors/studio-errors'
export type GetDatabaseOperationsOptions = {
headers?: HeadersInit
}
export type GetDevelopmentOperationsOptions = {
headers?: HeadersInit
}
export type GetDebuggingOperationsOptions = {
headers?: HeadersInit
}
export function getDatabaseOperations({
headers,
}: GetDatabaseOperationsOptions): DatabaseOperations {
return {
async executeSql<T>(_projectRef: string, options: ExecuteSqlOptions) {
const { query, parameters, read_only: readOnly } = options
const { data, error } = await executeQuery<T>({ query, parameters, headers, readOnly })
if (error) {
throw error
}
return data
},
async listMigrations() {
const { data, error } = await listMigrationVersions({ headers })
if (error) {
throw error
}
return data
},
async applyMigration(_projectRef: string, options: ApplyMigrationOptions) {
const { query, name } = options
const { error } = await applyAndTrackMigrations({ query, name, headers })
if (error) {
throw error
}
},
}
}
export function getDevelopmentOperations({
headers,
}: GetDevelopmentOperationsOptions): DevelopmentOperations {
return {
async getProjectUrl(_projectRef) {
const settings = getProjectSettings()
return `${settings.app_config.protocol}://${settings.app_config.endpoint}`
},
async getPublishableKeys(_projectRef) {
if (process.env.SUPABASE_PUBLISHABLE_KEY) {
const publishableKeysArray: ApiKey[] = [
{
api_key: process.env.SUPABASE_PUBLISHABLE_KEY,
name: 'publishable',
type: 'publishable' as ApiKeyType,
},
]
return publishableKeysArray
}
const settings = getProjectSettings()
const anonKey = settings.service_api_keys.find((key) => key.name === 'anon key')
if (!anonKey) {
throw new Error('Anon key not found in project settings')
}
const publishableKeysArray: ApiKey[] = [
{
api_key: anonKey.api_key,
name: anonKey.name,
type: 'legacy' as ApiKeyType,
},
]
return publishableKeysArray
},
async generateTypescriptTypes(_projectRef, options) {
const response = await generateTypescriptTypes({ headers, schemas: options?.schemas })
if (isStudioError(response)) {
throw response
}
return response
},
}
}
// Logs are disabled by default for self-hosted; enabled via the
// `docker-compose.logs.yml` override, which sets ENABLED_FEATURES_LOGS_ALL=true.
function assertLogsEnabled() {
const disabledFeatures = getEnabledFeaturesOverrideDisabledList(process.env) as Feature[]
if (!isFeatureEnabled('logs:all', disabledFeatures)) {
throw new Error(
'Logs are disabled on this instance. Enable the `docker-compose.logs.yml` override to query logs.'
)
}
}
export function getDebuggingOperations({
headers,
}: GetDebuggingOperationsOptions): DebuggingOperations {
return {
// Self-hosted logs are served by Logflare, which speaks BigQuery SQL.
logsDialect: 'bigquery',
// `query_logs` replaces `get_logs` on self-hosted. Declaring `queryLogs`
// makes the MCP server hide `get_logs` from clients (see `getDebuggingTools`
// in @supabase/mcp-server-supabase), so this method is never reached over
// MCP. The `DebuggingOperations` interface still requires it, so it throws
// defensively rather than serving logs.
async getLogs() {
throw new Error('get_logs is not supported on self-hosted; use query_logs instead.')
},
async queryLogs(projectRef: string, options: QueryLogsOptions) {
assertLogsEnabled()
// Pass the model's SQL straight through to the Logflare `logs.all`
// endpoint, which accepts an arbitrary `sql` param.
const { data, error } = await retrieveAnalyticsData({
name: 'logs.all',
projectRef,
params: {
sql: options.sql,
iso_timestamp_start: options.iso_timestamp_start,
iso_timestamp_end: options.iso_timestamp_end,
},
})
if (error) {
throw error
}
return data
},
async getSecurityAdvisors(_projectRef) {
const { data, error } = await getLints({
headers,
exposedSchemas: DEFAULT_EXPOSED_SCHEMAS,
})
if (error) {
throw error
}
return data.filter((lint) => lint.categories.includes('SECURITY'))
},
async getPerformanceAdvisors(_projectRef) {
const { data, error } = await getLints({
headers,
exposedSchemas: DEFAULT_EXPOSED_SCHEMAS,
})
if (error) {
throw error
}
return data.filter((lint) => lint.categories.includes('PERFORMANCE'))
},
}
}
export type GetFeedbackOperationsOptions = Pick<FeedbackOperationsOptions, 'fetch'>
export function getFeedbackOperations({
fetch,
}: GetFeedbackOperationsOptions = {}): FeedbackOperations {
const feedback = createFeedbackOperations({ fetch })
// Self-hosted project refs aren't Supabase projects, so feedback is sent without one.
return {
submit: ({ projectId: _projectId, ...input }) => feedback.submit(input),
delete: ({ projectId: _projectId, ...input }) => feedback.delete(input),
}
}
export type GetSelfHostedPlatformOptions = {
headers?: HeadersInit
}
// Self-hosted Studio has no notebooks. Without `notebooks` the MCP server registers no notebook tools.
// https://github.com/supabase/mcp/blob/8af504280d5689537c481924f8a11222ae0ceaeb/packages/mcp-server-supabase/src/server.ts#L374
export function getSelfHostedPlatform({
headers,
}: GetSelfHostedPlatformOptions): Omit<SupabasePlatform, 'notebooks'> {
return {
database: getDatabaseOperations({ headers }),
development: getDevelopmentOperations({ headers }),
debugging: getDebuggingOperations({ headers }),
feedback: getFeedbackOperations(),
}
}