DX-116574: LD multi-context with per-request project and org targeting#89
Merged
aniket-s-kulkarni merged 5 commits intoMar 17, 2026
Conversation
FeatureFlagManager previously used a hardcoded single LD context
("mcp-server") for all flag evaluations, making per-project and
per-org targeting impossible. This change builds an LD multi-context
from the current request scope so flags can target by application,
project, and organization independently.
Key changes:
- feature_flags: _build_context() creates multi-context with project
and org kinds when available, falls back to single context otherwise
- settings: add org_id field (NoFlag) on Dremio model
- mcp: DelegatingTokenVerifier extracts org_id from JWT aud claim
(Dremio Cloud sets aud=orgId); dual-route OAuth metadata endpoint
so /mcp/{project_id}/.well-known/oauth-authorization-server resolves
- tools: @secured decorator wires org_id ContextVar into run_with()
- manual test: org_id CLI arg now passed through to run_with()
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add LDContextKind StrEnum defining projectId and orgId context kinds - Move project_id/org_id ContextVars to FeatureFlagManager (decoupled from settings) - Remove org_id from Dremio settings model (only needed for LD context) - ProjectIdMiddleware and DelegatingTokenVerifier set ContextVars directly - Update tests to use FeatureFlagManager.set_project_id/set_org_id Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ktsunoda
reviewed
Mar 16, 2026
Add dremio.extract_org_id_from_jwt (default false, LD-flaggable) to control whether the server reads the JWT aud claim for LD org-based targeting. Without this setting there is no other mechanism to derive the org ID during tool calls. - New Dremio model field + golden flag keys updated - verify_token gated behind the setting - conftest: dremio_overrides param for http_streamable_mcp_server - 3 E2E tests: org+project context, org-only, opaque token fallback - Smoke test: --ld-sdk-key/--ld-flag/--ld-expected options with aud assertion ensuring JWT contains orgId before LD evaluation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace hand-rolled base64 payload extraction with
jwt.decode(token, options={"verify_signature": False}) in mcp.py,
stremable_http_cli.py, and test_launchdarkly_e2e.py.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ktsunoda
approved these changes
Mar 17, 2026
ktsunoda
approved these changes
Mar 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LD multi-context:
FeatureFlagManager._build_context()builds an LD multi-context withapplication,project, andorganizationkinds from the current request scope, enabling per-project and per-org flag targeting. Falls back to the existing single"mcp-server"context when neither is available (zero behavioral change for existing deployments).extract_org_id_from_jwtsetting: JWTaudextraction is gated behind a newdremio.extract_org_id_from_jwtsetting (defaultfalse, LD-flaggable). This is the only mechanism to derive the org ID for LD org-based targeting during tool calls — without it there is no way to identify which org is making the request. When enabled,DelegatingTokenVerifierextracts theaudclaim from the bearer token JWT (Dremio Cloud setsaud=orgIdviaTokenServiceImpl). No signature verification — the token is always forwarded to Dremio for real validation; we only read the audience for LD context targeting. Gracefully handles opaque (non-JWT) tokens by returningNone.Tenant-scoped OAuth metadata: Added dual route so
/mcp/{project_id}/.well-known/oauth-authorization-serverresolves to the same handler as the root path.ProjectIdMiddlewareextracts the project ID from the URL; Starlette's exact-matchRouterequires the second registration since the MCPMountonly does prefix matching at/mcp.E2E tests for LD multi-context: 3 new E2E tests verify org_id + project_id flow into the LD context during real tool calls (mock LD client captures
variation()contexts). Covers: both IDs present, org-only, and opaque token fallback.Smoke test LD flag check: New
--ld-sdk-key,--ld-flag,--ld-expectedoptions on thetestcommand evaluate a real LD flag with the full multi-context (project from URL, org from JWTaud). Asserts that the JWTaudclaim contains an orgId before proceeding.Test plan
dremio.extract_org_id_from_jwtaudhas orgId before LD flag evaluation/mcp/{project_id}/.well-known/oauth-authorization-serverreturns metadata--ld-sdk-keyand--ld-flag🤖 Generated with Claude Code