CI / Rust Checks (pull_request) Failing after 13m41s
CI / UI Checks (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Deploy (pull_request) Skipped
Community Release / release (push) Failing after 13m33s
Recovery delivery of the accumulated, TL-accepted Epic 3 work that had never been
committed to Git (stories 3.6-3.17, see the crank board). Story 3.18 is not accepted
yet and is deliberately excluded: its logging surface, its capability registration,
its oracle projections and its tests are not part of this tree.
Accepted scope
- 3.6 typed static Resource Drafts; 3.7 publication and exact binding of static
Resource Versions; 3.8 MCP discovery/read and revocation of static Resources;
- 3.9 Resource import/export in API and UI plus TLS dependency maintenance;
3.10 REST-backed Resource templates; 3.11 shared REST read runtime and the MCP
revision/capability foundation;
- 3.12 parameterised Prompt Drafts with preview; 3.13 Prompt publication and exact
version binding to Agents; 3.14 MCP prompts; 3.15 Prompt import/export;
- 3.16 composite Prompts with published Resources (dependency content scan plus
dynamic read through the accepted 3.11 runtime, admin preview and MCP prompts/get);
- 3.17 bounded MCP completion suggestions from typed published schemas and the
resources/list admission fix for bound template publications.
Accepted evidence being reused (unchanged code paths)
- 3.16 candidate: core 7, admin-api 22, registry 4, mcp-server 4, UI 6; one final
`just verify` run 1651 passed / 0 failed / 2 ignored.
- 3.17 candidate: full run 1672 passed / 0 failed / 2 ignored, QA targeted reruns and
a real MCP Inspector 2.12.0 client smoke.
Delivery engineering in this commit
- CI: one event per change (feature branches are gated by their pull request, push
runs only on main), story events run the changed packages, the full workspace suite
stays the feature/release gate; no cache/sharding without a measured runner check.
- Release: the packaged archives, checksums and SBOM are now uploaded to the Gitea
release entry of the tag instead of dying with the runner workspace.
Not included on purpose: Story 3.18 work, build caches, runtime databases, local
credentials and scratch evidence.
Refs: crank kanban t_e39d7263; baseline 1b6db09bd1.
891 lines
30 KiB
Rust
891 lines
30 KiB
Rust
//! Revision negotiation on the real endpoint: modern stateless discovery, legacy
|
|
//! initialize/tools-list, withdrawn revisions, unknown/mismatched/missing identity, the negative
|
|
//! "no experimental surface" oracle and the minimal client.
|
|
//!
|
|
//! Tests moved verbatim from `revision_matrix.rs` (Story 3.6, kanban t_987bf309); only the module
|
|
//! prefix changed.
|
|
|
|
use super::super::common::*;
|
|
use axum::http::header;
|
|
use serde_json::{Value, json};
|
|
|
|
use super::harness::{
|
|
LEGACY_REVISION, META_CLIENT_CAPABILITIES, META_CLIENT_INFO, META_PROTOCOL_VERSION,
|
|
MODERN_REVISION, UNKNOWN_REVISION, approved_revisions, endpoint, fixture, json_body,
|
|
modern_headers, modern_meta, modern_post, modern_request, modern_request_with_params,
|
|
oracle_status, require_modern_result_type, tools_list_request, wire_case,
|
|
};
|
|
/// Exact-descriptor assertion driven by an independent projection fixture
|
|
/// (`expected-advertised-capabilities.json`): the current scope may advertise exactly what is
|
|
/// implemented, and deferred capabilities must not appear. A generic official-key allowlist would
|
|
/// not prove that (TL finding on the descriptor oracle).
|
|
fn assert_advertised_descriptor(capabilities: &serde_json::Map<String, Value>, body: &Value) {
|
|
let expected = fixture("expected-advertised-capabilities.json");
|
|
|
|
let mut expected_keys: Vec<String> = expected["expected_keys"]
|
|
.as_array()
|
|
.unwrap()
|
|
.iter()
|
|
.filter_map(Value::as_str)
|
|
.map(str::to_owned)
|
|
.collect();
|
|
expected_keys.sort();
|
|
|
|
let mut actual_keys: Vec<String> = capabilities.keys().cloned().collect();
|
|
actual_keys.sort();
|
|
assert_eq!(
|
|
actual_keys, expected_keys,
|
|
"the advertised descriptor must equal the implemented current scope, got {body}"
|
|
);
|
|
|
|
for forbidden in expected["must_not_be_advertised"].as_array().unwrap() {
|
|
let key = forbidden.as_str().unwrap();
|
|
assert!(
|
|
!capabilities.contains_key(key),
|
|
"capability {key:?} is not implemented in the current scope and must not be advertised, got {body}"
|
|
);
|
|
}
|
|
|
|
// R8: compare the subfeatures as well, not only the key set.
|
|
let expected_descriptor = expected["expected_descriptor"]
|
|
.as_object()
|
|
.expect("the projection fixture must carry the expected descriptor");
|
|
assert_eq!(
|
|
&Value::Object(capabilities.clone()),
|
|
&Value::Object(expected_descriptor.clone()),
|
|
"advertised subfeatures must equal the independent golden descriptor, got {body}"
|
|
);
|
|
}
|
|
|
|
fn header_refs<'a>(headers: &'a [(&'static str, String)]) -> Vec<(&'static str, &'a str)> {
|
|
headers
|
|
.iter()
|
|
.map(|(name, value)| (*name, value.as_str()))
|
|
.collect()
|
|
}
|
|
|
|
fn initialize_request(revision: &str) -> Value {
|
|
json!({
|
|
"jsonrpc": "2.0",
|
|
"id": 1,
|
|
"method": "initialize",
|
|
"params": { "protocolVersion": revision, "capabilities": {} }
|
|
})
|
|
}
|
|
|
|
/// AT-3.1-04: the modern stateless revision is served and `server/discover` is mandatory.
|
|
///
|
|
/// Golden coverage from the pinned schema: exact `supportedVersions`, `serverInfo`, revision-correct
|
|
/// `resultType` handling, cache hints, and the complete advertised capability descriptor (no
|
|
/// experimental or extension surface in the current scope). One positive status alone is **not**
|
|
/// treated as full AC-04 evidence.
|
|
#[tokio::test]
|
|
async fn at_3_1_04_modern_discover_is_served_without_a_session() {
|
|
let endpoint = endpoint().await;
|
|
let expected = oracle_status("wm-01");
|
|
assert_eq!(expected, 200);
|
|
|
|
let headers = modern_headers(MODERN_REVISION, "server/discover");
|
|
let response = post_jsonrpc_with_headers(
|
|
&endpoint.client,
|
|
&endpoint.mcp_url,
|
|
&endpoint.api_key,
|
|
&header_refs(&headers),
|
|
modern_request(15, "server/discover", MODERN_REVISION, true),
|
|
)
|
|
.await;
|
|
|
|
assert_eq!(
|
|
response.status().as_u16(),
|
|
expected,
|
|
"modern `server/discover` must be served"
|
|
);
|
|
assert!(
|
|
response.headers().get("MCP-Session-Id").is_none(),
|
|
"the modern stateless era must not mint a session"
|
|
);
|
|
|
|
let body = json_body(response).await;
|
|
let result = &body["result"];
|
|
|
|
let mut supported: Vec<String> = result["supportedVersions"]
|
|
.as_array()
|
|
.cloned()
|
|
.unwrap_or_default()
|
|
.iter()
|
|
.filter_map(Value::as_str)
|
|
.map(str::to_owned)
|
|
.collect();
|
|
supported.sort();
|
|
let mut approved = approved_revisions();
|
|
approved.sort();
|
|
assert_eq!(
|
|
supported, approved,
|
|
"discover must advertise exactly the approved revisions, got {body}"
|
|
);
|
|
|
|
// Pinned `DiscoverResult` places the server identity inside `result._meta`, not on the result
|
|
// object itself; the pinned prose makes it a SHOULD for the server to include it.
|
|
let server_info = &result["_meta"]["io.modelcontextprotocol/serverInfo"];
|
|
assert!(
|
|
server_info["name"].is_string() && server_info["version"].is_string(),
|
|
"discover must return `_meta['io.modelcontextprotocol/serverInfo']` with name and version, got {body}"
|
|
);
|
|
assert!(
|
|
result.get("serverInfo").is_none(),
|
|
"serverInfo must not be projected onto the result object itself, got {body}"
|
|
);
|
|
// The pinned revision treats an absent resultType as "complete".
|
|
assert!(
|
|
result.get("resultType").is_none() || result["resultType"] == json!("complete"),
|
|
"resultType must be absent or `complete` for a successful discover, got {body}"
|
|
);
|
|
// `ttlMs` and `cacheScope` are non-optional fields of the pinned `CacheableResult` that
|
|
// `DiscoverResult` extends, and both appear in the pinned discover example.
|
|
assert!(
|
|
result["ttlMs"].is_u64(),
|
|
"discover must carry the required cache TTL hint, got {body}"
|
|
);
|
|
assert!(
|
|
matches!(result["cacheScope"].as_str(), Some("public" | "private")),
|
|
"discover must carry the required cache scope, got {body}"
|
|
);
|
|
|
|
let capabilities = result["capabilities"]
|
|
.as_object()
|
|
.unwrap_or_else(|| panic!("capabilities must be an object, got {body}"));
|
|
assert_advertised_descriptor(capabilities, &body);
|
|
}
|
|
|
|
/// AT-3.1-04: a second, independent modern request is served without discover/session priming.
|
|
#[tokio::test]
|
|
async fn at_3_1_04_modern_request_is_served_without_priming() {
|
|
let endpoint = endpoint().await;
|
|
|
|
let headers = modern_headers(MODERN_REVISION, "tools/list");
|
|
let response = post_jsonrpc_with_headers(
|
|
&endpoint.client,
|
|
&endpoint.mcp_url,
|
|
&endpoint.api_key,
|
|
&header_refs(&headers),
|
|
modern_request(16, "tools/list", MODERN_REVISION, true),
|
|
)
|
|
.await;
|
|
|
|
assert_eq!(
|
|
response.status().as_u16(),
|
|
200,
|
|
"a complete modern request must be served without priming"
|
|
);
|
|
assert!(response.headers().get("MCP-Session-Id").is_none());
|
|
|
|
let body = json_body(response).await;
|
|
assert_eq!(body["result"]["tools"][0]["name"], "crm_create_lead");
|
|
}
|
|
|
|
/// AT-3.1-05: the legacy `2025-11-25` session lifecycle keeps working (existing correct behaviour).
|
|
#[tokio::test]
|
|
async fn at_3_1_05_legacy_initialize_and_tools_list_stay_green() {
|
|
let endpoint = endpoint().await;
|
|
assert_eq!(oracle_status("wm-06"), 200);
|
|
|
|
let session = initialize_session(&endpoint.client, &endpoint.mcp_url, &endpoint.api_key).await;
|
|
let tools = post_jsonrpc(
|
|
&endpoint.client,
|
|
&endpoint.mcp_url,
|
|
&endpoint.api_key,
|
|
Some(&session),
|
|
tools_list_request(2),
|
|
)
|
|
.await;
|
|
|
|
assert_eq!(tools["result"]["tools"][0]["name"], "crm_create_lead");
|
|
}
|
|
|
|
/// AT-3.1-02: the withdrawn `2025-03-26` revision is rejected and mints no session.
|
|
#[tokio::test]
|
|
async fn at_3_1_02_withdrawn_2025_03_26_initialize_is_rejected() {
|
|
let endpoint = endpoint().await;
|
|
let expected = oracle_status("wm-10");
|
|
|
|
let response = post_jsonrpc_with_headers(
|
|
&endpoint.client,
|
|
&endpoint.mcp_url,
|
|
&endpoint.api_key,
|
|
&[],
|
|
initialize_request("2025-03-26"),
|
|
)
|
|
.await;
|
|
|
|
assert_eq!(
|
|
response.status().as_u16(),
|
|
expected,
|
|
"a withdrawn revision must be rejected with {expected}"
|
|
);
|
|
assert!(
|
|
response.headers().get("MCP-Session-Id").is_none(),
|
|
"a rejected revision must not mint a session"
|
|
);
|
|
}
|
|
|
|
/// AT-3.1-02: the withdrawn `2025-06-18` revision is rejected as well.
|
|
#[tokio::test]
|
|
async fn at_3_1_02_withdrawn_2025_06_18_initialize_is_rejected() {
|
|
let endpoint = endpoint().await;
|
|
let expected = oracle_status("wm-11");
|
|
|
|
let response = post_jsonrpc_with_headers(
|
|
&endpoint.client,
|
|
&endpoint.mcp_url,
|
|
&endpoint.api_key,
|
|
&[],
|
|
initialize_request("2025-06-18"),
|
|
)
|
|
.await;
|
|
|
|
assert_eq!(
|
|
response.status().as_u16(),
|
|
expected,
|
|
"a withdrawn revision must be rejected with {expected}"
|
|
);
|
|
assert!(
|
|
response.headers().get("MCP-Session-Id").is_none(),
|
|
"a rejected revision must not mint a session"
|
|
);
|
|
}
|
|
|
|
/// AT-3.1-06 (wm-05): an unknown revision, identical in header and body, yields `-32022` with the
|
|
/// supported list. All other required metadata stays valid, so this is a single-fault case.
|
|
#[tokio::test]
|
|
async fn at_3_1_06_unsupported_version_yields_structured_error() {
|
|
let endpoint = endpoint().await;
|
|
let case = wire_case("wm-05");
|
|
assert_eq!(case["expected_error"], "UnsupportedProtocolVersion");
|
|
|
|
let headers = modern_headers(UNKNOWN_REVISION, "tools/list");
|
|
let response = post_jsonrpc_with_headers(
|
|
&endpoint.client,
|
|
&endpoint.mcp_url,
|
|
&endpoint.api_key,
|
|
&header_refs(&headers),
|
|
modern_request(17, "tools/list", UNKNOWN_REVISION, true),
|
|
)
|
|
.await;
|
|
|
|
assert_eq!(response.status().as_u16(), 400);
|
|
|
|
let body = json_body(response).await;
|
|
assert_eq!(
|
|
body["error"]["code"], -32022,
|
|
"unknown revision must use the era-correct error code, got {body}"
|
|
);
|
|
let mut supported: Vec<String> = body["error"]["data"]["supported"]
|
|
.as_array()
|
|
.cloned()
|
|
.unwrap_or_default()
|
|
.iter()
|
|
.filter_map(Value::as_str)
|
|
.map(str::to_owned)
|
|
.collect();
|
|
supported.sort();
|
|
let mut approved = approved_revisions();
|
|
approved.sort();
|
|
assert_eq!(
|
|
supported, approved,
|
|
"the error must advertise exactly the supported revisions, got {body}"
|
|
);
|
|
}
|
|
|
|
/// AT-3.1-06 (wm-02): a known version in the header that differs from the body version is a
|
|
/// mismatch (`-32020`), not an unsupported-version error.
|
|
#[tokio::test]
|
|
async fn at_3_1_06_header_body_version_mismatch_is_rejected() {
|
|
let endpoint = endpoint().await;
|
|
let case = wire_case("wm-02");
|
|
assert_eq!(case["expected_error"], "HeaderMismatch");
|
|
|
|
let headers = modern_headers(MODERN_REVISION, "tools/list");
|
|
let response = post_jsonrpc_with_headers(
|
|
&endpoint.client,
|
|
&endpoint.mcp_url,
|
|
&endpoint.api_key,
|
|
&header_refs(&headers),
|
|
modern_request(18, "tools/list", LEGACY_REVISION, true),
|
|
)
|
|
.await;
|
|
|
|
assert_eq!(response.status().as_u16(), 400);
|
|
|
|
let body = json_body(response).await;
|
|
assert_eq!(
|
|
body["error"]["code"], -32020,
|
|
"a header/body version mismatch must use the header-mismatch code, got {body}"
|
|
);
|
|
}
|
|
|
|
/// AT-3.1-06 (wm-03): a modern header without the required body `_meta` is rejected.
|
|
#[tokio::test]
|
|
async fn at_3_1_06_modern_header_without_required_meta_is_rejected() {
|
|
let endpoint = endpoint().await;
|
|
assert_eq!(oracle_status("wm-03"), 400);
|
|
|
|
let headers = modern_headers(MODERN_REVISION, "tools/list");
|
|
let response = post_jsonrpc_with_headers(
|
|
&endpoint.client,
|
|
&endpoint.mcp_url,
|
|
&endpoint.api_key,
|
|
&header_refs(&headers),
|
|
modern_request(19, "tools/list", MODERN_REVISION, false),
|
|
)
|
|
.await;
|
|
|
|
assert_eq!(
|
|
response.status().as_u16(),
|
|
400,
|
|
"a modern header without the required body metadata must be rejected"
|
|
);
|
|
assert!(response.headers().get("MCP-Session-Id").is_none());
|
|
}
|
|
|
|
/// AT-3.1-06 (wm-04): an incomplete `_meta` (missing required client capabilities) is rejected.
|
|
#[tokio::test]
|
|
async fn at_3_1_06_modern_request_without_required_metadata_is_rejected() {
|
|
let endpoint = endpoint().await;
|
|
assert_eq!(oracle_status("wm-04"), 400);
|
|
|
|
let headers = modern_headers(MODERN_REVISION, "tools/list");
|
|
let incomplete = json!({
|
|
"jsonrpc": "2.0",
|
|
"id": 20,
|
|
"method": "tools/list",
|
|
"params": { "_meta": { META_PROTOCOL_VERSION: MODERN_REVISION } }
|
|
});
|
|
|
|
let response = post_jsonrpc_with_headers(
|
|
&endpoint.client,
|
|
&endpoint.mcp_url,
|
|
&endpoint.api_key,
|
|
&header_refs(&headers),
|
|
incomplete,
|
|
)
|
|
.await;
|
|
|
|
assert_eq!(
|
|
response.status().as_u16(),
|
|
400,
|
|
"missing required client capabilities must be rejected"
|
|
);
|
|
}
|
|
|
|
/// AT-3.1-06 / AT-3.1-02 (wm-12): a legacy `initialize` with an unknown revision must not mint a
|
|
/// session, must not return a successful initialize result, and must never echo the withdrawn
|
|
/// `2025-03-26` as the served identity.
|
|
///
|
|
/// The pinned legacy prose does not pin an HTTP status for an unsupported *body* version on
|
|
/// `initialize`, so this case deliberately asserts behaviour instead of guessing a status code.
|
|
#[tokio::test]
|
|
async fn at_3_1_06_legacy_initialize_unknown_revision_is_rejected() {
|
|
let endpoint = endpoint().await;
|
|
let case = wire_case("wm-12");
|
|
assert_eq!(case["expected"], "no_session_and_no_withdrawn_identity");
|
|
assert_eq!(case["status_not_pinned"], true);
|
|
|
|
let response = post_jsonrpc_with_headers(
|
|
&endpoint.client,
|
|
&endpoint.mcp_url,
|
|
&endpoint.api_key,
|
|
&[],
|
|
initialize_request(UNKNOWN_REVISION),
|
|
)
|
|
.await;
|
|
|
|
let status = response.status();
|
|
let echoed = response
|
|
.headers()
|
|
.get("MCP-Protocol-Version")
|
|
.map(|value| value.to_str().unwrap().to_owned());
|
|
let session_header = response.headers().get("MCP-Session-Id").is_some();
|
|
|
|
assert!(
|
|
!session_header,
|
|
"an unknown revision must not mint a session"
|
|
);
|
|
assert_ne!(
|
|
echoed.as_deref(),
|
|
Some("2025-03-26"),
|
|
"the withdrawn revision must never be echoed as the served identity"
|
|
);
|
|
|
|
let body = json_body(response).await;
|
|
if status.is_success() {
|
|
assert!(
|
|
body["error"].is_object(),
|
|
"a 2xx response for an unknown revision must still carry a JSON-RPC error, got {body}"
|
|
);
|
|
assert!(
|
|
body["result"].is_null(),
|
|
"an unknown revision must not produce an initialize result, got {body}"
|
|
);
|
|
}
|
|
}
|
|
|
|
/// AT-3.1-06 (wm-13) / AT-3.1-02: an authenticated request that carries no identity at all
|
|
/// (no initialization, no verified session, no version header, no `_meta`) must fail instead of
|
|
/// being served as a withdrawn revision. This replaces the earlier internal-constant assertion.
|
|
#[tokio::test]
|
|
async fn at_3_1_06_request_without_any_identity_is_rejected() {
|
|
let endpoint = endpoint().await;
|
|
assert_eq!(oracle_status("wm-13"), 400);
|
|
|
|
let response = post_jsonrpc_with_headers(
|
|
&endpoint.client,
|
|
&endpoint.mcp_url,
|
|
&endpoint.api_key,
|
|
&[],
|
|
tools_list_request(21),
|
|
)
|
|
.await;
|
|
|
|
assert_eq!(
|
|
response.status().as_u16(),
|
|
400,
|
|
"a request without any protocol identity must be rejected"
|
|
);
|
|
assert!(
|
|
response.headers().get("MCP-Session-Id").is_none(),
|
|
"an unidentified request must not mint a session"
|
|
);
|
|
let echoed = response
|
|
.headers()
|
|
.get("MCP-Protocol-Version")
|
|
.map(|value| value.to_str().unwrap().to_owned());
|
|
assert_ne!(
|
|
echoed.as_deref(),
|
|
Some("2025-03-26"),
|
|
"the withdrawn revision must never be echoed as the served identity"
|
|
);
|
|
}
|
|
|
|
/// AT-3.1-09 (advertisement half): the negotiated capability descriptor never contains an
|
|
/// experimental or extension surface, and unknown RPC/extension methods are not dispatchable.
|
|
#[tokio::test]
|
|
async fn at_3_1_09_no_extension_surface_is_advertised_or_dispatched() {
|
|
let endpoint = endpoint().await;
|
|
let session = initialize_session(&endpoint.client, &endpoint.mcp_url, &endpoint.api_key).await;
|
|
|
|
// 1. the actual negotiated capabilities from the real initialize response
|
|
let capabilities_response = endpoint
|
|
.client
|
|
.post(&endpoint.mcp_url)
|
|
.header(header::ACCEPT, "application/json, text/event-stream")
|
|
.header(
|
|
header::AUTHORIZATION,
|
|
format!("Bearer {}", endpoint.api_key),
|
|
)
|
|
.json(&initialize_request(LEGACY_REVISION))
|
|
.send()
|
|
.await
|
|
.unwrap();
|
|
let capabilities_body = json_body(capabilities_response).await;
|
|
let advertised = capabilities_body["result"]["capabilities"]
|
|
.as_object()
|
|
.cloned()
|
|
.unwrap_or_default();
|
|
|
|
assert_advertised_descriptor(&advertised, &capabilities_body);
|
|
|
|
// 2. an unknown extension method must not be dispatchable
|
|
let unknown_method = post_jsonrpc(
|
|
&endpoint.client,
|
|
&endpoint.mcp_url,
|
|
&endpoint.api_key,
|
|
Some(&session),
|
|
json!({
|
|
"jsonrpc": "2.0",
|
|
"id": 30,
|
|
"method": "io.modelcontextprotocol/tasks/list",
|
|
"params": {}
|
|
}),
|
|
)
|
|
.await;
|
|
assert!(
|
|
unknown_method["error"].is_object(),
|
|
"an unknown extension method must be rejected, got {unknown_method}"
|
|
);
|
|
|
|
// 3. a name that is not a registered tool must not be dispatched
|
|
let denied = post_jsonrpc(
|
|
&endpoint.client,
|
|
&endpoint.mcp_url,
|
|
&endpoint.api_key,
|
|
Some(&session),
|
|
json!({
|
|
"jsonrpc": "2.0",
|
|
"id": 31,
|
|
"method": "tools/call",
|
|
"params": { "name": "experimental_unknown_extension", "arguments": {} }
|
|
}),
|
|
)
|
|
.await;
|
|
assert!(
|
|
denied["error"].is_object(),
|
|
"an unregistered identifier must be denied, got {denied}"
|
|
);
|
|
}
|
|
|
|
/// AT-3.1-10: a minimal client that declares no optional capabilities still lists and calls Tools.
|
|
#[tokio::test]
|
|
async fn at_3_1_10_minimal_client_still_lists_and_calls_tools() {
|
|
let endpoint = endpoint().await;
|
|
|
|
let session = initialize_session_with_capabilities(
|
|
&endpoint.client,
|
|
&endpoint.mcp_url,
|
|
&endpoint.api_key,
|
|
json!({}),
|
|
)
|
|
.await;
|
|
|
|
let tools = post_jsonrpc(
|
|
&endpoint.client,
|
|
&endpoint.mcp_url,
|
|
&endpoint.api_key,
|
|
Some(&session),
|
|
tools_list_request(22),
|
|
)
|
|
.await;
|
|
assert_eq!(tools["result"]["tools"][0]["name"], "crm_create_lead");
|
|
|
|
let call = post_jsonrpc(
|
|
&endpoint.client,
|
|
&endpoint.mcp_url,
|
|
&endpoint.api_key,
|
|
Some(&session),
|
|
json!({
|
|
"jsonrpc": "2.0",
|
|
"id": 23,
|
|
"method": "tools/call",
|
|
"params": {
|
|
"name": "crm_create_lead",
|
|
"arguments": { "email": "minimal@example.com" }
|
|
}
|
|
}),
|
|
)
|
|
.await;
|
|
assert_eq!(
|
|
call["result"]["structuredContent"],
|
|
json!({ "id": "lead_123" })
|
|
);
|
|
}
|
|
|
|
/// R2: each **required** modern metadata carrier is validated independently (single-fault cases).
|
|
/// The optional `clientInfo` is covered by the corrected oracle below (review pass 6, P4).
|
|
#[tokio::test]
|
|
async fn r2_modern_missing_body_version_is_rejected() {
|
|
let endpoint = endpoint().await;
|
|
let headers = modern_headers(MODERN_REVISION, "tools/list");
|
|
let mut meta = modern_meta(MODERN_REVISION);
|
|
meta.as_object_mut().unwrap().remove(META_PROTOCOL_VERSION);
|
|
|
|
let response = modern_post(
|
|
&endpoint,
|
|
&headers,
|
|
modern_request_with_params(Some(50), "tools/list", json!({ "_meta": meta })),
|
|
None,
|
|
)
|
|
.await;
|
|
|
|
assert_eq!(response.status().as_u16(), 400);
|
|
assert!(response.headers().get("MCP-Session-Id").is_none());
|
|
let body = json_body(response).await;
|
|
assert!(body["error"].is_object(), "got {body}");
|
|
assert!(body["result"].is_null(), "got {body}");
|
|
}
|
|
|
|
/// R2 (corrected in review pass 6, P4): `clientInfo` is **optional** in the pinned modern request
|
|
/// metadata. `RequestMetaObject` declares it as `"io.modelcontextprotocol/clientInfo"?:
|
|
/// Implementation` and its prose says clients **SHOULD** include it unless specifically configured
|
|
/// not to, while `protocolVersion` and `clientCapabilities` are declared required
|
|
/// (`build/review6/pinned-modern-schema.ts:63-98`, pinned by SHA-256
|
|
/// `742750af0bb8c716e7030c4977c992b55d1adc4407e9e66997db5846baedc2cd`).
|
|
///
|
|
/// The earlier derived oracle promoted that SHOULD to a MUST: `validate_modern_metadata`
|
|
/// (`protocol/mod.rs` 516-533) rejects an absent `clientInfo`, so a source-correct modern request is
|
|
/// refused today. Correcting this invalid oracle is **not** permission to relax the required
|
|
/// metadata: a `clientInfo` that is present but malformed (wrong type, or missing `name`/`version`)
|
|
/// is still rejected, and those cases stay asserted separately above.
|
|
#[tokio::test]
|
|
async fn r2_modern_request_without_optional_client_info_is_served() {
|
|
let endpoint = endpoint().await;
|
|
let headers = modern_headers(MODERN_REVISION, "tools/list");
|
|
let mut meta = modern_meta(MODERN_REVISION);
|
|
meta.as_object_mut().unwrap().remove(META_CLIENT_INFO);
|
|
|
|
let response = modern_post(
|
|
&endpoint,
|
|
&headers,
|
|
modern_request_with_params(Some(51), "tools/list", json!({ "_meta": meta })),
|
|
None,
|
|
)
|
|
.await;
|
|
|
|
assert_eq!(
|
|
response.status().as_u16(),
|
|
200,
|
|
"a modern request whose only deviation is the omitted **optional** `clientInfo` must be \
|
|
served (pinned `RequestMetaObject` marks it optional)"
|
|
);
|
|
let body = json_body(response).await;
|
|
assert!(
|
|
body["error"].is_null(),
|
|
"omitting the optional `clientInfo` must not produce a JSON-RPC error, got {body}"
|
|
);
|
|
assert_eq!(
|
|
body["result"]["tools"][0]["name"], "crm_create_lead",
|
|
"the served result must keep the published tool payload, got {body}"
|
|
);
|
|
require_modern_result_type(&body["result"], "tools/list (without clientInfo)");
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn r2_modern_client_info_without_name_or_version_is_rejected() {
|
|
let endpoint = endpoint().await;
|
|
let headers = modern_headers(MODERN_REVISION, "tools/list");
|
|
|
|
for incomplete in [json!({}), json!({ "name": "crank-atdd-client" })] {
|
|
let mut meta = modern_meta(MODERN_REVISION);
|
|
meta[META_CLIENT_INFO] = incomplete.clone();
|
|
|
|
let response = modern_post(
|
|
&endpoint,
|
|
&headers,
|
|
modern_request_with_params(Some(52), "tools/list", json!({ "_meta": meta })),
|
|
None,
|
|
)
|
|
.await;
|
|
|
|
assert_eq!(
|
|
response.status().as_u16(),
|
|
400,
|
|
"clientInfo {incomplete} must be rejected"
|
|
);
|
|
}
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn r2_modern_client_info_or_capabilities_of_wrong_type_are_rejected() {
|
|
let endpoint = endpoint().await;
|
|
let headers = modern_headers(MODERN_REVISION, "tools/list");
|
|
|
|
for (key, value) in [
|
|
(META_CLIENT_INFO, json!("not-an-object")),
|
|
(META_CLIENT_CAPABILITIES, json!("not-an-object")),
|
|
] {
|
|
let mut meta = modern_meta(MODERN_REVISION);
|
|
meta[key] = value.clone();
|
|
|
|
let response = modern_post(
|
|
&endpoint,
|
|
&headers,
|
|
modern_request_with_params(Some(53), "tools/list", json!({ "_meta": meta })),
|
|
None,
|
|
)
|
|
.await;
|
|
|
|
assert_eq!(
|
|
response.status().as_u16(),
|
|
400,
|
|
"{key} with value {value} must be rejected"
|
|
);
|
|
}
|
|
}
|
|
|
|
/// R2: body-only modern identity without the required version header must be rejected.
|
|
#[tokio::test]
|
|
async fn r2_modern_identity_without_version_header_is_rejected() {
|
|
let endpoint = endpoint().await;
|
|
let headers = vec![("Mcp-Method", "tools/list".to_owned())];
|
|
|
|
let response = modern_post(
|
|
&endpoint,
|
|
&headers,
|
|
modern_request_with_params(Some(54), "tools/list", json!({})),
|
|
None,
|
|
)
|
|
.await;
|
|
|
|
assert_eq!(
|
|
response.status().as_u16(),
|
|
400,
|
|
"the modern era requires the negotiated version header"
|
|
);
|
|
assert!(response.headers().get("MCP-Session-Id").is_none());
|
|
}
|
|
|
|
/// R3: legacy `initialize` must admit only the legacy revision.
|
|
#[tokio::test]
|
|
async fn r3_legacy_initialize_with_modern_body_version_is_rejected() {
|
|
let endpoint = endpoint().await;
|
|
|
|
let response = modern_post(&endpoint, &[], initialize_request(MODERN_REVISION), None).await;
|
|
|
|
assert_eq!(response.status().as_u16(), 400);
|
|
assert!(
|
|
response.headers().get("MCP-Session-Id").is_none(),
|
|
"a modern body version must not mint a legacy session"
|
|
);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn r3_legacy_header_with_modern_initialize_body_is_rejected() {
|
|
let endpoint = endpoint().await;
|
|
let headers = vec![("MCP-Protocol-Version", LEGACY_REVISION.to_owned())];
|
|
|
|
let response = modern_post(
|
|
&endpoint,
|
|
&headers,
|
|
initialize_request(MODERN_REVISION),
|
|
None,
|
|
)
|
|
.await;
|
|
|
|
assert_eq!(response.status().as_u16(), 400);
|
|
assert!(
|
|
response.headers().get("MCP-Session-Id").is_none(),
|
|
"a conflicting modern body version must not mint a session"
|
|
);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn r3_modern_identity_with_legacy_initialize_body_is_rejected() {
|
|
let endpoint = endpoint().await;
|
|
let headers = modern_headers(MODERN_REVISION, "initialize");
|
|
|
|
let response = modern_post(
|
|
&endpoint,
|
|
&headers,
|
|
modern_request_with_params(
|
|
Some(55),
|
|
"initialize",
|
|
json!({ "protocolVersion": LEGACY_REVISION, "capabilities": {} }),
|
|
),
|
|
None,
|
|
)
|
|
.await;
|
|
|
|
let status = response.status().as_u16();
|
|
assert!(
|
|
status == 400 || status == 404,
|
|
"a legacy initialize body must not be admitted by the modern era, got {status}"
|
|
);
|
|
assert!(response.headers().get("MCP-Session-Id").is_none());
|
|
}
|
|
|
|
/// Review pass 6 (P2 / matrix rows 14-15): a legacy `initialize` that names a withdrawn revision in
|
|
/// **both** carriers it can use — the `MCP-Protocol-Version` header and `params.protocolVersion` —
|
|
/// must stay legacy-shaped.
|
|
///
|
|
/// Defect this oracle pins: with an equal withdrawn identity the resolver takes the `other` branch
|
|
/// (`protocol/mod.rs` 665) and answers the modern `-32022` `UnsupportedProtocolVersionError`, while
|
|
/// the same withdrawn revision without a header is answered with the legacy `-32602` (`626-630`).
|
|
/// Row 14 forbids imposing the modern `-32022` contract on a legacy `initialize`; row 15 forbids an
|
|
/// implicit fallback into a withdrawn revision. The exact legacy code is deliberately **not** pinned
|
|
/// (the local contract names none for this path) — only the modern codes are excluded.
|
|
async fn assert_legacy_initialize_with_withdrawn_revision_is_legacy_shaped(
|
|
revision: &str,
|
|
correlation: &str,
|
|
) {
|
|
let endpoint = endpoint().await;
|
|
let headers = vec![("MCP-Protocol-Version", revision.to_owned())];
|
|
let message = json!({
|
|
"jsonrpc": "2.0",
|
|
"id": 1,
|
|
"method": "initialize",
|
|
"params": { "protocolVersion": revision, "capabilities": {} }
|
|
});
|
|
|
|
let response = modern_post(&endpoint, &headers, message, Some(correlation)).await;
|
|
let status = response.status().as_u16();
|
|
assert!(
|
|
response.headers().get("MCP-Session-Id").is_none(),
|
|
"a withdrawn `initialize` must not mint a session ({correlation})"
|
|
);
|
|
let raw = response.text().await.unwrap();
|
|
|
|
assert_eq!(
|
|
status, 400,
|
|
"a withdrawn `initialize` revision must be rejected safely ({correlation}), got {raw}"
|
|
);
|
|
assert!(
|
|
!raw.trim().is_empty(),
|
|
"matrix rows 14/15 require a structured legacy error ({correlation}), but the response body \
|
|
was empty"
|
|
);
|
|
let body: Value = serde_json::from_str(&raw).unwrap_or_else(|error| {
|
|
panic!(
|
|
"the legacy initialize rejection must be a JSON-RPC envelope ({correlation}), got {raw:?}: {error}"
|
|
)
|
|
});
|
|
|
|
assert_eq!(
|
|
body["jsonrpc"], "2.0",
|
|
"the legacy rejection must be a JSON-RPC 2.0 envelope ({correlation}), got {body}"
|
|
);
|
|
assert_eq!(
|
|
body["id"],
|
|
json!(1),
|
|
"the legacy rejection must keep the request id ({correlation}), got {body}"
|
|
);
|
|
assert!(
|
|
body["error"]["code"].is_i64(),
|
|
"the legacy rejection must carry a numeric JSON-RPC code ({correlation}), got {body}"
|
|
);
|
|
assert_ne!(
|
|
body["error"]["code"],
|
|
json!(-32022),
|
|
"the modern UnsupportedProtocolVersionError must not be imposed on a withdrawn legacy \
|
|
`initialize` (row 14, {correlation}), got {body}"
|
|
);
|
|
assert_ne!(
|
|
body["error"]["code"],
|
|
json!(-32020),
|
|
"the modern HeaderMismatch code must not be imposed on a legacy `initialize` (row 14, \
|
|
{correlation}), got {body}"
|
|
);
|
|
assert!(
|
|
body["error"]["message"]
|
|
.as_str()
|
|
.is_some_and(|message| !message.trim().is_empty()),
|
|
"the legacy rejection must carry a non-empty message ({correlation}), got {body}"
|
|
);
|
|
assert_eq!(
|
|
body["error"]["data"]["request_id"],
|
|
json!(correlation),
|
|
"the legacy rejection must preserve the request correlation ({correlation}), got {body}"
|
|
);
|
|
assert!(
|
|
body.get("result").is_none(),
|
|
"a rejected `initialize` must not carry a result ({correlation}), got {body}"
|
|
);
|
|
}
|
|
|
|
/// Review pass 6 (P2): withdrawn revision `2025-03-26` in both legacy carriers.
|
|
#[tokio::test]
|
|
async fn review6_p2_legacy_initialize_with_withdrawn_2025_03_26_is_legacy_shaped() {
|
|
assert_legacy_initialize_with_withdrawn_revision_is_legacy_shaped(
|
|
"2025-03-26",
|
|
"review6-p2-withdrawn-2025-03-26",
|
|
)
|
|
.await;
|
|
}
|
|
|
|
/// Review pass 6 (P2): withdrawn revision `2025-06-18` in both legacy carriers.
|
|
#[tokio::test]
|
|
async fn review6_p2_legacy_initialize_with_withdrawn_2025_06_18_is_legacy_shaped() {
|
|
assert_legacy_initialize_with_withdrawn_revision_is_legacy_shaped(
|
|
"2025-06-18",
|
|
"review6-p2-withdrawn-2025-06-18",
|
|
)
|
|
.await;
|
|
}
|