-
Notifications
You must be signed in to change notification settings - Fork 3k
Proper handle extra data in MCP objects #1937
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
Changes from all commits
e448b42
701779a
6e3d2df
6784912
6a7b420
2e9eda9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,10 +30,9 @@ | |
|
|
||
|
|
||
| class MCPModel(BaseModel): | ||
| """Base class for all MCP protocol types. Allows extra fields for forward compatibility.""" | ||
| """Base class for all MCP protocol types.""" | ||
|
|
||
| # TODO(Marcelo): The extra="allow" should be only on specific types e.g. `Meta`, not on the base class. | ||
| model_config = ConfigDict(extra="allow", alias_generator=to_camel, populate_by_name=True) | ||
| model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now properly done.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (quick comment before I review) just to link related things, there's ongoing discussions around this here: modelcontextprotocol/modelcontextprotocol#2084
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally we should have it just ignore extra fields. Wouldn't this cause errors if a newer server sends back extra stuff in an object?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is ignoring extra fields now. That's what this PR is doing.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are 3 options: extra being
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ohh I thought default was forbid
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool! |
||
|
|
||
|
|
||
| Meta: TypeAlias = dict[str, Any] | ||
|
|
@@ -472,10 +471,13 @@ class GetTaskPayloadRequest(Request[GetTaskPayloadRequestParams, Literal["tasks/ | |
|
|
||
| class GetTaskPayloadResult(Result): | ||
| """The response to a tasks/result request. | ||
|
|
||
| The structure matches the result type of the original request. | ||
| For example, a tools/call task would return the CallToolResult structure. | ||
| """ | ||
|
|
||
| model_config = ConfigDict(extra="allow", alias_generator=to_camel, populate_by_name=True) | ||
|
|
||
|
|
||
| class CancelTaskRequestParams(RequestParams): | ||
| task_id: str | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to bump it for this to work because the
extra="allow"behavior doesn't work properly inTypedDicts on previous versions. Given that we are forced to do it on 3.14, I think it makes sense to change this to have a clean state here.