-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestPhase3.js
More file actions
113 lines (103 loc) · 2.8 KB
/
Copy pathtestPhase3.js
File metadata and controls
113 lines (103 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { spawn } from "child_process";
const server = spawn("node", ["server.js"], {
stdio: ["pipe", "pipe", "pipe"],
});
server.stderr.on("data", (data) => {
console.log("Server:", data.toString().trim());
});
function sendRequest(request) {
return new Promise((resolve) => {
const requestStr = JSON.stringify(request) + "\n";
const handleResponse = (data) => {
try {
const response = JSON.parse(data.toString().trim());
server.stdout.off("data", handleResponse);
resolve(response);
} catch (e) {
console.error("Parse error:", data.toString());
}
};
server.stdout.on("data", handleResponse);
server.stdin.write(requestStr);
});
}
async function test() {
console.log("🔍 Testing Schema Explorer - Phase 3...\n");
try {
await sendRequest({
jsonrpc: "2.0",
id: 1,
method: "tools/call",
params: {
name: "connect_database",
arguments: { path: "sample.db" }
}
});
const tablesResponse = await sendRequest({
jsonrpc: "2.0",
id: 2,
method: "tools/call",
params: {
name: "list_tables",
arguments: {}
}
});
console.log("📋 Available Tables:");
console.log(tablesResponse.result.content[0].text);
console.log();
const describeResponse = await sendRequest({
jsonrpc: "2.0",
id: 3,
method: "tools/call",
params: {
name: "describe_table",
arguments: { table_name: "users" }
}
});
console.log("🔍 Users Table Structure:");
console.log(describeResponse.result.content[0].text);
console.log();
const indexesResponse = await sendRequest({
jsonrpc: "2.0",
id: 4,
method: "tools/call",
params: {
name: "show_indexes",
arguments: { table_name: "users" }
}
});
console.log("📋 Users Table Indexes:");
console.log(indexesResponse.result.content[0].text);
console.log();
const dataResponse = await sendRequest({
jsonrpc: "2.0",
id: 5,
method: "tools/call",
params: {
name: "get_table_data",
arguments: { table_name: "products", limit: 3 }
}
});
console.log("📊 Products Table Preview:");
console.log(dataResponse.result.content[0].text);
console.log();
const infoResponse = await sendRequest({
jsonrpc: "2.0",
id: 6,
method: "tools/call",
params: {
name: "database_info",
arguments: {}
}
});
console.log("📊 Database Information:");
console.log(infoResponse.result.content[0].text);
console.log();
console.log("🎉 Phase 3 Complete! Schema Explorer working perfectly!");
} catch (error) {
console.error("❌ Test failed:", error);
} finally {
server.kill();
}
}
test();