|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import sys |
| 3 | +import json |
| 4 | +import subprocess |
| 5 | +import time |
| 6 | + |
| 7 | +mcp_script = "./nitpick_mcp.py" |
| 8 | + |
| 9 | +p = subprocess.Popen( |
| 10 | + ["python3", mcp_script], |
| 11 | + stdin=subprocess.PIPE, |
| 12 | + stdout=subprocess.PIPE, |
| 13 | + stderr=subprocess.PIPE, |
| 14 | + text=True |
| 15 | +) |
| 16 | + |
| 17 | +def send_request(method, params, req_id): |
| 18 | + req = { |
| 19 | + "jsonrpc": "2.0", |
| 20 | + "id": req_id, |
| 21 | + "method": method, |
| 22 | + "params": params |
| 23 | + } |
| 24 | + p.stdin.write(json.dumps(req) + "\n") |
| 25 | + p.stdin.flush() |
| 26 | + line = p.stdout.readline() |
| 27 | + if not line: |
| 28 | + return None |
| 29 | + return json.loads(line) |
| 30 | + |
| 31 | +try: |
| 32 | + print("Testing initialize...") |
| 33 | + res = send_request("initialize", {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name":"test","version":"1"}}, 1) |
| 34 | + assert res is not None, "Failed to get response" |
| 35 | + assert "result" in res, f"Expected result in {res}" |
| 36 | + |
| 37 | + # After initialize, the server sends an initialized notification? |
| 38 | + # Actually client sends initialized notification. |
| 39 | + notif = { |
| 40 | + "jsonrpc": "2.0", |
| 41 | + "method": "notifications/initialized", |
| 42 | + "params": {} |
| 43 | + } |
| 44 | + p.stdin.write(json.dumps(notif) + "\n") |
| 45 | + p.stdin.flush() |
| 46 | + |
| 47 | + print("Testing tools/list...") |
| 48 | + res = send_request("tools/list", {}, 2) |
| 49 | + assert res is not None, "Failed to get response" |
| 50 | + assert "result" in res, f"Expected result in {res}" |
| 51 | + tools = res["result"]["tools"] |
| 52 | + tool_names = [t["name"] for t in tools] |
| 53 | + assert "nitpick_compile" in tool_names |
| 54 | + assert "nitpick_check" in tool_names |
| 55 | + assert "nitpick_docs" in tool_names |
| 56 | + |
| 57 | + print("All MCP tests passed!") |
| 58 | +finally: |
| 59 | + p.terminate() |
0 commit comments