Skip to content

fix: resolve schema generation regression with dual-pattern support (v0.10.1) - #56

Merged
avrabe merged 8 commits into
mainfrom
fix/schema-generation-v0.10.1
Sep 5, 2025
Merged

fix: resolve schema generation regression with dual-pattern support (v0.10.1)#56
avrabe merged 8 commits into
mainfrom
fix/schema-generation-v0.10.1

Conversation

@avrabe

@avrabe avrabe commented Sep 4, 2025

Copy link
Copy Markdown
Contributor

🐛 Problem

Issue #55 reported that parameter schema generation was completely broken in v0.10.0:

  • All tools showed empty schemas: {"properties": {}, "type": "object"}
  • MCP clients couldn't validate parameters, provide autocomplete, or call tools properly
  • Users got "Missing required parameter 'params'" errors

🎯 Root Cause

The macro was generating hardcoded empty schemas instead of using JsonSchema trait implementations:

// Generated code was doing this:
("properties").into(),
::serde_json::Value::Object(::serde_json::Map::new()),  // Always empty!

Solution: Branch 2 - Dual Pattern Support

Instead of forcing a breaking change, we now support both patterns:

Pattern 1: Multi-parameter → Auto-generated schema

// ✅ Works now (was broken, now generates proper schema)
fn tool(&self, name: String, age: u32, active: bool) -> String

Generated schema:

{
  "properties": {
    "name": {"type": "string"},
    "age": {"type": "integer", "minimum": 0}, 
    "active": {"type": "boolean"}
  },
  "required": ["name", "age", "active"]
}

Pattern 2: JsonSchema struct → Rich schema

// ✅ Already worked, now works even better
#[derive(Serialize, Deserialize, JsonSchema)]
struct MyParams {
    /// Required message with validation
    message: String,
    /// Optional count  
    count: Option<u32>,
}
fn tool(&self, params: MyParams) -> String

Generated schema:

{
  "description": "Rich schema with descriptions",
  "properties": {
    "message": {
      "description": "Required message with validation",
      "type": "string"
    },
    "count": {
      "description": "Optional count", 
      "type": ["integer", "null"],
      "minimum": 0
    }
  },
  "required": ["message"]
}

🚫 Non-Breaking Change

Before (Broken): Empty schemas for all tools
After (Fixed): Proper schemas for both patterns - no code changes required

  • ✅ Our 37 existing multi-parameter methods work unchanged
  • ✅ User code works unchanged
  • ✅ JsonSchema structs get even richer schemas
  • ✅ Perfect Optional detection → nullable types + excluded from required

📊 Impact

This resolves the schema generation regression while supporting both the multi-parameter pattern we use extensively and the JsonSchema struct pattern for rich validation.

Fixes critical bug where parameter schemas were hardcoded as empty objects
instead of using JsonSchema trait implementations.

## Problem
- Issue #55: Tools showed empty schemas `{"properties": {}, "type": "object"}`
- MCP clients couldn't validate parameters or provide autocomplete
- Root cause: macro generated hardcoded empty schemas instead of calling JsonSchema

## Solution
- Rewrote `generate_input_schema_for_method()` to detect single parameter structs
- Now calls `<ParamType>::json_schema()` to generate real schemas from JsonSchema derives
- Added clear compile errors for multi-parameter patterns with migration guidance
- Added comprehensive test demonstrating proper schema generation

## Results
- Tools now generate proper typed schemas with required/optional field detection
- Resolves "Missing required parameter 'params'" errors in MCP clients
- Enforces best practice single-struct parameter pattern

## Breaking Change
Multi-parameter tools now require migration to single struct pattern:
```rust
// Old (now compile error)
fn tool(&self, name: String, count: Option<u32>) -> String

// New (required)
fn tool(&self, params: ToolParams) -> String
```

Closes #55

Version: 0.10.0 → 0.10.1
Updates examples to work with the schema generation fix:
- Add schemars dependency and imports
- Convert multi-parameter tools to single parameter structs
- Add JsonSchema derives for proper schema generation

