-
Notifications
You must be signed in to change notification settings - Fork 2.5k
MCP Apps Plumbing #6286
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
Merged
Merged
MCP Apps Plumbing #6286
Changes from all commits
Commits
Show all changes
8 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,8 +41,8 @@ use crate::oauth::oauth_flow; | |
| use crate::prompt_template; | ||
| use crate::subprocess::configure_command_no_window; | ||
| use rmcp::model::{ | ||
| CallToolRequestParam, Content, ErrorCode, ErrorData, GetPromptResult, Prompt, RawContent, | ||
| Resource, ResourceContents, ServerInfo, Tool, | ||
| CallToolRequestParam, Content, ErrorCode, ErrorData, GetPromptResult, Prompt, Resource, | ||
| ResourceContents, ServerInfo, Tool, | ||
| }; | ||
| use rmcp::transport::auth::AuthClient; | ||
| use schemars::_private::NoSerialize; | ||
|
|
@@ -713,14 +713,13 @@ impl ExtensionManager { | |
| input_schema: tool.input_schema, | ||
| annotations: tool.annotations, | ||
| output_schema: tool.output_schema, | ||
| icons: None, | ||
| title: None, | ||
| meta: None, | ||
| icons: tool.icons, | ||
| title: tool.title, | ||
| meta: tool.meta, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| // Exit loop when there are no more pages | ||
| if client_tools.next_cursor.is_none() { | ||
| break; | ||
| } | ||
|
|
@@ -773,7 +772,7 @@ impl ExtensionManager { | |
| } | ||
|
|
||
| // Function that gets executed for read_resource tool | ||
| pub async fn read_resource( | ||
| pub async fn read_resource_tool( | ||
| &self, | ||
| params: Value, | ||
| cancellation_token: CancellationToken, | ||
|
|
@@ -784,14 +783,17 @@ impl ExtensionManager { | |
|
|
||
| // If extension name is provided, we can just look it up | ||
| if extension_name.is_some() { | ||
| let result = self | ||
| .read_resource_from_extension( | ||
| uri, | ||
| extension_name.unwrap(), | ||
| cancellation_token.clone(), | ||
| true, | ||
| ) | ||
| let read_result = self | ||
|
Collaborator
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. not your code but |
||
| .read_resource(uri, extension_name.unwrap(), cancellation_token.clone()) | ||
| .await?; | ||
|
|
||
| let mut result = Vec::new(); | ||
| for content in read_result.contents { | ||
| if let ResourceContents::TextResourceContents { text, .. } = content { | ||
| let content_str = format!("{}\n\n{}", uri, text); | ||
| result.push(Content::text(content_str)); | ||
| } | ||
| } | ||
| return Ok(result); | ||
| } | ||
|
|
||
|
|
@@ -804,16 +806,20 @@ impl ExtensionManager { | |
| let extension_names: Vec<String> = self.extensions.lock().await.keys().cloned().collect(); | ||
|
|
||
| for extension_name in extension_names { | ||
| let result = self | ||
| .read_resource_from_extension( | ||
| uri, | ||
| &extension_name, | ||
| cancellation_token.clone(), | ||
| true, | ||
| ) | ||
| let read_result = self | ||
| .read_resource(uri, &extension_name, cancellation_token.clone()) | ||
| .await; | ||
| match result { | ||
| Ok(result) => return Ok(result), | ||
| match read_result { | ||
| Ok(read_result) => { | ||
| let mut result = Vec::new(); | ||
| for content in read_result.contents { | ||
| if let ResourceContents::TextResourceContents { text, .. } = content { | ||
| let content_str = format!("{}\n\n{}", uri, text); | ||
| result.push(Content::text(content_str)); | ||
| } | ||
| } | ||
| return Ok(result); | ||
| } | ||
| Err(_) => continue, | ||
| } | ||
| } | ||
|
|
@@ -839,13 +845,12 @@ impl ExtensionManager { | |
| )) | ||
| } | ||
|
|
||
| async fn read_resource_from_extension( | ||
| pub async fn read_resource( | ||
| &self, | ||
| uri: &str, | ||
| extension_name: &str, | ||
| cancellation_token: CancellationToken, | ||
| format_with_uri: bool, | ||
| ) -> Result<Vec<Content>, ErrorData> { | ||
| ) -> Result<rmcp::model::ReadResourceResult, ErrorData> { | ||
| let available_extensions = self | ||
| .extensions | ||
| .lock() | ||
|
|
@@ -865,7 +870,7 @@ impl ExtensionManager { | |
| .ok_or(ErrorData::new(ErrorCode::INVALID_PARAMS, error_msg, None))?; | ||
|
|
||
| let client_guard = client.lock().await; | ||
| let read_result = client_guard | ||
| client_guard | ||
| .read_resource(uri, cancellation_token) | ||
| .await | ||
| .map_err(|_| { | ||
|
|
@@ -874,21 +879,7 @@ impl ExtensionManager { | |
| format!("Could not read resource with uri: {}", uri), | ||
| None, | ||
| ) | ||
| })?; | ||
|
|
||
| let mut result = Vec::new(); | ||
| for content in read_result.contents { | ||
| if let ResourceContents::TextResourceContents { text, .. } = content { | ||
| let content_str = if format_with_uri { | ||
| format!("{}\n\n{}", uri, text) | ||
| } else { | ||
| text | ||
| }; | ||
| result.push(Content::text(content_str)); | ||
| } | ||
| } | ||
|
|
||
| Ok(result) | ||
| }) | ||
| } | ||
|
|
||
| pub async fn get_ui_resources(&self) -> Result<Vec<(String, Resource)>, ErrorData> { | ||
|
|
@@ -925,31 +916,6 @@ impl ExtensionManager { | |
| Ok(ui_resources) | ||
| } | ||
|
|
||
| pub async fn read_ui_resource( | ||
| &self, | ||
| uri: &str, | ||
| extension_name: &str, | ||
| cancellation_token: CancellationToken, | ||
| ) -> Result<String, ErrorData> { | ||
| let contents = self | ||
| .read_resource_from_extension(uri, extension_name, cancellation_token, false) | ||
| .await?; | ||
|
|
||
| contents | ||
| .into_iter() | ||
| .find_map(|c| match c.raw { | ||
| RawContent::Text(text_content) => Some(text_content.text), | ||
| _ => None, | ||
| }) | ||
| .ok_or_else(|| { | ||
| ErrorData::new( | ||
| ErrorCode::RESOURCE_NOT_FOUND, | ||
| format!("No text content in resource '{}'", uri), | ||
| None, | ||
| ) | ||
| }) | ||
| } | ||
|
|
||
| async fn list_resources_from_extension( | ||
| &self, | ||
| extension_name: &str, | ||
|
|
||
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
Oops, something went wrong.
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.
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.
huh - so will show the tool it is adding?
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.
no, this is just for completion sake. we're not really using icons as far as I can tell, but dropping these values on the floor can only be bad :)