Skip to content

Commit e56a31e

Browse files
authored
Merge pull request #119 from supabase-community/charis/user-agent
fix: add user-agent string to content api requests
2 parents 1b70421 + f16e085 commit e56a31e

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

packages/mcp-server-supabase/src/content-api/graphql.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ export class GraphQLClient {
149149
}
150150
}
151151

152+
/**
153+
* Sets the User-Agent header for all requests.
154+
*/
155+
setUserAgent(userAgent: string) {
156+
this.#headers['User-Agent'] = userAgent;
157+
}
158+
152159
/**
153160
* Executes a GraphQL query against the provided URL.
154161
*

packages/mcp-server-supabase/src/content-api/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const contentApiSchemaResponseSchema = z.object({
88
export type ContentApiClient = {
99
schema: string;
1010
query: QueryFn;
11+
setUserAgent: (userAgent: string) => void;
1112
};
1213

1314
export async function createContentApiClient(
@@ -32,5 +33,8 @@ export async function createContentApiClient(
3233
async query(request: GraphQLRequest) {
3334
return graphqlClient.query(request);
3435
},
36+
setUserAgent(userAgent: string) {
37+
graphqlClient.setUserAgent(userAgent);
38+
},
3539
};
3640
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ export function createSupabaseMcpServer(options: SupabaseMcpServerOptions) {
9292
contentApiUrl = 'https://supabase.com/docs/api/graphql',
9393
} = options;
9494

95-
const contentApiClientPromise = createContentApiClient(contentApiUrl);
95+
const contentApiClientPromise = createContentApiClient(contentApiUrl, {
96+
'User-Agent': `supabase-mcp/${version}`,
97+
});
9698

9799
const enabledFeatures = z
98100
.set(featureGroupSchema)
@@ -104,7 +106,15 @@ export function createSupabaseMcpServer(options: SupabaseMcpServerOptions) {
104106
async onInitialize(info) {
105107
// Note: in stateless HTTP mode, `onInitialize` will not always be called
106108
// so we cannot rely on it for initialization. It's still useful for telemetry.
107-
await platform.init?.(info);
109+
const { clientInfo } = info;
110+
const userAgent = `supabase-mcp/${version} (${clientInfo.name}/${clientInfo.version})`;
111+
112+
await Promise.all([
113+
platform.init?.(info),
114+
contentApiClientPromise.then((client) =>
115+
client.setUserAgent(userAgent)
116+
),
117+
]);
108118
},
109119
tools: async () => {
110120
const contentApiClient = await contentApiClientPromise;

0 commit comments

Comments
 (0)