use serde_json::{json, Value};
mod mcp_test_helpers;
use mcp_test_helpers::*;
#[tokio::test]
async fn test_debug_info_pollutes_protocol_responses() {
let test_server = McpTestServer::start().await.expect("Failed to start test server");
let port = test_server.port;
let test_message = json!({
"jsonrpc": "2.0",
"id": "test-debug-pollution",
"method": "tools/call",
"params": {
"name": "test_tool",
"arguments": {
"test_param": "test_value"
},
"_meta": {
"progressToken": "progress-token-123"
}
}
});
let client = reqwest::Client::new();
let url = format!("http://127.0.0.1:{}/mcp", port);
let response = client
.post(&url)
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.header("User-Agent", "Cursor-Debug-Test")
.json(&test_message)
.send()
.await
.expect("Failed to send request");
let response_text = response.text().await.expect("Failed to get response text");
let response_size = response_text.len();
println!("Response size: {} bytes", response_size);
println!("Response preview (first 500 chars): {}",
response_text.chars().take(500).collect::<String>());
let response_json: Value = serde_json::from_str(&response_text)
.expect("Response should be valid JSON");
assert_eq!(response_json["jsonrpc"], "2.0");
assert_eq!(response_json["id"], "test-debug-pollution");
println!("Full response JSON: {}", response_text);
let response_json_str = serde_json::to_string(&response_json).unwrap();
println!("Re-serialized response: {}", response_json_str);
let is_pure_json = serde_json::from_str::<Value>(&response_text).is_ok();
if !is_pure_json {
println!("❌ RESPONSE IS NOT PURE JSON!");
println!(" This indicates debug output is being mixed with JSON response");
println!(" This would cause the 'LARGE DEBUG SECTION DETECTED' warning");
}
let expected_max_size = 200;
if response_size > expected_max_size {
println!("⚠️ RESPONSE TOO LARGE: {} bytes (expected < {} bytes)",
response_size, expected_max_size);
println!(" This suggests debug output is inflating the response");
}
assert!(is_pure_json, "Response should be pure JSON, not mixed with debug output");
assert!(response_size < 1000, "Response should be under 1000 bytes for a simple error, got {} bytes", response_size);
}
#[tokio::test]
async fn test_clean_response_without_debug_pollution() {
let clean_response = json!({
"jsonrpc": "2.0",
"id": "test-clean",
"error": {
"code": -32601,
"message": "Method not found"
}
});
let clean_json = serde_json::to_string(&clean_response).unwrap();
let clean_size = clean_json.len();
println!("Clean MCP response example:");
println!("Size: {} bytes", clean_size);
println!("Content: {}", clean_json);
assert!(clean_size < 200, "Clean response should be under 200 bytes");
assert!(!clean_json.contains("debug"));
assert!(!clean_json.contains("🚀"));
assert!(!clean_json.contains("Request ID:"));
assert!(!clean_json.contains("=== MCP REQUEST ANALYSIS"));
}
#[tokio::test]
async fn test_debug_warning_threshold() {
let large_response = "debug".repeat(2000);
let triggers_warning = large_response.contains("debug") && large_response.len() > 5000;
assert!(triggers_warning, "Should trigger LARGE DEBUG SECTION DETECTED warning");
println!("✅ Debug warning threshold test confirms the 5000 byte threshold");
}