From 0f1322858b21384dc53e79190f0cd072a9222afe Mon Sep 17 00:00:00 2001 From: Bennet Bo Fenner Date: Wed, 22 Apr 2026 13:01:50 +0200 Subject: [PATCH 1/2] Support latest MCP protocol versions --- crates/agent/src/tests/mod.rs | 14 +++++ .../src/tools/context_server_registry.rs | 3 + crates/context_server/src/client.rs | 7 +++ crates/context_server/src/context_server.rs | 2 + crates/context_server/src/listener.rs | 1 + crates/context_server/src/protocol.rs | 7 +++ crates/context_server/src/test.rs | 2 + crates/context_server/src/transport.rs | 5 ++ crates/context_server/src/transport/http.rs | 30 ++++++++++ crates/context_server/src/types.rs | 55 ++++++++++++++++++- 10 files changed, 125 insertions(+), 1 deletion(-) diff --git a/crates/agent/src/tests/mod.rs b/crates/agent/src/tests/mod.rs index 16952e178aff86..d94b402340d99d 100644 --- a/crates/agent/src/tests/mod.rs +++ b/crates/agent/src/tests/mod.rs @@ -1453,6 +1453,7 @@ async fn test_mcp_tools(cx: &mut TestAppContext) { "test_server", vec![context_server::types::Tool { name: "echo".into(), + title: None, description: None, input_schema: serde_json::to_value(EchoTool::input_schema( LanguageModelToolSchemaFormat::JsonSchema, @@ -1618,6 +1619,7 @@ async fn test_mcp_tool_result_displayed_when_server_disconnected(cx: &mut TestAp "github_server", vec![context_server::types::Tool { name: "issue_read".into(), + title: None, description: Some("Read a GitHub issue".into()), input_schema: json!({ "type": "object", @@ -1812,6 +1814,7 @@ async fn test_mcp_tool_truncation(cx: &mut TestAppContext) { vec![ context_server::types::Tool { name: "echo".into(), // Conflicts with native EchoTool + title: None, description: None, input_schema: serde_json::to_value(EchoTool::input_schema( LanguageModelToolSchemaFormat::JsonSchema, @@ -1822,6 +1825,7 @@ async fn test_mcp_tool_truncation(cx: &mut TestAppContext) { }, context_server::types::Tool { name: "unique_tool_1".into(), + title: None, description: None, input_schema: json!({"type": "object", "properties": {}}), output_schema: None, @@ -1837,6 +1841,7 @@ async fn test_mcp_tool_truncation(cx: &mut TestAppContext) { vec![ context_server::types::Tool { name: "echo".into(), // Also conflicts with native EchoTool + title: None, description: None, input_schema: serde_json::to_value(EchoTool::input_schema( LanguageModelToolSchemaFormat::JsonSchema, @@ -1847,6 +1852,7 @@ async fn test_mcp_tool_truncation(cx: &mut TestAppContext) { }, context_server::types::Tool { name: "unique_tool_2".into(), + title: None, description: None, input_schema: json!({"type": "object", "properties": {}}), output_schema: None, @@ -1854,6 +1860,7 @@ async fn test_mcp_tool_truncation(cx: &mut TestAppContext) { }, context_server::types::Tool { name: "a".repeat(MAX_TOOL_NAME_LENGTH - 2), + title: None, description: None, input_schema: json!({"type": "object", "properties": {}}), output_schema: None, @@ -1861,6 +1868,7 @@ async fn test_mcp_tool_truncation(cx: &mut TestAppContext) { }, context_server::types::Tool { name: "b".repeat(MAX_TOOL_NAME_LENGTH - 1), + title: None, description: None, input_schema: json!({"type": "object", "properties": {}}), output_schema: None, @@ -1875,6 +1883,7 @@ async fn test_mcp_tool_truncation(cx: &mut TestAppContext) { vec![ context_server::types::Tool { name: "a".repeat(MAX_TOOL_NAME_LENGTH - 2), + title: None, description: None, input_schema: json!({"type": "object", "properties": {}}), output_schema: None, @@ -1882,6 +1891,7 @@ async fn test_mcp_tool_truncation(cx: &mut TestAppContext) { }, context_server::types::Tool { name: "b".repeat(MAX_TOOL_NAME_LENGTH - 1), + title: None, description: None, input_schema: json!({"type": "object", "properties": {}}), output_schema: None, @@ -1889,6 +1899,7 @@ async fn test_mcp_tool_truncation(cx: &mut TestAppContext) { }, context_server::types::Tool { name: "c".repeat(MAX_TOOL_NAME_LENGTH + 1), + title: None, description: None, input_schema: json!({"type": "object", "properties": {}}), output_schema: None, @@ -1904,6 +1915,7 @@ async fn test_mcp_tool_truncation(cx: &mut TestAppContext) { "Azure DevOps", vec![context_server::types::Tool { name: "echo".into(), // Also conflicts - will be disambiguated as azure_dev_ops_echo + title: None, description: None, input_schema: serde_json::to_value(EchoTool::input_schema( LanguageModelToolSchemaFormat::JsonSchema, @@ -4291,7 +4303,9 @@ fn setup_context_server( ), server_info: context_server::types::Implementation { name: name.into(), + title: None, version: "1.0.0".to_string(), + description: None, }, capabilities: context_server::types::ServerCapabilities { tools: Some(context_server::types::ToolsCapabilities { diff --git a/crates/agent/src/tools/context_server_registry.rs b/crates/agent/src/tools/context_server_registry.rs index df4cc313036b55..4540bb3edc2307 100644 --- a/crates/agent/src/tools/context_server_registry.rs +++ b/crates/agent/src/tools/context_server_registry.rs @@ -404,6 +404,9 @@ impl AnyAgentTool for ContextServerTool { context_server::types::ToolResponseContent::Resource { .. } => { log::warn!("Ignoring resource content from tool response"); } + context_server::types::ToolResponseContent::ResourceLink { .. } => { + log::warn!("Ignoring resource link content from tool response"); + } } } Ok(AgentToolOutput { diff --git a/crates/context_server/src/client.rs b/crates/context_server/src/client.rs index 974c25d7297719..6c97a5c4e1b255 100644 --- a/crates/context_server/src/client.rs +++ b/crates/context_server/src/client.rs @@ -474,6 +474,13 @@ impl Client { Ok(()) } + /// Notify the underlying transport of the negotiated MCP protocol version + /// so it can stamp subsequent requests (e.g. HTTP's `MCP-Protocol-Version` + /// header required from 2025-06-18 onward). + pub(crate) fn set_protocol_version(&self, version: &str) { + self.transport.set_protocol_version(version); + } + #[must_use] pub fn on_notification( &self, diff --git a/crates/context_server/src/context_server.rs b/crates/context_server/src/context_server.rs index e7e063efa9d6e9..05a3451ea863a3 100644 --- a/crates/context_server/src/context_server.rs +++ b/crates/context_server/src/context_server.rs @@ -138,7 +138,9 @@ impl ContextServer { let protocol = crate::protocol::ModelContextProtocol::new(client); let client_info = types::Implementation { name: "Zed".to_string(), + title: None, version: env!("CARGO_PKG_VERSION").to_string(), + description: None, }; let initialized_protocol = protocol.initialize(client_info).await?; diff --git a/crates/context_server/src/listener.rs b/crates/context_server/src/listener.rs index ad70c6d32e1ef6..bec84f23e5a45a 100644 --- a/crates/context_server/src/listener.rs +++ b/crates/context_server/src/listener.rs @@ -102,6 +102,7 @@ impl McpServer { let registered_tool = RegisteredTool { tool: Tool { name: T::NAME.into(), + title: None, description, input_schema: input_schema.into(), output_schema: if TypeId::of::() == TypeId::of::<()>() { diff --git a/crates/context_server/src/protocol.rs b/crates/context_server/src/protocol.rs index a218a8a3e0e635..05082637c276ff 100644 --- a/crates/context_server/src/protocol.rs +++ b/crates/context_server/src/protocol.rs @@ -27,6 +27,8 @@ impl ModelContextProtocol { fn supported_protocols() -> Vec { vec![ types::ProtocolVersion(types::LATEST_PROTOCOL_VERSION.to_string()), + types::ProtocolVersion(types::VERSION_2025_06_18.to_string()), + types::ProtocolVersion(types::VERSION_2025_03_26.to_string()), types::ProtocolVersion(types::VERSION_2024_11_05.to_string()), ] } @@ -59,6 +61,11 @@ impl ModelContextProtocol { log::trace!("mcp server info {:?}", response.server_info); + // Per MCP 2025-06-18, HTTP transport must attach the negotiated version + // as `MCP-Protocol-Version` on every post-initialize request. + self.inner + .set_protocol_version(&response.protocol_version.0); + let initialized_protocol = InitializedContextServerProtocol { inner: self.inner, initialize: response, diff --git a/crates/context_server/src/test.rs b/crates/context_server/src/test.rs index 008542ab246bc2..b1e457975f916d 100644 --- a/crates/context_server/src/test.rs +++ b/crates/context_server/src/test.rs @@ -27,7 +27,9 @@ fn create_initialize_response(server_name: String) -> InitializeResponse { protocol_version: ProtocolVersion(crate::types::LATEST_PROTOCOL_VERSION.to_string()), server_info: Implementation { name: server_name, + title: None, version: "1.0.0".to_string(), + description: None, }, capabilities: ServerCapabilities::default(), meta: None, diff --git a/crates/context_server/src/transport.rs b/crates/context_server/src/transport.rs index a3d6f998d49872..bffd7e4c4d84a8 100644 --- a/crates/context_server/src/transport.rs +++ b/crates/context_server/src/transport.rs @@ -14,4 +14,9 @@ pub trait Transport: Send + Sync { async fn send(&self, message: String) -> Result<()>; fn receive(&self) -> Pin + Send>>; fn receive_err(&self) -> Pin + Send>>; + + /// Called after the MCP initialize handshake completes so transports that + /// need the negotiated version (currently only HTTP, which must attach an + /// `MCP-Protocol-Version` header from 2025-06-18 onward) can pick it up. + fn set_protocol_version(&self, _version: &str) {} } diff --git a/crates/context_server/src/transport/http.rs b/crates/context_server/src/transport/http.rs index 3e002983b5e490..d0adbd8eb0abb0 100644 --- a/crates/context_server/src/transport/http.rs +++ b/crates/context_server/src/transport/http.rs @@ -10,6 +10,7 @@ use std::{pin::Pin, sync::Arc}; use crate::oauth::{self, OAuthTokenProvider, WwwAuthenticate}; use crate::transport::Transport; +use crate::types; /// Typed errors returned by the HTTP transport that callers can downcast from /// `anyhow::Error` to handle specific failure modes. @@ -34,6 +35,7 @@ impl std::error::Error for TransportError {} // Constants from MCP spec const HEADER_SESSION_ID: &str = "Mcp-Session-Id"; +const HEADER_PROTOCOL_VERSION: &str = "MCP-Protocol-Version"; const EVENT_STREAM_MIME_TYPE: &str = "text/event-stream"; const JSON_MIME_TYPE: &str = "application/json"; @@ -42,6 +44,11 @@ pub struct HttpTransport { http_client: Arc, endpoint: String, session_id: Arc>>, + /// Negotiated MCP protocol version, populated by `set_protocol_version` + /// after the initialize handshake. From 2025-06-18 onward the server + /// requires clients to echo this in the `MCP-Protocol-Version` header on + /// every subsequent request. + protocol_version: Arc>>, executor: BackgroundExecutor, response_tx: channel::Sender, response_rx: channel::Receiver, @@ -79,6 +86,7 @@ impl HttpTransport { executor, endpoint, session_id: Arc::new(SyncMutex::new(None)), + protocol_version: Arc::new(SyncMutex::new(None)), response_tx, response_rx, error_tx, @@ -115,6 +123,14 @@ impl HttpTransport { request_builder = request_builder.header(HEADER_SESSION_ID, session_id.as_str()); } + // Echo the negotiated protocol version once initialization has + // completed. Required by servers speaking MCP 2025-06-18 or later. + if let Some(ref version) = *self.protocol_version.lock() + && types::requires_protocol_version_header(version) + { + request_builder = request_builder.header(HEADER_PROTOCOL_VERSION, version.as_str()); + } + Ok(request_builder.body(AsyncBody::from(message.to_vec()))?) } @@ -315,6 +331,10 @@ impl Transport for HttpTransport { fn receive_err(&self) -> Pin + Send>> { Box::pin(self.error_rx.clone()) } + + fn set_protocol_version(&self, version: &str) { + *self.protocol_version.lock() = Some(version.to_string()); + } } impl Drop for HttpTransport { @@ -323,6 +343,7 @@ impl Drop for HttpTransport { let http_client = self.http_client.clone(); let endpoint = self.endpoint.clone(); let session_id = self.session_id.lock().clone(); + let protocol_version = self.protocol_version.lock().clone(); let headers = self.headers.clone(); let access_token = self.token_provider.as_ref().and_then(|p| p.access_token()); @@ -345,6 +366,15 @@ impl Drop for HttpTransport { request_builder.header("Authorization", format!("Bearer {}", token)); } + // Stamp the negotiated MCP protocol version on the DELETE + // too, matching what `build_request` does for POSTs. + if let Some(ref version) = protocol_version + && types::requires_protocol_version_header(version) + { + request_builder = + request_builder.header(HEADER_PROTOCOL_VERSION, version.as_str()); + } + let request = request_builder.body(AsyncBody::empty()); if let Ok(request) = request { diff --git a/crates/context_server/src/types.rs b/crates/context_server/src/types.rs index 81a427a289347a..803f11b4ccd92f 100644 --- a/crates/context_server/src/types.rs +++ b/crates/context_server/src/types.rs @@ -5,8 +5,16 @@ use url::Url; use crate::client::RequestId; -pub const LATEST_PROTOCOL_VERSION: &str = "2025-03-26"; pub const VERSION_2024_11_05: &str = "2024-11-05"; +pub const VERSION_2025_03_26: &str = "2025-03-26"; +pub const VERSION_2025_06_18: &str = "2025-06-18"; +pub const LATEST_PROTOCOL_VERSION: &str = "2025-11-25"; + +/// Protocol versions that include the streamable HTTP transport's +/// `MCP-Protocol-Version` header requirement on post-initialize requests. +pub fn requires_protocol_version_header(version: &str) -> bool { + matches!(version, VERSION_2025_06_18 | LATEST_PROTOCOL_VERSION) +} pub mod requests { use super::*; @@ -209,10 +217,21 @@ pub struct CompletionCompleteParams { #[serde(rename = "ref")] pub reference: CompletionReference, pub argument: CompletionArgument, + /// Previously-resolved argument values so the server can provide + /// context-sensitive completions (added in MCP 2025-06-18). + #[serde(skip_serializing_if = "Option::is_none")] + pub context: Option, #[serde(rename = "_meta", skip_serializing_if = "Option::is_none")] pub meta: Option>, } +#[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct CompletionContext { + #[serde(skip_serializing_if = "Option::is_none")] + pub arguments: Option>, +} + #[derive(Debug, Serialize, Deserialize)] #[serde(untagged)] pub enum CompletionReference { @@ -421,6 +440,9 @@ pub struct CompletionResult { #[serde(rename_all = "camelCase")] pub struct Prompt { pub name: String, + /// Human-readable display name (added in MCP 2025-06-18). + #[serde(skip_serializing_if = "Option::is_none")] + pub title: Option, #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -431,6 +453,9 @@ pub struct Prompt { #[serde(rename_all = "camelCase")] pub struct PromptArgument { pub name: String, + /// Human-readable display name (added in MCP 2025-06-18). + #[serde(skip_serializing_if = "Option::is_none")] + pub title: Option, #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -499,6 +524,9 @@ pub struct RootsCapabilities { #[serde(rename_all = "camelCase")] pub struct Tool { pub name: String, + /// Human-readable display name (added in MCP 2025-06-18). + #[serde(skip_serializing_if = "Option::is_none")] + pub title: Option, #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, pub input_schema: serde_json::Value, @@ -532,7 +560,13 @@ pub struct ToolAnnotations { #[serde(rename_all = "camelCase")] pub struct Implementation { pub name: String, + /// Human-readable display name (added in MCP 2025-06-18). + #[serde(skip_serializing_if = "Option::is_none")] + pub title: Option, pub version: String, + /// Human-readable description of the implementation (added in MCP 2025-11-25). + #[serde(skip_serializing_if = "Option::is_none")] + pub description: Option, } #[derive(Debug, Serialize, Deserialize)] @@ -540,6 +574,9 @@ pub struct Implementation { pub struct Resource { pub uri: Url, pub name: String, + /// Human-readable display name (added in MCP 2025-06-18). + #[serde(skip_serializing_if = "Option::is_none")] + pub title: Option, #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -577,6 +614,9 @@ pub struct BlobResourceContents { pub struct ResourceTemplate { pub uri_template: String, pub name: String, + /// Human-readable display name (added in MCP 2025-06-18). + #[serde(skip_serializing_if = "Option::is_none")] + pub title: Option, #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -709,6 +749,19 @@ pub enum ToolResponseContent { Audio { data: String, mime_type: String }, #[serde(rename = "resource")] Resource { resource: ResourceContents }, + /// Link to an MCP resource on the server, without inlining its contents. + /// Added in MCP 2025-06-18. + #[serde(rename = "resource_link", rename_all = "camelCase")] + ResourceLink { + uri: Url, + name: String, + #[serde(skip_serializing_if = "Option::is_none")] + title: Option, + #[serde(skip_serializing_if = "Option::is_none")] + description: Option, + #[serde(skip_serializing_if = "Option::is_none")] + mime_type: Option, + }, } impl ToolResponseContent { From b206c356e7b61f03bcdc1dd1be3cc1abe98fd3cd Mon Sep 17 00:00:00 2001 From: Bennet Bo Fenner Date: Wed, 29 Apr 2026 18:05:54 +0200 Subject: [PATCH 2/2] Update mod.rs --- crates/agent/src/tests/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/agent/src/tests/mod.rs b/crates/agent/src/tests/mod.rs index eff52014e0717d..d9f451f135d6bf 100644 --- a/crates/agent/src/tests/mod.rs +++ b/crates/agent/src/tests/mod.rs @@ -1622,6 +1622,7 @@ async fn test_mcp_tool_multi_content_response(cx: &mut TestAppContext) { "screenshot_server", vec![context_server::types::Tool { name: "screenshot".into(), + title: None, description: None, input_schema: json!({"type": "object", "properties": {}}), output_schema: None,