Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support validation for method fields in *Request #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
zhongyi51 wants to merge 1 commit into rust-mcp-stack:main
base: main
Choose a base branch
Loading
from zhongyi51:main

Conversation

Copy link

@zhongyi51 zhongyi51 commented Jul 19, 2025

Closes: #75

The Problem

As identified in issue #75, the individual *Request structs (e.g., PingRequest, ListResourcesRequest) do not currently validate that their method field matches the constant value defined in the JSON schema. This creates ambiguity. For example, a JSON payload like:

{
 "method": "wrong/method",
 "params": { /* ... valid params for ListResourcesRequest ... */ }
}

could be incorrectly deserialized as a ListResourcesRequest. The deserialization process should fail fast if the method name is incorrect for the target struct.

The Solution

This pull request proposes a robust pattern to validate the method field by leveraging Serde's #[serde(deserialize_with = "...")]:

  1. Deserializes the incoming value as a string.
  2. Compares it against the expected constant value for that specific request type.

Note for Maintainers

⚠️ This pull request should NOT be merged directly. It serves as a working example for the code generator.

@zhongyi51 zhongyi51 changed the title (削除) Support validation for subtypes of *Request enums (ServerRequest as an example) (削除ここまで) (追記) Support validation for method field in *Request (追記ここまで) Jul 19, 2025
@zhongyi51 zhongyi51 changed the title (削除) Support validation for method field in *Request (削除ここまで) (追記) Support validation for method fields in *Request (追記ここまで) Jul 19, 2025
Copy link
Member

Update: It has been a long time and my focus was on other priority features of the SDK. I started adding these changes into schema generator and will update this PR soon 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /