refactor(mcp): strip sse fallback architecture in favor of pure websockets and fix nvim NDJSON bug
This commit is contained in:
1 parent
0e29b12ac8
commit
3716c3e698
33 files changed
+2082
-1756
No files matched your search
@@ -42,7 +42,6 @@ fn read_message(stdout: &mut std::process::ChildStdout) -> Option<Value> {
|
||||
|
||||
#[test]
|
||||
fn test_mcp_initialization_and_tools_list() {
|
||||
// Determine the path to the built binary.
|
||||
let mut nvim_exe = std::env::current_exe().unwrap();
|
||||
nvim_exe.pop();
|
||||
nvim_exe.pop();
|
||||
@@ -58,6 +57,17 @@ fn test_mcp_initialization_and_tools_list() {
|
||||
let mut stdin = child.stdin.take().expect("Failed to open stdin");
|
||||
let mut stdout = child.stdout.take().expect("Failed to open stdout");
|
||||
|
||||
// 0. Test server/discover (probe)
|
||||
let discover_req = json!({
|
||||
"jsonrpc": "2.0",
|
||||
"method": "server/discover",
|
||||
"params": {},
|
||||
"id": 0
|
||||
});
|
||||
send_message(&mut stdin, discover_req);
|
||||
let discover_resp = read_message(&mut stdout).expect("Failed to read server/discover response");
|
||||
assert_eq!(discover_resp["error"]["code"], -32601);
|
||||
|
||||
// 1. Test Initialize
|
||||
let init_req = json!({
|
||||
"jsonrpc": "2.0",
|
||||
@@ -73,7 +83,10 @@ fn test_mcp_initialization_and_tools_list() {
|
||||
"id": 1
|
||||
});
|
||||
|
||||
send_message(&mut stdin, init_req);
|
||||
// Send initialize using JSONL format!
|
||||
let s = serde_json::to_string(&init_req).unwrap();
|
||||
stdin.write_all(format!("{}\n", s).as_bytes()).unwrap();
|
||||
stdin.flush().unwrap();
|
||||
|
||||
let init_resp = read_message(&mut stdout).expect("Failed to read initialize response");
|
||||
|
||||
@@ -102,11 +115,31 @@ fn test_mcp_initialization_and_tools_list() {
|
||||
let tools = tools_resp["result"]["tools"].as_array().expect("result.tools must be an array");
|
||||
assert!(!tools.is_empty(), "Server must expose at least one tool");
|
||||
|
||||
// Verify a specific tool exists
|
||||
let has_get_active_buffer = tools.iter().any(|t| t["name"] == "nvim_get_active_buffer");
|
||||
assert!(has_get_active_buffer, "Missing nvim_get_active_buffer tool");
|
||||
|
||||
// Kill the child process cleanly
|
||||
// 3. Test negative scenario: tools/call when Neovim is not running
|
||||
// Since Neovim is not guaranteed to be running on the test agent's system,
|
||||
// calling a Neovim-specific tool should gracefully return a JSON-RPC error.
|
||||
let call_req = json!({
|
||||
"jsonrpc": "2.0",
|
||||
"method": "tools/call",
|
||||
"params": {
|
||||
"name": "nvim_get_active_buffer",
|
||||
"arguments": {}
|
||||
},
|
||||
"id": 3
|
||||
});
|
||||
|
||||
send_message(&mut stdin, call_req);
|
||||
|
||||
let call_resp = read_message(&mut stdout).expect("Failed to read tools/call response");
|
||||
|
||||
assert_eq!(call_resp["jsonrpc"], "2.0");
|
||||
assert_eq!(call_resp["id"], 3);
|
||||
assert!(call_resp.get("error").is_some(), "Expected an error response since Neovim shouldn't be running");
|
||||
assert_eq!(call_resp["error"]["code"], -32603); // Internal Error
|
||||
|
||||
child.kill().expect("Failed to kill child");
|
||||
child.wait().expect("Failed to wait on child");
|
||||
}
|
||||
Reference in new issue
Block a user