Skip to content

Conversation

@bug-ops
Copy link
Contributor

@bug-ops bug-ops commented Nov 9, 2025

Summary

Implements modelcontextprotocol/modelcontextprotocol#1034 by adding optional default value support to StringSchema, NumberSchema, and EnumSchema in elicitation schemas.

Motivation

Resolves #521

Currently, users must manually enter information that could be pre-populated with sensible defaults, creating unnecessary friction in interactive tool workflows. For example, in an email reply tool, recipient and CC information from the email thread context should be automatically populated rather than requiring manual re-entry.

Changes

  • StringSchema: Added optional default: Option<Cow<'static, str>> field with with_default() builder method
  • NumberSchema: Added optional default: Option field with with_default() builder method
  • EnumSchema: Added optional default: Option field with with_default() builder method
  • Added comprehensive test coverage (8 new tests) for default value serialization, deserialization, and backward compatibility
  • Updated elicitation_stdio.rs example to demonstrate default values usage in a practical email reply scenario

Implementation Details:

  • Follows the existing BooleanSchema pattern for consistency
  • All defaults are optional (Option) for backward compatibility
  • Uses #[serde(skip_serializing_if = "Option::is_none")] to ensure old clients can safely ignore the new field
  • Type-safe: Rust's type system ensures defaults match their schema types

Example Usage

  let schema = ElicitationSchema::builder()
      .string_property("recipient", |s| {
          s.format(StringFormat::Email)
              .with_default("sender@example.com")
              .description("Email recipient")
      })
      .number_property("confidence", |n| {
          n.range(0.0, 1.0)
              .with_default(0.8)
              .description("Reply confidence score")
      })
      .build()?;
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Implement optional default values for StringSchema, NumberSchema, and EnumSchema
following the BooleanSchema pattern. This allows forms to be pre-populated with
sensible defaults, improving user experience in elicitation workflows.

Changes:
- Add optional `default` field to StringSchema (Cow<'static, str>)
- Add optional `default` field to NumberSchema (f64)
- Add optional `default` field to EnumSchema (String)
- Add `with_default()` builder methods to all three schemas
- Add comprehensive tests for default value serialization and deserialization
- Update elicitation example to demonstrate default values usage

All defaults are optional (Option<T>) for backward compatibility and use
skip_serializing_if to ensure old clients ignore the new field.
@github-actions github-actions bot added T-core Core library changes T-examples Example code changes T-model Model/data structure changes labels Nov 9, 2025
- Update server JSON RPC message schema with new default fields
- Apply code formatting to elicitation example
@github-actions github-actions bot added T-test Testing related changes T-config Configuration file changes labels Nov 9, 2025
@bug-ops
Copy link
Contributor Author

bug-ops commented Nov 9, 2025

Note: Inspector Testing Currently Unavailable

Testing with MCP Inspector is blocked on upstream dependencies:

Dependency chain:
This PR (Rust SDK) ✅ → TypeScript SDK ❌ → Inspector ❌

The TypeScript SDK hasn't implemented SEP-1034 yet (only BooleanSchema has default field). Inspector v0.17.2 inherits this limitation via @modelcontextprotocol/sdk@1.20.1.

Status:

  • ✅ Python SDK: Supported (via Pydantic)
  • ✅ Rust SDK: This PR - first complete implementation
  • ❌ TypeScript SDK: Not implemented
  • ❌ Inspector: Waiting for TS SDK

Inspector testing will be available once TypeScript SDK implements SEP-1034 for StringSchema, NumberSchema, and EnumSchema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-config Configuration file changes T-core Core library changes T-examples Example code changes T-model Model/data structure changes T-test Testing related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement SEP-1034: Default Values for Elicitation Schemas

1 participant