feat(mcp): execute Prompts through request-scoped SDK handlers
CI / UI Checks (pull_request) Successful in 14s
CI / Rust Checks (pull_request) Successful in 37m47s
CI / Rust Feature Validation (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Required Checks (pull_request) Successful in 1s
CI / Deploy (pull_request) Skipped
CI / UI Checks (pull_request) Successful in 14s
CI / Rust Checks (pull_request) Successful in 37m47s
CI / Rust Feature Validation (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Required Checks (pull_request) Successful in 1s
CI / Deploy (pull_request) Skipped
This commit is contained in:
1 parent
5b0af84d5a
commit
5cce1b09df
11 files changed
+1070
-108
No files matched your search
@@ -6,6 +6,7 @@ use serde_json::{Value, json};
|
||||
use std::{sync::Arc, time::Duration};
|
||||
#[path = "rmcp_prompts_test_support.rs"]
|
||||
mod fixtures;
|
||||
use super::rmcp_prompts_handler_runtime_tests as handler;
|
||||
use fixtures::Endpoint;
|
||||
|
||||
fn observe_body(response: Response, counters: Arc<CounterSet>) -> Response {
|
||||
@@ -111,11 +112,15 @@ async fn success(
|
||||
std::array::from_fn(|i| after[i] - before[i]),
|
||||
)
|
||||
}
|
||||
async fn control(revision: &str) -> Vec<([usize; 3], [usize; 3])> {
|
||||
pub(super) async fn control(
|
||||
revision: &str,
|
||||
require_handler: bool,
|
||||
) -> Vec<([usize; 3], [usize; 3])> {
|
||||
let h = Endpoint::started().await;
|
||||
let session = h.session(revision).await;
|
||||
let session = session.as_deref();
|
||||
let mut deltas = Vec::new();
|
||||
let mut handlers = Vec::new();
|
||||
let mut first_cursor = None;
|
||||
// Both revisions' JSON contract, plus modern terminal SSE through the same normal app.
|
||||
let modes: &[bool] = if revision == MODERN_REVISION {
|
||||
@@ -130,7 +135,9 @@ async fn control(revision: &str) -> Vec<([usize; 3], [usize; 3])> {
|
||||
if let Some(ref cursor) = cursor {
|
||||
params["cursor"] = json!(cursor);
|
||||
}
|
||||
let before = handler::counts(&h.counters);
|
||||
let (result, delta) = success(&h, revision, session, "prompts/list", params, sse).await;
|
||||
handlers.push(handler::delta(&h.counters, before, "prompts/list"));
|
||||
let prompts = result["prompts"].as_array().unwrap();
|
||||
assert_eq!(prompts.len(), 1, "{result}");
|
||||
assert_eq!(
|
||||
@@ -174,6 +181,7 @@ async fn control(revision: &str) -> Vec<([usize; 3], [usize; 3])> {
|
||||
] {
|
||||
let mut previous = None;
|
||||
for _ in 0..2 {
|
||||
let before = handler::counts(&h.counters);
|
||||
let (result, delta) = success(
|
||||
&h,
|
||||
revision,
|
||||
@@ -183,6 +191,7 @@ async fn control(revision: &str) -> Vec<([usize; 3], [usize; 3])> {
|
||||
sse,
|
||||
)
|
||||
.await;
|
||||
handlers.push(handler::delta(&h.counters, before, "prompts/get"));
|
||||
assert_eq!(result["description"], format!("Published {name}"));
|
||||
assert_eq!(
|
||||
result["messages"],
|
||||
@@ -232,7 +241,9 @@ async fn control(revision: &str) -> Vec<([usize; 3], [usize; 3])> {
|
||||
"prompts/get",
|
||||
json!({"name":"greeting","arguments":arguments}),
|
||||
);
|
||||
let before = handler::counts(&h.counters);
|
||||
let body = wire(h.post(revision, session, &req, sse).await, &req["id"], sse).await;
|
||||
handlers.push(handler::delta(&h.counters, before, "prompts/get"));
|
||||
assert_eq!(body["error"]["code"], -32602, "{body}");
|
||||
assert_eq!(body["error"]["data"]["reason"], reason, "{body}");
|
||||
assert_eq!(body["error"]["data"]["argument"], argument);
|
||||
@@ -255,7 +266,9 @@ async fn control(revision: &str) -> Vec<([usize; 3], [usize; 3])> {
|
||||
"prm_a",
|
||||
] {
|
||||
let req = request(revision, "prompts/get", json!({"name":name}));
|
||||
let before = handler::counts(&h.counters);
|
||||
let body = wire(h.post(revision, session, &req, sse).await, &req["id"], sse).await;
|
||||
handlers.push(handler::delta(&h.counters, before, "prompts/get"));
|
||||
assert_eq!(body["error"]["code"], -32602, "{body}");
|
||||
assert_eq!(
|
||||
body["error"]["message"],
|
||||
@@ -269,7 +282,8 @@ async fn control(revision: &str) -> Vec<([usize; 3], [usize; 3])> {
|
||||
}
|
||||
}
|
||||
for params in [json!({"cursor":"invalid"}), json!({"limit":"invalid"})] {
|
||||
let req = request(revision, "prompts/list", params);
|
||||
let before = handler::counts(&h.counters);
|
||||
let req = request(revision, "prompts/list", params.clone());
|
||||
let body = wire(
|
||||
h.post(revision, session, &req, false).await,
|
||||
&req["id"],
|
||||
@@ -277,6 +291,15 @@ async fn control(revision: &str) -> Vec<([usize; 3], [usize; 3])> {
|
||||
)
|
||||
.await;
|
||||
assert_eq!(body["error"]["code"], -32602, "{body}");
|
||||
if params.get("cursor").is_some() {
|
||||
handlers.push(handler::delta(&h.counters, before, "prompts/list"));
|
||||
} else {
|
||||
assert_eq!(
|
||||
handler::counts(&h.counters),
|
||||
before,
|
||||
"parsing rejects must not enter handlers"
|
||||
);
|
||||
}
|
||||
}
|
||||
let other = if revision == MODERN_REVISION {
|
||||
LEGACY_REVISION
|
||||
@@ -345,6 +368,27 @@ async fn control(revision: &str) -> Vec<([usize; 3], [usize; 3])> {
|
||||
),
|
||||
"{binding:?}"
|
||||
);
|
||||
sqlx::query(
|
||||
"update platform_api_keys set scopes_json = '[]'::jsonb where id = 'pk_dispatch_observer'",
|
||||
)
|
||||
.execute(h.registry.pool())
|
||||
.await
|
||||
.unwrap();
|
||||
for (method, params) in [
|
||||
("prompts/list", json!({})),
|
||||
("prompts/get", json!({"name":"greeting"})),
|
||||
] {
|
||||
let before = handler::counts(&h.counters);
|
||||
let req = request(revision, method, params);
|
||||
assert_eq!(h.post(revision, session, &req, false).await.status(), 403);
|
||||
assert_eq!(
|
||||
handler::counts(&h.counters),
|
||||
before,
|
||||
"scope rejects must precede handlers"
|
||||
);
|
||||
}
|
||||
sqlx::query("update platform_api_keys set scopes_json = '[\"read\",\"write\"]'::jsonb where id = 'pk_dispatch_observer'")
|
||||
.execute(h.registry.pool()).await.unwrap();
|
||||
h.registry
|
||||
.revoke_platform_api_key(
|
||||
&workspace_id(),
|
||||
@@ -360,29 +404,41 @@ async fn control(revision: &str) -> Vec<([usize; 3], [usize; 3])> {
|
||||
json!({"name":"greeting","arguments":{"name":"Ada"}}),
|
||||
),
|
||||
] {
|
||||
let before = handler::counts(&h.counters);
|
||||
assert_eq!(
|
||||
h.post(revision, session, &request(revision, method, params), false)
|
||||
.await
|
||||
.status(),
|
||||
401
|
||||
);
|
||||
assert_eq!(
|
||||
handler::counts(&h.counters),
|
||||
before,
|
||||
"revocation must precede handlers"
|
||||
);
|
||||
}
|
||||
eprintln!(
|
||||
"existing GREEN Prompts wire {revision}: populated pagination, typed metadata/values, exact immutable rendering, archive, structured refusals/non-disclosure, correlation/ID/cache, revoked401; SDK actual/expected={deltas:?}"
|
||||
);
|
||||
if require_handler {
|
||||
assert!(
|
||||
handlers.iter().all(|(actual, expected)| actual == expected),
|
||||
"SDK Prompts handler completion/consumption missing after successful HTTP wire/error/guard checks: {handlers:?}"
|
||||
);
|
||||
}
|
||||
deltas
|
||||
}
|
||||
#[tokio::test]
|
||||
async fn rmcp_prompts_wire_legacy() {
|
||||
control(LEGACY_REVISION).await;
|
||||
control(LEGACY_REVISION, false).await;
|
||||
}
|
||||
#[tokio::test]
|
||||
async fn rmcp_prompts_wire_modern() {
|
||||
control(MODERN_REVISION).await;
|
||||
control(MODERN_REVISION, false).await;
|
||||
}
|
||||
#[tokio::test]
|
||||
async fn rmcp_prompts_sdk_legacy() {
|
||||
let deltas = control(LEGACY_REVISION).await;
|
||||
let deltas = control(LEGACY_REVISION, false).await;
|
||||
assert!(
|
||||
deltas.iter().all(|(a, e)| a == e),
|
||||
"SDK typed dispatch/result missing after successful HTTP: {deltas:?}"
|
||||
@@ -390,7 +446,7 @@ async fn rmcp_prompts_sdk_legacy() {
|
||||
}
|
||||
#[tokio::test]
|
||||
async fn rmcp_prompts_sdk_modern() {
|
||||
let deltas = control(MODERN_REVISION).await;
|
||||
let deltas = control(MODERN_REVISION, false).await;
|
||||
assert!(
|
||||
deltas.iter().all(|(a, e)| a == e),
|
||||
"SDK typed dispatch/result missing after successful HTTP: {deltas:?}"
|
||||
|
||||
Reference in new issue
Block a user