Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Support latest MCP protocol version (#54494)

Bennet Bo Fenner24f62484e936
diff --git a/crates/agent/src/tests/mod.rs b/crates/agent/src/tests/mod.rs
index 996e753952b..d9f451f135d 100644
--- a/crates/agent/src/tests/mod.rs
+++ b/crates/agent/src/tests/mod.rs
@@ -1457,6 +1457,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,
@@ -1621,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,
@@ -1742,6 +1744,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",
@@ -1936,6 +1939,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,
@@ -1946,6 +1950,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,
@@ -1961,6 +1966,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,
@@ -1971,6 +1977,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,
@@ -1978,6 +1985,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,
@@ -1985,6 +1993,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,
@@ -1999,6 +2008,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,
@@ -2006,6 +2016,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,
@@ -2013,6 +2024,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,
@@ -2028,6 +2040,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,
@@ -4406,7 +4419,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 261c89e6b80..9948b587f4f 100644
--- a/crates/agent/src/tools/context_server_registry.rs
+++ b/crates/agent/src/tools/context_server_registry.rs
@@ -410,6 +410,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");
+ }
}
}
let raw_output = serde_json::Value::String(concatenated_text);
diff --git a/crates/context_server/src/client.rs b/crates/context_server/src/client.rs
index 676baef9732..1c433d9fd34 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 e7e063efa9d..05a3451ea86 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 2e395e493cc..a9be4c07a26 100644
--- a/crates/context_server/src/listener.rs
+++ b/crates/context_server/src/listener.rs
@@ -103,6 +103,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::<T::Output>() == TypeId::of::<()>() {
diff --git a/crates/context_server/src/protocol.rs b/crates/context_server/src/protocol.rs
index a218a8a3e0e..05082637c27 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<types::ProtocolVersion> {
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 008542ab246..b1e457975f9 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 a3d6f998d49..bffd7e4c4d8 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<Box<dyn Stream<Item = String> + Send>>;
fn receive_err(&self) -> Pin<Box<dyn Stream<Item = String> + 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 47e31c7abc7..bf374586b35 100644
--- a/crates/context_server/src/transport/http.rs
+++ b/crates/context_server/src/transport/http.rs
@@ -9,6 +9,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.
@@ -33,6 +34,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";
@@ -41,6 +43,11 @@ pub struct HttpTransport {
http_client: Arc<dyn HttpClient>,
endpoint: String,
session_id: Arc<SyncMutex<Option<String>>>,
+ /// 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<SyncMutex<Option<String>>>,
executor: BackgroundExecutor,
response_tx: async_channel::Sender<String>,
response_rx: async_channel::Receiver<String>,
@@ -78,6 +85,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,
@@ -114,6 +122,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<Box<dyn Stream<Item = String> + 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 81a427a2893..803f11b4ccd 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<CompletionContext>,
#[serde(rename = "_meta", skip_serializing_if = "Option::is_none")]
pub meta: Option<HashMap<String, serde_json::Value>>,
}
+#[derive(Debug, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CompletionContext {
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub arguments: Option<HashMap<String, String>>,
+}
+
#[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<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[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<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[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<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
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<String>,
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<String>,
}
#[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<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[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<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[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<String>,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ description: Option<String>,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ mime_type: Option<String>,
+ },
}
impl ToolResponseContent {