Skip to content

fix: resolve test stalling and add MCP schema validation#21

Merged
crowecawcaw merged 2 commits intomainfrom
claude/fix-tool-schema-tests-cHV8m
Jan 12, 2026
Merged

fix: resolve test stalling and add MCP schema validation#21
crowecawcaw merged 2 commits intomainfrom
claude/fix-tool-schema-tests-cHV8m

Conversation

@crowecawcaw
Copy link
Copy Markdown
Owner

This commit addresses two critical issues and adds comprehensive schema validation:

  1. Fixed test stalling issue caused by pydantic serialization error

    • Root cause: Click's Sentinel.UNSET values were being included in tool schemas
    • Solution: Filter out non-JSON-serializable defaults (Sentinel, enums, etc.)
    • Tests now complete in ~37s instead of timing out after 60s+
  2. Fixed enum support for click.Choice parameters

    • Enums are now properly extracted from param.type.choices
    • Enables proper validation of choice-based parameters
  3. Added pytest timeout configuration

    • Set default timeout to 10s per test
    • Added pytest-timeout to test dependencies
    • Prevents future test hangs from blocking CI/CD
  4. Integrated official MCP JSON Schema (2025-06-18)

    • Downloaded and saved official schema to tests/schemas/
    • All tool definitions now validate against official spec
  5. Created comprehensive schema validation test suite (15 new tests)

    • Validates all generated tools against official MCP schema
    • Tests basic, complex, and edge case scenarios
    • Covers real CLI fixtures (basic_cli, advanced_cli, context_cli)
    • Ensures JSON Schema draft 2020-12 compliance
    • Added jsonschema dependency for validation

All 74 tests now pass successfully (59 existing + 15 new).

This commit addresses two critical issues and adds comprehensive schema validation:

1. Fixed test stalling issue caused by pydantic serialization error
   - Root cause: Click's Sentinel.UNSET values were being included in tool schemas
   - Solution: Filter out non-JSON-serializable defaults (Sentinel, enums, etc.)
   - Tests now complete in ~37s instead of timing out after 60s+

2. Fixed enum support for click.Choice parameters
   - Enums are now properly extracted from param.type.choices
   - Enables proper validation of choice-based parameters

3. Added pytest timeout configuration
   - Set default timeout to 10s per test
   - Added pytest-timeout to test dependencies
   - Prevents future test hangs from blocking CI/CD

4. Integrated official MCP JSON Schema (2025-06-18)
   - Downloaded and saved official schema to tests/schemas/
   - All tool definitions now validate against official spec

5. Created comprehensive schema validation test suite (15 new tests)
   - Validates all generated tools against official MCP schema
   - Tests basic, complex, and edge case scenarios
   - Covers real CLI fixtures (basic_cli, advanced_cli, context_cli)
   - Ensures JSON Schema draft 2020-12 compliance
   - Added jsonschema dependency for validation

All 74 tests now pass successfully (59 existing + 15 new).
The MCP schema validates basic structure of inputSchema but does NOT
validate that the inputSchema itself is a valid JSON Schema. This
commit adds comprehensive validation to ensure inputSchema compliance
with JSON Schema draft 2020-12.

Key additions:
- validate_input_schema_is_valid_json_schema() function using
  Draft202012Validator.check_schema()
- 7 new test cases specifically validating JSON Schema compliance:
  * All inputSchemas are valid JSON Schema draft 2020-12
  * Type field is present and set to "object"
  * All properties have required "type" field
  * Enum properties are valid JSON Schema
  * Required array references valid properties
  * Real fixtures produce valid JSON Schemas
  * Default values match their declared types

This addresses the gap where MCP schema uses "additionalProperties: true"
for property schemas, allowing invalid JSON Schema to pass.

All 81 tests pass (59 existing + 22 schema validation tests).
@crowecawcaw crowecawcaw merged commit bcefcd1 into main Jan 12, 2026
4 checks passed
@crowecawcaw crowecawcaw deleted the claude/fix-tool-schema-tests-cHV8m branch January 12, 2026 16:00
@crowecawcaw crowecawcaw restored the claude/fix-tool-schema-tests-cHV8m branch January 12, 2026 16:00
@crowecawcaw crowecawcaw deleted the claude/fix-tool-schema-tests-cHV8m branch January 12, 2026 16:00
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.

2 participants