Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions crates/comptrol-core/src/mcp/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#![deny(unsafe_code)]

pub const LEGACY_VERSION: &str = "2025-03-26";
pub const HANDSHAKE_VERSIONS: &[&str] = &[
"2025-11-25",
"2025-06-18",
LEGACY_VERSION,
"2024-11-05",
];
pub const CURRENT_VERSION: &str = "2026-07-28";

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
Expand All @@ -11,17 +17,23 @@ pub enum ProtocolMode {

pub fn negotiate(requested: Option<&str>) -> Result<(&'static str, ProtocolMode), String> {
match requested {
None | Some(LEGACY_VERSION) => Ok((LEGACY_VERSION, ProtocolMode::Legacy)),
Some(CURRENT_VERSION) => Ok((CURRENT_VERSION, ProtocolMode::Current)),
Some(other) => Err(format!("unsupported MCP protocol version {other}")),
Some(version) => HANDSHAKE_VERSIONS
.iter()
.copied()
.find(|supported| *supported == version)
.map(|supported| (supported, ProtocolMode::Legacy))
.ok_or_else(|| format!("unsupported MCP protocol version {version}")),
None => Ok((LEGACY_VERSION, ProtocolMode::Legacy)),
}
}

pub fn from_header(value: Option<&str>) -> Result<ProtocolMode, String> {
match value {
None | Some(LEGACY_VERSION) => Ok(ProtocolMode::Legacy),
Some(CURRENT_VERSION) => Ok(ProtocolMode::Current),
Some(version) if HANDSHAKE_VERSIONS.contains(&version) => Ok(ProtocolMode::Legacy),
Some(other) => Err(format!("unsupported MCP protocol version {other}")),
None => Ok(ProtocolMode::Legacy),
}
}

Expand All @@ -32,10 +44,16 @@ mod tests {
#[test]
fn supports_legacy_and_current_modes_without_accepting_unknown_versions() {
assert_eq!(negotiate(None).unwrap().1, ProtocolMode::Legacy);
for version in HANDSHAKE_VERSIONS {
assert_eq!(negotiate(Some(version)).unwrap(), (*version, ProtocolMode::Legacy));
assert_eq!(from_header(Some(version)).unwrap(), ProtocolMode::Legacy);
}
assert_eq!(
negotiate(Some(CURRENT_VERSION)).unwrap().1,
ProtocolMode::Current
);
assert_eq!(from_header(Some(CURRENT_VERSION)).unwrap(), ProtocolMode::Current);
assert!(negotiate(Some("future")).is_err());
assert!(from_header(Some("future")).is_err());
}
}
2 changes: 1 addition & 1 deletion crates/comptrol-platform-windows/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
mod uia;

#[cfg(windows)]
pub use uia::{Action, Request, SemanticCacheEntry, UiaScopedCache, execute};
pub use uia::{Action, Request, execute};

#[cfg(not(windows))]
pub mod unsupported {
Expand Down
Loading
Loading