Skip to content

Conversation

@pbezglasny
Copy link

@pbezglasny pbezglasny commented Nov 14, 2025

Implemented #524 Elicitation Enum Schema Improvements and Standards Compliance.

Motivation and Context

SEP-1330: Elicitation Enum Schema Improvements introduce new schema for enum type for elicitation. This PR implements its specifications: single/multi select options with/without titles.

Details:

  • Introduced new model struct to match required schema
  • Old response move to Legacy struct
  • Added builder to configure enum schema
  • New elicitation enum structs support default values required by Implement SEP-1034: Default Values for Elicitation Schemas #521
  • Updated schema inference in ElicitationSchema::from_json_schema, now it understands enum fields of struct. Now it's possible to use next structs for elicitation request:
#[derive(Debug, Serialize, Deserialize, JsonSchema, Default)]
// inline attribute required to work for schema inference in elicitation forms
#[schemars(inline)]
// schemars does not provide required type field for enums, so we extend it here
#[schemars(extend("type" = "string"))]
enum TitledEnum {
    #[schemars(title = "Title for the first value")]
    #[default]
    FirstValue,
    #[schemars(title = "Title for the second value")]
    SecondValue,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
// inline attribute required to work for schema inference in elicitation forms
#[schemars(inline)]
enum UntitledEnum {
    First,
    Second,
    Third,
}

fn default_untitled_multi_select() -> Vec<UntitledEnum> {
    vec![UntitledEnum::Second, UntitledEnum::Third]
}
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
#[schemars(description = "User information")]
struct SelectEnumForm {
    pub single_select_untitled: UntitledEnum,
    #[schemars(
        title = "Single Select Titled",
        description = "Description for single select enum",
        default
    )]
    pub single_select_titled: TitledEnum,
    #[serde(default = "default_untitled_multi_select")]
    pub multi_select_untitled: Vec<UntitledEnum>,
    #[schemars(
        title = "Multi Select Titled",
        description = "Multi Select Description"
    )]
    pub multi_select_titled: Vec<TitledEnum>,
}

This code will serialized to specification format.

  • Added new example of using enums with elicitations in elicitation_enum_inference.rs

There was another PR #537 that closed. In this PR is used standard way to parse json schema without modification using attributes of schemars

How Has This Been Tested?

Tested with mcpinspector. It correctly understands single select option for enum. But does not work with multi-select options.

Breaking Changes

Yes. By default elicitation

Types of changes

  • 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

Additional context

Closes #524

Copilot AI review requested due to automatic review settings November 14, 2025 00:30
@github-actions github-actions bot added T-dependencies Dependencies related changes T-test Testing related changes T-config Configuration file changes T-core Core library changes T-examples Example code changes T-model Model/data structure changes labels Nov 14, 2025
Copilot finished reviewing on behalf of pbezglasny November 14, 2025 00:34
Copy link
Contributor

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 SEP-1330 Elicitation Enum Schema Improvements to support enhanced enum selection capabilities for the MCP (Model Context Protocol) Rust SDK. The implementation adds support for single/multi-select enums with optional human-readable titles.

Key changes:

  • Introduced new enum schema structures (SingleSelectEnumSchema, MultiSelectEnumSchema) with titled and untitled variants to comply with the updated specification
  • Added EnumSchemaBuilder with a fluent API for configuring enum schemas including multi-select options, min/max items, and default values
  • Maintained backward compatibility by preserving the legacy enum schema structure
  • Enhanced JSON schema inference to automatically detect and convert enum types in structs to the appropriate elicitation schema format

Reviewed Changes

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

Show a summary per file
File Description
examples/servers/src/elicitation_enum_inference.rs New example demonstrating enum selection in elicitation forms with both titled and untitled single/multi-select options
examples/servers/Cargo.toml Added example configuration for the new enum elicitation example
crates/rmcp/tests/test_message_schema/server_json_rpc_message_schema_current.json Updated JSON schema definitions to include new enum schema structures
crates/rmcp/tests/test_message_schema/server_json_rpc_message_schema.json Updated JSON schema definitions to include new enum schema structures
crates/rmcp/tests/test_elicitation.rs Updated test to use new EnumSchema::builder() API instead of direct vector construction
crates/rmcp/src/model/elicitation_schema.rs Core implementation of new enum schema types, builder pattern, and schema inference logic
Comments suppressed due to low confidence (1)

crates/rmcp/src/model/elicitation_schema.rs:953

  • Debug print statement left in production code. This println! should be removed or replaced with proper logging (e.g., tracing::debug!).
        serde_json::from_value(serde_json::Value::Object(schema))

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bug-ops
Copy link
Contributor

bug-ops commented Nov 15, 2025

Hi, @pbezglasny ! As I see, you've combined the implementation of #521 in this PR. I think it's worth mentioning this explicitly here.

@pbezglasny
Copy link
Author

@bug-ops good point, thanks. I'll update PR description

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-dependencies Dependencies related 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-1330: Elicitation Enum Schema Improvements

2 participants