Skip to content

Conversation

@ByteBaker
Copy link
Contributor

Implement type-safe schema definitions for MCP elicitation requests, replacing generic JsonObject with strongly-typed primitive schemas per the MCP 2025-06-18 specification.

Features:

  • Type-safe schema hierarchy (StringSchema, NumberSchema, IntegerSchema, BooleanSchema)
  • Builder pattern with fluent API and 20+ convenience methods
  • Build-time validation ensuring required fields exist in properties
  • Private fields enforcing invariants through validated constructors
  • Comprehensive validation support (range, length, format, enums)
  • Typed property methods for cleaner schema construction

Benefits:

  • Compile-time type safety prevents invalid schema construction
  • 60-70% reduction in boilerplate through convenience methods
  • Enforces MCP specification requirement for primitive-only properties
  • Better IDE autocomplete and type inference
  • Runtime validation catches schema errors early

Fixes #465

Motivation and Context

How Has This Been Tested?

Comprehensive tests have been added and verified to be passing.

Breaking Changes

  • CreateElicitationRequestParam.requested_schema changed from JsonObject to ElicitationSchema
  • ElicitationSchemaBuilder::build() now returns Result instead of direct value

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

@github-actions github-actions bot added 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 T-service Service layer changes labels Oct 2, 2025
Copy link
Contributor

@bug-ops bug-ops left a comment

Choose a reason for hiding this comment

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

Hi @ByteBaker, some adjustments need to be made to comply with the MCP specifications.

@ByteBaker
Copy link
Contributor Author

Hi @bug-ops, I had missed out on several points. Thanks for catching them. I've made a commit addressing the issues. I hope I've resolved them all this time around.

@ByteBaker ByteBaker requested a review from bug-ops October 11, 2025 19:27
@4t145 4t145 requested review from bug-ops and Copilot and removed request for bug-ops October 13, 2025 07:03
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 type-safe schema definitions for MCP elicitation requests, replacing the generic JsonObject type with strongly-typed primitive schemas that enforce the MCP 2025-06-18 specification requirements.

Key changes:

  • Introduces type-safe schema hierarchy with primitive schema types (StringSchema, NumberSchema, IntegerSchema, BooleanSchema, EnumSchema)
  • Implements fluent builder pattern with 20+ convenience methods for schema construction
  • Adds build-time validation ensuring required fields exist in properties

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
examples/servers/src/elicitation_stdio.rs Adds a new GreetingMessage struct for demonstration
crates/rmcp/tests/test_message_schema/*.json Updates JSON schema definitions to include new primitive schema types
crates/rmcp/tests/test_elicitation.rs Refactors tests to use new type-safe schema API instead of raw JSON objects
crates/rmcp/src/service/server.rs Updates server implementation to convert JsonObject to ElicitationSchema
crates/rmcp/src/model/elicitation_schema.rs New comprehensive implementation of type-safe elicitation schemas
crates/rmcp/src/model.rs Integrates the new elicitation schema module and updates CreateElicitationRequestParam

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

)

Implement type-safe schema definitions for MCP elicitation requests,
replacing generic `JsonObject` with strongly-typed primitive schemas
per the [MCP 2025-06-18 specification](https://spec.modelcontextprotocol.io/specification/2025-06-18/server/elicitation/).

Features:
- Type-safe schema hierarchy (`StringSchema`, `NumberSchema`, `IntegerSchema`, `BooleanSchema`)
- Builder pattern with fluent API and 20+ convenience methods
- Build-time validation ensuring required fields exist in properties
- Private fields enforcing invariants through validated constructors
- Comprehensive validation support (range, length, format, enums)
- Typed property methods for cleaner schema construction

Benefits:
- Compile-time type safety prevents invalid schema construction
- 60-70% reduction in boilerplate through convenience methods
- Enforces MCP specification requirement for primitive-only properties
- Better IDE autocomplete and type inference
- Runtime validation catches schema errors early

Breaking changes:
- `CreateElicitationRequestParam.requested_schema` changed from `JsonObject` to `ElicitationSchema`
- `ElicitationSchemaBuilder::build()` now returns `Result` instead of direct value

Fixes modelcontextprotocol#465
Add from_json_schema() and from_type() methods to ElicitationSchema
for easier type-to-schema conversion. This addresses feedback about
improving ergonomics when working with generated schemas.

Also make all struct fields public for better flexibility.
@ByteBaker
Copy link
Contributor Author

@4t145 done. Please review.

4t145
4t145 previously approved these changes Oct 14, 2025
@4t145
Copy link
Collaborator

4t145 commented Oct 14, 2025

@ByteBaker It looks good to me now. Should I just merge this or wait for some review from @bug-ops?

Copy link
Contributor

@bug-ops bug-ops left a comment

Choose a reason for hiding this comment

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

Hi @ByteBaker @4t145 , sorry for long reply. I added a small suggestion, the rest LGTM

@ByteBaker
Copy link
Contributor Author

@bug-ops @4t145 all changes are done. We should be good now.

Copy link
Contributor

@bug-ops bug-ops left a comment

Choose a reason for hiding this comment

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

LGTM

@4t145 4t145 merged commit 11093bc into modelcontextprotocol:main Oct 15, 2025
11 checks passed
@4t145
Copy link
Collaborator

4t145 commented Oct 15, 2025

Thanks for your patience!

@github-actions github-actions bot mentioned this pull request Oct 15, 2025
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-service Service layer changes T-test Testing related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add type-safe requestedSchema support for elicitation (MCP 2025-06-18 full compliance)

3 participants