-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-client.ts
More file actions
108 lines (93 loc) · 3.18 KB
/
Copy pathtest-client.ts
File metadata and controls
108 lines (93 loc) · 3.18 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
#!/usr/bin/env tsx
/**
* Simple MCP client for testing the Schematic MCP server
* This validates that the server responds correctly to MCP protocol messages
*/
import { config } from "dotenv";
config({ path: ".env.local" });
config(); // also load .env as fallback
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
import { join } from "path";
import { fileURLToPath } from "url";
import { dirname } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
async function testMCP() {
console.log("🧪 Testing Schematic MCP Server\n");
const serverPath = join(__dirname, "dist", "index.js");
// Create MCP client transport (this will spawn the server process)
const transport = new StdioClientTransport({
command: "node",
args: [serverPath],
env: {
...process.env,
SCHEMATIC_API_KEY: process.env.SCHEMATIC_API_KEY || "test-key",
},
});
try {
const client = new Client(
{
name: "test-client",
version: "1.0.0",
},
{
capabilities: {},
}
);
await client.connect(transport);
console.log("✅ Connected to MCP server\n");
// Test 1: List tools
console.log("Test 1: Listing tools...");
const tools = await client.listTools();
console.log(`✅ Found ${tools.tools.length} tools:`);
tools.tools.forEach((tool) => {
console.log(` - ${tool.name}: ${tool.description?.substring(0, 60)}...`);
});
console.log("");
// Test 2: Call a simple tool (list_plans - doesn't require company lookup)
if (process.env.SCHEMATIC_API_KEY && process.env.SCHEMATIC_API_KEY !== "test-key") {
console.log("Test 2: Calling list_plans tool...");
try {
const result = await client.callTool({
name: "list_plans",
arguments: {},
});
console.log("✅ Tool call successful!");
console.log(`Response: ${result.content[0]?.text?.substring(0, 200)}...\n`);
} catch (error: any) {
console.log(`⚠️ Tool call failed (expected if API key is invalid): ${error.message}\n`);
}
} else {
console.log("Test 2: Skipped (no valid SCHEMATIC_API_KEY set)\n");
}
// Test 3: Validate tool schemas
console.log("Test 3: Validating tool schemas...");
let schemaErrors = 0;
for (const tool of tools.tools) {
if (!tool.name) {
console.log(` ❌ Tool missing name`);
schemaErrors++;
}
if (!tool.description) {
console.log(` ⚠️ Tool ${tool.name} missing description`);
}
if (!tool.inputSchema) {
console.log(` ❌ Tool ${tool.name} missing inputSchema`);
schemaErrors++;
}
}
if (schemaErrors === 0) {
console.log("✅ All tool schemas are valid\n");
} else {
console.log(`❌ Found ${schemaErrors} schema errors\n`);
}
await client.close();
console.log("✅ Tests completed successfully!");
} catch (error: any) {
console.error("❌ Test failed:", error.message);
console.error(error.stack);
process.exit(1);
}
}
testMCP().catch(console.error);