Skip to content

feat(schema): add auto-detection schema mode from clientInfo#52

Merged
polaz merged 8 commits intomainfrom
feat/49-schema-mode
Jan 20, 2026
Merged

feat(schema): add auto-detection schema mode from clientInfo#52
polaz merged 8 commits intomainfrom
feat/49-schema-mode

Conversation

@polaz
Copy link
Copy Markdown
Member

@polaz polaz commented Jan 20, 2026

Summary

Implements auto-detection of schema mode based on MCP client information during initialization.

Phase 1 (already existed):

  • GITLAB_SCHEMA_MODE=flat|discriminated environment variable
  • Conditional flattening in transformToolSchema()

Phase 2 (new in this PR):

  • 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

Environment Variable

# Explicit modes (Phase 1)
GITLAB_SCHEMA_MODE=flat         # Default - flatten oneOf for AI clients
GITLAB_SCHEMA_MODE=discriminated # Preserve oneOf structure

# Auto-detection (Phase 2)
GITLAB_SCHEMA_MODE=auto         # Detect from clientInfo

Test plan

  • Unit tests for detectSchemaMode() with various client names
  • Unit tests for auto mode fallback when client not yet detected
  • Unit tests for discriminated mode preserving oneOf
  • Full test suite passes (2063 tests)
  • Lint and build pass

Closes #49

polaz added 2 commits January 20, 2026 09:27
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
Copilot AI review requested due to automatic review settings January 20, 2026 07:35
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 20, 2026

📊 Test Coverage Report

Overall Coverage: 87.39%

Coverage Details

Metric Percentage
Statements 87.39%
Branches 80%
Functions 73.19%
Lines 87.9%

Coverage Report: View detailed coverage report

This report was generated automatically from your PR changes.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 20, 2026

Codecov Report

❌ Patch coverage is 95.74468% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/server.ts 50.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 auto as a new SchemaMode type option with client detection logic
  • Implements server.oninitialized callback 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

polaz added 2 commits January 20, 2026 09:48
…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
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

polaz added 3 commits January 20, 2026 09:59
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)
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

- Use exact match + dash-prefix for mcp-inspector (not bare startsWith)
- Update mock in tests to match actual implementation
@polaz polaz requested a review from Copilot January 20, 2026 08:09
@polaz polaz merged commit 9ec6368 into main Jan 20, 2026
26 checks passed
@polaz polaz deleted the feat/49-schema-mode branch January 20, 2026 08:14
sw-release-bot bot pushed a commit that referenced this pull request Jan 20, 2026
## [6.11.0](v6.10.0...v6.11.0) (2026-01-20)

### Features

* **schema:** add auto-detection schema mode from clientInfo ([#52](#52)) ([9ec6368](9ec6368)), closes [#49](#49)
@polaz polaz review requested due to automatic review settings March 23, 2026 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto schema_mode per-session based on clientInfo

2 participants