forked from Life-Atlas/lpi-developer-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-client.ts
More file actions
106 lines (88 loc) · 3.3 KB
/
test-client.ts
File metadata and controls
106 lines (88 loc) · 3.3 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
#!/usr/bin/env node
/**
* LPI Sandbox Test Client
*
* Connects to the LPI sandbox MCP server and calls each tool.
* Use this to verify your setup works before building on top of it.
*
* Usage:
* npm run build
* npm run test-client
*/
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
async function main() {
console.log("=== LPI Sandbox Test Client ===\n");
// Connect to the sandbox server
const transport = new StdioClientTransport({
command: "node",
args: ["dist/src/index.js"],
});
const client = new Client(
{ name: "lpi-test-client", version: "1.0.0" },
{ capabilities: {} }
);
await client.connect(transport);
console.log("Connected to LPI Sandbox\n");
// List available tools
const tools = await client.listTools();
console.log(`Available tools (${tools.tools.length}):`);
for (const tool of tools.tools) {
console.log(` - ${tool.name}: ${(tool.description ?? "").slice(0, 80)}...`);
}
console.log();
// Test each tool
const tests: Array<{ name: string; args: Record<string, string> }> = [
{ name: "smile_overview", args: {} },
{ name: "smile_phase_detail", args: { phase: "reality-emulation" } },
{ name: "list_topics", args: {} },
{ name: "query_knowledge", args: { query: "explainable AI" } },
{ name: "get_case_studies", args: {} },
{ name: "get_case_studies", args: { query: "smart buildings" } },
{ name: "get_insights", args: { scenario: "personal health digital twin", tier: "free" } },
{ name: "get_methodology_step", args: { phase: "concurrent-engineering" } },
// Invalid input
{ name: "query_knowledge", args: { query: "!!!!!!!" } },
// Long input (DoS style)
{ name: "query_knowledge", args: { query: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" } },
// SQL injection attempt
{ name: "query_knowledge", args: { query: "' OR 1=1 --" } },
// Script injection attempt
{ name: "query_knowledge", args: { query: "<script>alert(1)</script>" } },
// Empty input
{ name: "query_knowledge", args: { query: "" } },
];
let passed = 0;
let failed = 0;
for (const test of tests) {
try {
const result = await client.callTool({
name: test.name,
arguments: test.args,
});
const text = (result.content as Array<{ type: string; text: string }>)[0]?.text || "";
const preview = text.slice(0, 120).replace(/\n/g, " ");
console.log(`[PASS] ${test.name}(${JSON.stringify(test.args)})`);
console.log(` ${preview}...\n`);
passed++;
} catch (error) {
const msg = error instanceof Error ? error.message : String(error);
console.log(`[FAIL] ${test.name}(${JSON.stringify(test.args)})`);
console.log(` Error: ${msg}\n`);
failed++;
}
}
console.log("=== Results ===");
console.log(`Passed: ${passed}/${tests.length}`);
console.log(`Failed: ${failed}/${tests.length}`);
if (failed === 0) {
console.log("\nAll tools working. Your LPI Sandbox is ready.");
console.log("You can now build agents that connect to this server.");
}
await client.close();
process.exit(failed > 0 ? 1 : 0);
}
main().catch((error) => {
console.error("Test client error:", error);
process.exit(1);
});