Skip to content

feat(supabase): add global.clientInfo to append parameters to X-Client-Info - #2887

Open
yannbf wants to merge 2 commits into
masterfrom
yannbraga/sdk-1877-add-mcp-middleware-telemetry-to-server
Open

yannbf wants to merge 2 commits into
masterfrom
yannbraga/sdk-1877-add-mcp-middleware-telemetry-to-server

Conversation

@yannbf

@yannbf yannbf commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

🔍 Description

What changed?

This PR adds a global.clientInfo option to createClient. A way to append a map of key: value pairs to the X-Client-Info header, e.g.:

createClient(url, key, {
  global: { clientInfo: { via: 'my-lib/1.2.0' } },
})
// X-Client-Info: supabase-js/<version>; runtime=node; runtime-version=22.23.4; via=my-lib/1.2.0

The createClient function throws when:

  • a given key does not match ^[A-Za-z0-9_-]+$
  • a given key is one the SDK sets itself (platform, platform-version, platform-architecture, runtime, runtime-version, framework, framework-version, features), or is already in the caller's header
  • a value is not a string, or is empty after trimming

Values are trimmed, and ;, % and anything outside printable ASCII are percent-encoded as UTF-8, based on the spec.

Why was this change needed?

To improve library detection, such as in @supabase/server as the consumer.

🔄 Breaking changes

  • This PR contains no breaking changes

The option is new and optional. Existing callers who set global.headers['X-Client-Info'] still replace the default as before, and the result is unchanged when clientInfo is not set.

📋 Checklist

  • I have read the Contributing Guidelines
  • My PR title follows the conventional commit format: <type>(<scope>): <description>
  • I have run pnpm nx format to ensure consistent code formatting
  • I have added tests for new functionality (if applicable)
  • I have updated documentation (if applicable)

📝 Additional notes

Spec updates in supabase/sdk are coming.

AI-assisted generated summary

Written with Claude Code and reviewed by me, including an independent review pass that found and fixed an emoji encoding bug (missing u regex flag).

Files: src/lib/types.ts (option and JSDoc), src/lib/helpers.ts (appendClientInfo, called from applySettingDefaults), src/lib/constants.ts (CLIENT_INFO_HEADER), src/SupabaseClient.ts (option list), README.md, and two test files.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Added an option to include custom key-value metadata in the X-Client-Info header sent with Auth, PostgREST, Storage, and Functions requests. Values are trimmed and encoded, and invalid or conflicting entries are rejected.
    • Custom metadata is appended to an existing client-info header when available.

The client options now support global.clientInfo for adding metadata to the X-Client-Info header. Header processing validates keys and values, rejects reserved or duplicate keys, and appends trimmed, encoded values to the caller-supplied or default header. Tests cover header composition, validation, and requests to PostgREST, Storage, Functions, and Auth.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant SupabaseClient
  participant applySettingDefaults
  participant appendClientInfo
  participant PostgREST
  participant Storage
  participant Functions
  participant Auth
  Caller->>SupabaseClient: create client with global.clientInfo
  SupabaseClient->>applySettingDefaults: resolve headers and clientInfo
  applySettingDefaults->>appendClientInfo: validate and append entries
  appendClientInfo-->>applySettingDefaults: resolved client-info header
  applySettingDefaults-->>SupabaseClient: resolved headers
  SupabaseClient->>PostgREST: send request with X-Client-Info
  SupabaseClient->>Storage: send request with X-Client-Info
  SupabaseClient->>Functions: send request with X-Client-Info
  SupabaseClient->>Auth: send request with X-Client-Info
Loading

Change: Feature

Merge Risk: Minimal · up to 796a2

This adds an optional global.clientInfo setting that appends validated metadata to the X-Client-Info header. Behavior is unchanged when the option is not used, and the new tests cover the main request paths. No merge-blocking risk was found.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4b7d8e0f-0360-4947-b120-2533cf5cb6fa
Commits

Reviewing files that changed from the base of the PR and between f9a5674 and 796a2c0.

Files selected for processing: 3

  • packages/core/supabase-js/README.md
  • packages/core/supabase-js/src/lib/helpers.ts
  • packages/core/supabase-js/src/lib/types.ts
Files skipped from review as they are similar to previous changes: 1

  • packages/core/supabase-js/src/lib/helpers.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@github-actions github-actions Bot added the supabase-js Related to the supabase-js library. label Nov 23, 2026
@pkg-pr-new

pkg-pr-new Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@supabase/auth-js

npm i https://pkg.pr.new/@supabase/auth-js@2887

@supabase/functions-js

npm i https://pkg.pr.new/@supabase/functions-js@2887

@supabase/postgrest-js

npm i https://pkg.pr.new/@supabase/postgrest-js@2887

@supabase/realtime-js

npm i https://pkg.pr.new/@supabase/realtime-js@2887

@supabase/storage-js

npm i https://pkg.pr.new/@supabase/storage-js@2887

@supabase/supabase-js

npm i https://pkg.pr.new/@supabase/supabase-js@2887

commit: 796a2c0

@coveralls

coveralls commented Nov 23, 2026 •

Copy link
Copy Markdown

Coverage Status

Coverage is 96.407% — yannbraga/sdk-1877-add-mcp-middleware-telemetry-to-server into master. No base build found for master.

…t-Info

Libraries built on supabase-js had to replace the whole X-Client-Info header
to identify themselves, which drops the SDK's own platform and runtime
parameters. global.clientInfo appends key=value parameters to the resolved
header instead.

Refs SDK-1877

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@yannbf
yannbf force-pushed the yannbraga/sdk-1877-add-mcp-middleware-telemetry-to-server branch from dd2a1c4 to f9a5674 Compare November 23, 2026 18:40
@yannbf
yannbf marked this pull request as ready for review November 24, 2026 10:17
@yannbf
yannbf requested a review from a team as a code owner November 24, 2026 10:17
…served keys

The reserved key list stays in helpers.ts only. The clientInfo JSDoc and the
README point to the spec for the key and value rules.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

supabase-js Related to the supabase-js library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants