feat(schema): add auto-detection schema mode from clientInfo#52
Merged
Conversation
Verify that GITLAB_SCHEMA_MODE=discriminated preserves oneOf structure instead of flattening to flat schema. Tests cover: - Preserving oneOf when mode is discriminated - Filtering denied actions while preserving oneOf structure
Implement GITLAB_SCHEMA_MODE=auto for automatic schema format detection: Phase 1 (already existed): - GITLAB_SCHEMA_MODE=flat|discriminated in config - Conditional flattening in schema-utils transformToolSchema Phase 2 (new): - Add 'auto' as third option for GITLAB_SCHEMA_MODE - detectSchemaMode() function to map client names to schema modes: - Claude clients (claude-code, claude-desktop, cursor) -> flat - MCP Inspector -> discriminated - Unknown clients -> flat (safe default) - server.oninitialized callback captures clientInfo - setDetectedSchemaMode/clearDetectedSchemaMode for session management - getSchemaMode() returns detected mode when in auto mode Closes #49
📊 Test Coverage ReportOverall Coverage: 87.39% Coverage Details
Coverage Report: View detailed coverage report
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR implements auto-detection of schema mode based on MCP client information during initialization. It adds a third auto option to the existing GITLAB_SCHEMA_MODE environment variable, allowing the server to automatically choose between flat and discriminated schema modes based on the connecting client's capabilities.
Changes:
- Adds
autoas a newSchemaModetype option with client detection logic - Implements
server.oninitializedcallback to capture client information and set schema mode - Adds comprehensive unit tests for auto-detection behavior and mode selection
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/config.ts | Adds auto to SchemaMode type, implements detectSchemaMode() function with client name matching logic |
| src/utils/schema-utils.ts | Adds module-level detectedSchemaMode variable with setter/getter/clear functions for session management |
| src/server.ts | Implements oninitialized callback to detect and set schema mode from client version |
| tests/unit/config.test.ts | Adds tests for auto mode parsing and client detection logic |
| tests/unit/utils/schema-utils.test.ts | Adds tests for auto-detection behavior in flat/discriminated modes with various scenarios |
…tation - Use exact match or prefix for client name detection (claude, claude-*) instead of substring matching to avoid false positives - Add documentation notes in config.ts, schema-utils.ts, and server.ts clarifying that auto mode is only reliable for stdio (single client) - Add edge case tests for client name detection false positives
Add tests for: - Action filtering with enum instead of const - Flattening schemas with enum action values - Description merging (take longer description) - Required for annotation with enum actions - Flat schema filtering edge cases Coverage: 91% -> 100% lines
- Add inspector-* prefix matching for consistency with claude/cursor - Remove redundant exact match (covered by startsWith)
- Use exact match + dash-prefix for mcp-inspector (not bare startsWith) - Update mock in tests to match actual implementation
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
Implements auto-detection of schema mode based on MCP client information during initialization.
Phase 1 (already existed):
GITLAB_SCHEMA_MODE=flat|discriminatedenvironment variabletransformToolSchema()Phase 2 (new in this PR):
autoas third option forGITLAB_SCHEMA_MODEdetectSchemaMode()function to map client names to schema modes:flatdiscriminatedflat(safe default)server.oninitializedcallback captures clientInfosetDetectedSchemaMode()/clearDetectedSchemaMode()for session managementgetSchemaMode()returns detected mode when in auto modeEnvironment Variable
Test plan
detectSchemaMode()with various client namesCloses #49