-
Notifications
You must be signed in to change notification settings - Fork 561
feat!: add server discovery and negotiation (SEP-2575) #973
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
DaleSeo
wants to merge
2
commits into
main
Choose a base branch
from
feat/sep-2575-discovery-negotiation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,13 +10,14 @@ use crate::{ | |
| ArgumentInfo, CallToolRequest, CallToolRequestParams, CallToolResponse, CallToolResult, | ||
| CancelledNotification, CancelledNotificationParam, ClientInfo, ClientJsonRpcMessage, | ||
| ClientNotification, ClientRequest, ClientResult, CompleteRequest, CompleteRequestParams, | ||
| CompleteResult, CompletionContext, CompletionInfo, DEFAULT_MRTR_MAX_ROUNDS, ErrorData, | ||
| GetExtensions, GetMeta, GetPromptRequest, GetPromptRequestParams, GetPromptResponse, | ||
| GetPromptResult, InitializeRequest, InitializedNotification, InputRequest, | ||
| InputRequiredResult, InputResponses, JsonRpcResponse, ListPromptsRequest, | ||
| ListPromptsResult, ListResourceTemplatesRequest, ListResourceTemplatesResult, | ||
| ListResourcesRequest, ListResourcesResult, ListToolsRequest, ListToolsResult, | ||
| NumberOrString, PaginatedRequestParams, ProgressNotification, ProgressNotificationParam, | ||
| CompleteResult, CompletionContext, CompletionInfo, DEFAULT_MRTR_MAX_ROUNDS, | ||
| DiscoverRequest, DiscoverRequestParams, DiscoverResult, ErrorData, GetExtensions, GetMeta, | ||
| GetPromptRequest, GetPromptRequestParams, GetPromptResponse, GetPromptResult, | ||
| InitializeRequest, InitializedNotification, InputRequest, InputRequiredResult, | ||
| InputResponses, JsonRpcResponse, ListPromptsRequest, ListPromptsResult, | ||
| ListResourceTemplatesRequest, ListResourceTemplatesResult, ListResourcesRequest, | ||
| ListResourcesResult, ListToolsRequest, ListToolsResult, Meta, NumberOrString, | ||
| PaginatedRequestParams, ProgressNotification, ProgressNotificationParam, ProtocolVersion, | ||
| ReadResourceRequest, ReadResourceRequestParams, ReadResourceResponse, ReadResourceResult, | ||
| Reference, RequestId, RootsListChangedNotification, ServerInfo, ServerJsonRpcMessage, | ||
| ServerNotification, ServerRequest, ServerResult, SetLevelRequest, SetLevelRequestParams, | ||
|
|
@@ -147,6 +148,19 @@ where | |
| #[expect(clippy::exhaustive_structs, reason = "intentionally exhaustive")] | ||
| pub struct RoleClient; | ||
|
|
||
| /// Select the first client-preferred protocol version supported by the server. | ||
| /// | ||
| /// Returns `None` when no version is shared. | ||
|
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. What happens in this case? When a client only expresses a preference the server doesn't yet support? Shouldn't it fall back to the newest one the server does support? |
||
| pub fn select_protocol_version( | ||
| client_preference: &[ProtocolVersion], | ||
| server_supported: &[ProtocolVersion], | ||
| ) -> Option<ProtocolVersion> { | ||
| client_preference | ||
| .iter() | ||
| .find(|version| server_supported.contains(version)) | ||
| .cloned() | ||
| } | ||
|
|
||
| impl ServiceRole for RoleClient { | ||
| type Req = ClientRequest; | ||
| type Resp = ClientResult; | ||
|
|
@@ -363,6 +377,19 @@ macro_rules! method { | |
| } | ||
|
|
||
| impl Peer<RoleClient> { | ||
| /// Discover the server's supported protocol versions and capabilities. | ||
| pub async fn discover(&self, meta: Meta) -> Result<DiscoverResult, ServiceError> { | ||
| let mut request = DiscoverRequest::new(DiscoverRequestParams {}); | ||
| request.extensions.insert(meta); | ||
| let result = self | ||
| .send_request(ClientRequest::DiscoverRequest(request)) | ||
| .await?; | ||
| match result { | ||
| ServerResult::DiscoverResult(result) => Ok(result), | ||
| _ => Err(ServiceError::UnexpectedResponse), | ||
| } | ||
| } | ||
|
|
||
| /// Send one `tools/call` request and return either a final result or an MRTR | ||
| /// `InputRequiredResult` without driving any follow-up rounds. | ||
| pub async fn call_tool_once( | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
I initially set them to
-32004and-32003following the SEP, but it failed the conformance suite. Then, I noticed that the error codes in the SEP differ from the draft schema. I reported this issue in modelcontextprotocol/modelcontextprotocol/issues/3091