domotz-mcp
Version:
MCP server for Domotz API and BMS (Building Management System) integration with IoT device monitoring
94 lines (81 loc) • 2.53 kB
JavaScript
import { spawn } from 'child_process';
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
async function testServer() {
console.log('Testing local domotz-mcp server...\n');
// Set environment variables
process.env.DOMOTZ_API_KEY = 'test-key';
process.env.DOMOTZ_API_ENDPOINT = 'https://api-eu-west-1-cell-1.domotz.com/public-api/v1/';
// Start the server
const serverProcess = spawn('node', ['dist/index.js'], {
env: process.env,
stdio: ['pipe', 'pipe', 'pipe']
});
// Create client
const transport = new StdioClientTransport({
command: 'node',
args: ['dist/index.js'],
env: process.env
});
const client = new Client({
name: 'test-client',
version: '1.0.0'
}, {
capabilities: {}
});
// Handle server stderr
serverProcess.stderr.on('data', (data) => {
console.log('Server stderr:', data.toString());
});
serverProcess.on('exit', (code) => {
console.log(`\nServer process exited with code ${code}`);
});
try {
// Connect to server
await client.connect(transport);
console.log('Connected to server successfully!\n');
// Initialize
console.log('Sending initialize request...');
const initResult = await client.request({
method: 'initialize',
params: {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: {
name: 'test-client',
version: '1.0.0'
}
}
});
console.log('Initialize response:', JSON.stringify(initResult, null, 2));
// List tools
console.log('\nSending tools/list request...');
const toolsResult = await client.request({
method: 'tools/list',
params: {}
});
console.log('Tools list:', JSON.stringify(toolsResult, null, 2));
// Test a tool
if (toolsResult.tools && toolsResult.tools.length > 0) {
console.log('\nTesting get_all_agents tool...');
const toolResult = await client.request({
method: 'tools/call',
params: {
name: 'get_all_agents',
arguments: {
page_size: 10,
page_number: 0
}
}
});
console.log('Tool result:', JSON.stringify(toolResult, null, 2));
}
} catch (error) {
console.error('Error:', error);
} finally {
console.log('\nTest complete. Closing server...');
await client.close();
serverProcess.kill();
}
}
testServer().catch(console.error);