Examples fixed:
- hello-world: SayHelloParams struct
- hello-world-with-auth: SayHelloParams struct
- ultra-simple: SayHelloParams and AddParams structs

This resolves CI compilation failures and demonstrates the new pattern.
@github-actions

github-actions Bot commented Sep 4, 2025

Copy link
Copy Markdown

PR Validation Results

Quick Validation: ✅

  • Format check
  • Clippy lints
  • Unit tests
  • Documentation

Summary: ✅ All checks passed

- Add explicit JsonSchema trait import in generated code
- Use fully qualified trait path for json_schema method call
- Ensures compatibility with primitive types (String, i32, bool, etc.)
- Maintains support for custom struct parameters with JsonSchema derives

This improves upon the initial fix by making the macro work with both
primitive parameter types and custom JsonSchema-derived structs.

Part of fix for #55
@avrabe
avrabe force-pushed the fix/schema-generation-v0.10.1 branch from ab68ef5 to feb928c Compare September 5, 2025 04:02
- Fix async_sync_tests.rs: Convert multi-parameter methods to single structs with JsonSchema
- Fix performance_tests.rs: Convert all multi-parameter methods (bulk_lookup, memory_intensive, etc.)
- Fix core_functionality.rs: Convert tool_with_params to use ToolParams struct
- Fix mcp_resource_tests.rs: Convert database table and API methods to use parameter structs

All fixes maintain the same functionality while conforming to the new single-struct
parameter requirement introduced to fix schema generation regression.

Part of resolving #55
@avrabe avrabe changed the title fix: resolve schema generation regression in mcp_tools macro (v0.10.1) BREAKING: resolve schema generation regression (v0.11.0) Sep 5, 2025
- Workspace version: 0.10.1 → 0.11.0
- All package versions: 0.10.0 → 0.11.0
- Properly reflects breaking change requiring code migration
- Multi-parameter tools now require single-struct pattern
- Resolves semantic versioning issue from #57

This is a breaking change that requires users to migrate:
- FROM: fn tool(&self, a: String, b: i32)
- TO: fn tool(&self, params: MyParams) with #[derive(JsonSchema)]
…ameter and JsonSchema patterns

🎯 **NON-BREAKING SOLUTION**: Instead of forcing users to migrate, we now support both patterns:

✅ **Pattern 1: Multi-parameter (auto-generated schemas)**
   fn tool(&self, name: String, age: u32, active: bool) -> String
   → Generates: {"properties": {"name": {"type": "string"}, ...}, "required": [...]}

✅ **Pattern 2: JsonSchema struct (rich schemas)**
   fn tool(&self, params: MyParams) -> String  // MyParams: #[derive(JsonSchema)]
   → Uses JsonSchema trait: Full validation, descriptions, format hints

🔧 **Implementation**:
- Enhanced generate_input_schema_for_method() to detect parameter patterns
- Multi-parameter: Auto-generate schemas from Rust primitive types
- Single JsonSchema struct: Use existing JsonSchema trait implementation
- Comprehensive type mapping: String→string, u32→integer+minimum:0, Option<T>→nullable

📊 **Results**:
- ✅ Fixes original schema regression (empty schemas → proper schemas)
- ✅ No breaking changes (our 37 multi-param methods keep working)
- ✅ No user migration required (existing code works unchanged)
- ✅ Optional handling: Option<T> correctly excluded from required fields
- ✅ Rich schemas: JsonSchema structs get descriptions and validation

This approach resolves #55 without the hypocrisy of forcing a pattern we don't use ourselves.
@avrabe avrabe changed the title BREAKING: resolve schema generation regression (v0.11.0) fix: resolve schema generation regression with dual-pattern support (v0.10.1) Sep 5, 2025
- Fixed formatting issues in test files (clippy uninlined_format_args)
- Updated test function calls to use proper parameter structs
- Added missing JsonSchema derives for type system tests
- Added schemars dependency to test-tools-server example
@github-actions

github-actions Bot commented Sep 5, 2025

