mirror of
https://gitea.ingwaz.work/Ingwaz/openbrain-mcp.git
synced 2026-03-31 14:49:06 +00:00
Fix MCP transport compatibility and batch_store e2e coverage
This commit is contained in:
112
tests/e2e_mcp.rs
112
tests/e2e_mcp.rs
@@ -110,6 +110,26 @@ async fn call_jsonrpc(client: &reqwest::Client, base: &str, request: Value) -> V
|
||||
.expect("JSON-RPC response body")
|
||||
}
|
||||
|
||||
async fn call_streamable_jsonrpc(
|
||||
client: &reqwest::Client,
|
||||
base: &str,
|
||||
request: Value,
|
||||
) -> reqwest::Response {
|
||||
let mut req_builder = client
|
||||
.post(format!("{base}/mcp"))
|
||||
.header("Accept", "application/json, text/event-stream")
|
||||
.json(&request);
|
||||
|
||||
if let Some(key) = api_key() {
|
||||
req_builder = req_builder.header("X-API-Key", key);
|
||||
}
|
||||
|
||||
req_builder
|
||||
.send()
|
||||
.await
|
||||
.expect("streamable JSON-RPC HTTP request")
|
||||
}
|
||||
|
||||
/// Make an authenticated GET request to an MCP endpoint
|
||||
async fn get_mcp_endpoint(client: &reqwest::Client, base: &str, path: &str) -> reqwest::Response {
|
||||
let mut req_builder = client.get(format!("{base}{path}"));
|
||||
@@ -357,6 +377,98 @@ async fn e2e_transport_tools_list_and_unknown_method() {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn e2e_streamable_initialize_and_tools_list() {
|
||||
let base = base_url();
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(Duration::from_secs(20))
|
||||
.build()
|
||||
.expect("reqwest client");
|
||||
|
||||
wait_until_ready(&client, &base).await;
|
||||
|
||||
let initialize_response: Value = call_streamable_jsonrpc(
|
||||
&client,
|
||||
&base,
|
||||
json!({
|
||||
"jsonrpc": "2.0",
|
||||
"id": "streamable-init-1",
|
||||
"method": "initialize",
|
||||
"params": {
|
||||
"protocolVersion": "2024-11-05",
|
||||
"capabilities": {},
|
||||
"clientInfo": {
|
||||
"name": "e2e-client",
|
||||
"version": "0.1.0"
|
||||
}
|
||||
}
|
||||
}),
|
||||
)
|
||||
.await
|
||||
.json()
|
||||
.await
|
||||
.expect("streamable initialize JSON");
|
||||
|
||||
assert_eq!(
|
||||
initialize_response
|
||||
.get("result")
|
||||
.and_then(|value| value.get("protocolVersion"))
|
||||
.and_then(Value::as_str),
|
||||
Some("2024-11-05")
|
||||
);
|
||||
|
||||
let tools_list_response: Value = call_streamable_jsonrpc(
|
||||
&client,
|
||||
&base,
|
||||
json!({
|
||||
"jsonrpc": "2.0",
|
||||
"id": "streamable-tools-list-1",
|
||||
"method": "tools/list",
|
||||
"params": {}
|
||||
}),
|
||||
)
|
||||
.await
|
||||
.json()
|
||||
.await
|
||||
.expect("streamable tools/list JSON");
|
||||
|
||||
assert!(
|
||||
tools_list_response
|
||||
.get("result")
|
||||
.and_then(|value| value.get("tools"))
|
||||
.and_then(Value::as_array)
|
||||
.map(|tools| !tools.is_empty())
|
||||
.unwrap_or(false),
|
||||
"streamable /mcp tools/list should return tool definitions"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn e2e_streamable_get_returns_405() {
|
||||
let base = base_url();
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(Duration::from_secs(20))
|
||||
.build()
|
||||
.expect("reqwest client");
|
||||
|
||||
wait_until_ready(&client, &base).await;
|
||||
|
||||
let mut request = client
|
||||
.get(format!("{base}/mcp"))
|
||||
.header("Accept", "text/event-stream");
|
||||
|
||||
if let Some(key) = api_key() {
|
||||
request = request.header("X-API-Key", key);
|
||||
}
|
||||
|
||||
let response = request.send().await.expect("GET /mcp");
|
||||
assert_eq!(
|
||||
response.status(),
|
||||
reqwest::StatusCode::METHOD_NOT_ALLOWED,
|
||||
"streamable GET /mcp should explicitly return 405 when standalone SSE streams are not offered"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn e2e_purge_requires_confirm_flag() {
|
||||
let base = base_url();
|
||||
|
||||
Reference in New Issue
Block a user