test-server.js•1.87 kB
#!/usr/bin/env node
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
async function testServer() {
console.log("Testing MCP Alloy Server...\n");
const transport = new StdioClientTransport({
command: "node",
args: ["build/index.js"]
});
const client = new Client(
{
name: "test-client",
version: "1.0.0"
},
{
capabilities: {
tools: {}
}
}
);
await client.connect(transport);
console.log("✓ Connected to server\n");
// List available tools
const tools = await client.listTools();
console.log("Available tools:");
tools.tools.forEach(tool => {
console.log(` - ${tool.name}: ${tool.description || 'No description'}`);
});
console.log();
// Test execute_alloy tool
console.log("Testing execute_alloy tool...");
const result = await client.callTool({
name: "execute_alloy",
arguments: {
code: "sig Thing {} run { one Thing }"
}
});
console.log("Result:");
result.content.forEach(item => {
if (item.type === 'text') {
console.log(item.text);
}
});
console.log();
// List resources
const resources = await client.listResources();
console.log("Available resources:");
resources.resources.forEach(resource => {
console.log(` - ${resource.uri}: ${resource.name || 'No name'}`);
});
console.log();
// List prompts
const prompts = await client.listPrompts();
console.log("Available prompts:");
prompts.prompts.forEach(prompt => {
console.log(` - ${prompt.name}: ${prompt.description || 'No description'}`);
});
console.log();
await client.close();
console.log("✓ Test completed successfully");
}
testServer().catch(error => {
console.error("Test failed:", error);
process.exit(1);
});