M6: native MCP client, lazy index, mcp-serve (closes #42-#51)
ci / check (pull_request) Canceled after 0s
ci / check (push) Canceled after 0s

This commit is contained in:
hermes committed 2026-09-30 15:51:25 +00:00
1 parent 6d35274f39
commit 99dc90fd3b
18 files changed
+1723 -22

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
#!/bin/sh
# M6 e2e: model discovers an MCP tool via the lazy index, describes and calls it; `hx mcp` reports costs;
# `hx mcp-serve` answers another MCP client (hx itself, configured as a server) with lens tools.
set -eu
root=$(cd "$(dirname "$0")/.." && pwd)
tmp=$(mktemp -d)
trap 'kill $srv 2>/dev/null; rm -rf "$tmp"' EXIT
port=$((20000 + $$ % 20000))
python3 "$root/tests/fake_m6.py" $port & srv=$!
mkdir -p "$tmp/home/.hx" "$tmp/repo/.hx"
echo '{"claude":{"access":"fake-token","refresh":"r","expires":99999999999999}}' > "$tmp/home/.hx/auth.json"
printf '[lsp]\nmode = "off"\ntests = "off"\n' > "$tmp/home/.hx/config.toml"
cat > "$tmp/repo/.hx/mcp.json" <<EOF
{"mcpServers": {"f": {"command": "python3", "args": ["$root/crates/hx-mcp/tests/fake_mcp.py"], "eager": false}}}
EOF
sleep 0.5
cd "$tmp/repo"
export HOME="$tmp/home" HX_BASE_URL="http://127.0.0.1:$port"
"$root/target/debug/hx" -p "sum" > "$tmp/out" 2> "$tmp/err" || { cat "$tmp/err"; exit 1; }
grep -q "FINISHED OK:42" "$tmp/out" || { echo "--- out"; cat "$tmp/out"; echo "--- log"; curl -s "http://127.0.0.1:$port/"; echo "--- err"; cat "$tmp/err"; exit 1; }
"$root/target/debug/hx" mcp > "$tmp/st"
grep -q "f: 5 tools.*lazy (index ~[0-9]* tok, eager schemas ~[0-9]* tok)" "$tmp/st" || { cat "$tmp/st"; exit 1; }
# mcp-serve: hx as MCP server, consumed by hx as MCP client
printf 'fn main() {}\n' > main.rs
cat > "$tmp/repo/.hx/mcp.json" <<EOF
{"mcpServers": {"hx": {"command": "$root/target/debug/hx", "args": ["mcp-serve"], "eager": false}}}
EOF
"$root/target/debug/hx" mcp > "$tmp/st2"
grep -q "hx.lsp: Language server queries" "$tmp/st2" || { cat "$tmp/st2"; exit 1; }
# a foreign client (python, raw JSON-RPC) gets pyright diagnostics through hx mcp-serve
if command -v pyright-langserver >/dev/null; then
printf 'x: int = "no"\n' > bad.py
python3 - "$root/target/debug/hx" > "$tmp/diag" <<'PY'
import json, subprocess, sys
p = subprocess.Popen([sys.argv[1], "mcp-serve"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True)
def rpc(i, m, params):
p.stdin.write(json.dumps({"jsonrpc": "2.0", "id": i, "method": m, "params": params}) + "\n"); p.stdin.flush()
while True:
r = json.loads(p.stdout.readline())
if r.get("id") == i:
return r
rpc(1, "initialize", {"protocolVersion": "2025-06-18", "capabilities": {}, "clientInfo": {"name": "t", "version": "0"}})
r = rpc(2, "tools/call", {"name": "lsp", "arguments": {"action": "diagnostics", "path": "bad.py"}})
print(r["result"]["content"][0]["text"])
p.stdin.close(); p.wait(timeout=30)
PY
grep -q 'error.*not assignable' "$tmp/diag" || { echo "--- diag"; cat "$tmp/diag"; exit 1; }
fi
echo "m6 e2e ok"