Skip to main content
Glama
Apache 2.0
845
2,105
  • Apple
index.ts1.59 kB
import createClient, { type Client, type FetchResponse, type ParseAsResponse, } from 'openapi-fetch'; import type { MediaType, ResponseObjectMap, SuccessResponse, } from 'openapi-typescript-helpers'; import { z } from 'zod'; import type { paths } from './types.js'; export function createManagementApiClient( baseUrl: string, accessToken: string, headers: Record<string, string> = {} ) { return createClient<paths>({ baseUrl, headers: { Authorization: `Bearer ${accessToken}`, ...headers, }, }); } export type ManagementApiClient = Client<paths>; export type SuccessResponseType< T extends Record<string | number, any>, Options, Media extends MediaType, > = { data: ParseAsResponse<SuccessResponse<ResponseObjectMap<T>, Media>, Options>; error?: never; response: Response; }; const errorSchema = z.object({ message: z.string(), }); export function assertSuccess< T extends Record<string | number, any>, Options, Media extends MediaType, >( response: FetchResponse<T, Options, Media>, fallbackMessage: string ): asserts response is SuccessResponseType<T, Options, Media> { if ('error' in response) { if (response.response.status === 401) { throw new Error( 'Unauthorized. Please provide a valid access token to the MCP server via the --access-token flag or SUPABASE_ACCESS_TOKEN.' ); } const { data: errorContent } = errorSchema.safeParse(response.error); if (errorContent) { throw new Error(errorContent.message); } throw new Error(fallbackMessage); } }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/supabase-community/mcp-supabase'

If you have feedback or need assistance with the MCP directory API, please join our Discord server