Copy link
Copy Markdown

Code Coverage Report 📊

Local Coverage: 19.64%
Validation: Handled by Codecov

Note: Coverage validation is now performed by Codecov to ensure consistency across all platforms.

Coverage Details
Filename                                                  Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
integration-tests/src/auth_server_integration.rs              380                61    83.95%          26                 9    65.38%         273                70    74.36%           0                 0         -
integration-tests/src/cli_server_integration.rs               390                32    91.79%          35                 5    85.71%         347                23    93.37%           0                 0         -
integration-tests/src/end_to_end_scenarios.rs                 906               172    81.02%          40                 9    77.50%         594                90    84.85%           0                 0         -
integration-tests/src/lib.rs                                   22                12    45.45%           5                 2    60.00%          44                17    61.36%           0                 0         -
integration-tests/src/monitoring_integration.rs               427                66    84.54%          28                 8    71.43%         357                83    76.75%           0                 0         -
integration-tests/src/transport_server_integration.rs         432               101    76.62%          31                11    64.52%         369               128    65.31%           0                 0         -
mcp-auth/src/audit.rs                                         385               262    31.95%          27                17    37.04%         269               177    34.20%           0                 0         -
mcp-auth/src/config.rs                                         48                41    14.58%          11                10     9.09%          75                68     9.33%           0                 0         -
mcp-auth/src/consent.rs                                       140               140     0.00%          12                12     0.00%          98                98     0.00%           0                 0         -
mcp-auth/src/consent/manager.rs                               511               511     0.00%          40                40     0.00%         395               395     0.00%           0                 0         -
mcp-auth/src/crypto/encryption.rs                              89                89     0.00%           9                 9     0.00%          51                51     0.00%           0                 0         -
mcp-auth/src/crypto/hashing.rs                                 98                98     0.00%          10                10     0.00%          53                53     0.00%           0                 0         -
mcp-auth/src/crypto/keys.rs                                   115               115     0.00%           8                 8     0.00%          78                78     0.00%           0                 0         -
mcp-auth/src/crypto/mod.rs                                     15                15     0.00%           2                 2     0.00%          12                12     0.00%           0                 0         -
mcp-auth/src/jwt.rs                                           321               284    11.53%          29                27     6.90%         255               226    11.37%           0                 0         -
mcp-auth/src/lib.rs                                            18                15    16.67%           6                 5    16.67%          16                13    18.75%           0                 0         -
mcp-auth/src/manager.rs                                      1229              1116     9.19%         116               101    12.93%         918               794    13.51%           0                 0         -
mcp-auth/src/manager_vault.rs                                 241               241     0.00%          22                22     0.00%         194               194     0.00%           0                 0         -
mcp-auth/src/middleware/mcp_auth.rs                           240               240     0.00%          24                24     0.00%         208               208     0.00%           0                 0         -
mcp-auth/src/middleware/session_middleware.rs                 435               435     0.00%          41                41     0.00%         359               359     0.00%           0                 0         -
mcp-auth/src/models.rs                                        195               195     0.00%          19                19     0.00%         166               166     0.00%           0                 0         -
mcp-auth/src/monitoring/dashboard_server.rs                   241               241     0.00%          28                28     0.00%         440               440     0.00%           0                 0         -
mcp-auth/src/monitoring/security_monitor.rs                   708               708     0.00%          70                70     0.00%         531               531     0.00%           0                 0         -
mcp-auth/src/performance.rs                                   577               577     0.00%          34                34     0.00%         425               425     0.00%           0                 0         -
mcp-auth/src/permissions/mcp_permissions.rs                   419               419     0.00%          33                33     0.00%         319               319     0.00%           0                 0         -
mcp-auth/src/security/request_security.rs                     702               702     0.00%          49                49     0.00%         615               615     0.00%           0                 0         -
mcp-auth/src/session/session_manager.rs                       457               457     0.00%          50                50     0.00%         353               353     0.00%           0                 0         -
mcp-auth/src/setup/mod.rs                                     160               160     0.00%          21                21     0.00%         163               163     0.00%           0                 0         -
mcp-auth/src/setup/validator.rs                               141               141     0.00%          11                11     0.00%         106               106     0.00%           0                 0         -
mcp-auth/src/storage.rs                                       697               680     2.44%          50                46     8.00%         412               394     4.37%           0                 0         -
mcp-auth/src/transport/auth_extractors.rs                     155               155     0.00%          27                27     0.00%         137               137     0.00%           0                 0         -
mcp-auth/src/transport/http_auth.rs                           303               303     0.00%          20                20     0.00%         216               216     0.00%           0                 0         -
mcp-auth/src/transport/stdio_auth.rs                          268               268     0.00%          22                22     0.00%         195               195     0.00%           0                 0         -
mcp-auth/src/transport/websocket_auth.rs                      351               351     0.00%          23                23     0.00%         258               258     0.00%           0                 0         -
mcp-auth/src/validation.rs                                    144               144     0.00%          13                13     0.00%          95                95     0.00%           0                 0         -
mcp-auth/src/vault/infisical.rs                               637               637     0.00%          54                54     0.00%         489               489     0.00%           0                 0         -
mcp-auth/src/vault/mod.rs                                     135               135     0.00%          17                17     0.00%          92                92     0.00%           0                 0         -
mcp-cli-derive/src/lib.rs                                     324               324     0.00%          22                22     0.00%         262               262     0.00%           0                 0         -
mcp-cli/src/config.rs                                          81                68    16.05%          13                10    23.08%          70                61    12.86%           0                 0         -
mcp-cli/src/lib.rs                                             15                15     0.00%           5                 5     0.00%          15                15     0.00%           0                 0         -
mcp-cli/src/server.rs                                         241               241     0.00%          34                34     0.00%         207               207     0.00%           0                 0         -
mcp-cli/src/utils.rs                                          101               101     0.00%          13                13     0.00%          73                73     0.00%           0                 0         -
mcp-logging/src/aggregation.rs                                311               311     0.00%          27                27     0.00%         228               228     0.00%           0                 0         -
mcp-logging/src/alerting.rs                                   552               344    37.68%          39                17    56.41%         419               226    46.06%           0                 0         -
mcp-logging/src/correlation.rs                                415               415     0.00%          34                34     0.00%         299               299     0.00%           0                 0         -
mcp-logging/src/dashboard.rs                                  391               197    49.62%          21                15    28.57%         394               182    53.81%           0                 0         -
mcp-logging/src/metrics.rs                                    306               127    58.50%          36                19    47.22%         329               123    62.61%           0                 0         -
mcp-logging/src/persistence.rs                                360               360     0.00%          26                26     0.00%         202               202     0.00%           0                 0         -
mcp-logging/src/profiling.rs                                  502               496     1.20%          37                36     2.70%         398               354    11.06%           0                 0         -
mcp-logging/src/sanitization.rs                               268               265     1.12%          22                21     4.55%         181               173     4.42%           0                 0         -
mcp-logging/src/structured.rs                                 258               255     1.16%          24                23     4.17%         230               227     1.30%           0                 0         -
mcp-logging/src/telemetry.rs                                   75                34    54.67%          12                 5    58.33%          78                24    69.23%           0                 0         -
mcp-monitoring/src/collector.rs                               179                78    56.42%          19                 8    57.89%         133                52    60.90%           0                 0         -
mcp-monitoring/src/config.rs                                    3                 0   100.00%           1                 0   100.00%           8                 0   100.00%           0                 0         -
mcp-monitoring/src/lib.rs                                       3                 0   100.00%           1                 0   100.00%           3                 0   100.00%           0                 0         -
mcp-monitoring/src/metrics.rs                                   3                 3     0.00%           1                 1     0.00%          11                11     0.00%           0                 0         -
mcp-protocol/src/error.rs                                     193               153    20.73%          27                18    33.33%         151               117    22.52%           0                 0         -
mcp-protocol/src/errors.rs                                     83                83     0.00%          12                12     0.00%          40                40     0.00%           0                 0         -
mcp-protocol/src/lib.rs                                        12                12     0.00%           2                 2     0.00%          11                11     0.00%           0                 0         -
mcp-protocol/src/model.rs                                     134               131     2.24%          30                29     3.33%         177               170     3.95%           0                 0         -
mcp-protocol/src/validation.rs                                222               222     0.00%          23                23     0.00%         159               159     0.00%           0                 0         -
mcp-security/src/config.rs                                      4                 0   100.00%           1                 0   100.00%           9                 0   100.00%           0                 0         -
mcp-security/src/lib.rs                                         3                 0   100.00%           1                 0   100.00%           3                 0   100.00%           0                 0         -
mcp-security/src/middleware.rs                                 18                 3    83.33%           3                 0   100.00%          25                 3    88.00%           0                 0         -
mcp-security/src/validation.rs                                 10                10     0.00%           1                 1     0.00%          11                11     0.00%           0                 0         -
mcp-server/src/alerting_endpoint.rs                           117               117     0.00%          15                15     0.00%         110               110     0.00%           0                 0         -
mcp-server/src/backend.rs                                     116               101    12.93%          26                22    15.38%         101                88    12.87%           0                 0         -
mcp-server/src/builder_trait.rs                                26                26     0.00%           3                 3     0.00%          23                23     0.00%           0                 0         -
mcp-server/src/common_backend.rs                               59                59     0.00%          11                11     0.00%          82                82     0.00%           0                 0         -
mcp-server/src/context.rs                                      55                14    74.55%          10                 3    70.00%          46                16    65.22%           0                 0         -
mcp-server/src/dashboard_endpoint.rs                          104               104     0.00%          12                12     0.00%          79                79     0.00%           0                 0         -
mcp-server/src/handler.rs                                     293               189    35.49%          51                29    43.14%         221               127    42.53%           0                 0         -
mcp-server/src/health_endpoint.rs                              83                83     0.00%           5                 5     0.00%          91                91     0.00%           0                 0         -
mcp-server/src/metrics_endpoint.rs                            133               133     0.00%           7                 7     0.00%          86                86     0.00%           0                 0         -
mcp-server/src/middleware.rs                                  128                33    74.22%          13                 5    61.54%         104                17    83.65%           0                 0         -
mcp-server/src/server.rs                                      327               111    66.06%          38                19    50.00%         230                77    66.52%           0                 0         -
mcp-transport/src/batch.rs                                    191               191     0.00%          14                14     0.00%         128               128     0.00%           0                 0         -
mcp-transport/src/config.rs                                    15                12    20.00%           5                 4    20.00%          15                12    20.00%           0                 0         -
mcp-transport/src/http.rs                                     651               634     2.61%          39                36     7.69%         438               408     6.85%           0                 0         -
mcp-transport/src/lib.rs                                       13                 3    76.92%           1                 0   100.00%          12                 3    75.00%           0                 0         -
mcp-transport/src/stdio.rs                                    233               186    20.17%          17                12    29.41%         162               119    26.54%           0                 0         -
mcp-transport/src/streamable_http.rs                          223               223     0.00%          19                19     0.00%         165               165     0.00%           0                 0         -
mcp-transport/src/validation.rs                               191               191     0.00%          14                14     0.00%         135               135     0.00%           0                 0         -
mcp-transport/src/websocket.rs                                 15                 9    40.00%           5                 3    40.00%          17                11    35.29%           0                 0         -
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                       20772             16986    18.23%        1855              1543    16.82%       16348             13138    19.64%           0                 0         -

📋 Full Report: View on Codecov

@codecov

codecov Bot commented Sep 5, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@avrabe
avrabe merged commit 40f3b5b into main Sep 5, 2025
22 checks passed
@avrabe
avrabe deleted the fix/schema-generation-v0.10.1 branch September 5, 2025 15:53
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.

Parameter schema generation not working - all tools show empty inputSchema

1 participant