#!/usr/bin/env node
/**
* Test the datastore_listKinds tool
*/
import { spawn } from 'child_process';
import { createInterface } from 'readline';
const server = spawn('node', ['build/index.js'], {
stdio: ['pipe', 'pipe', 'inherit'],
env: {
...process.env,
GOOGLE_APPLICATION_CREDENTIALS: process.env.GOOGLE_APPLICATION_CREDENTIALS,
GOOGLE_CLOUD_PROJECT: process.env.GOOGLE_CLOUD_PROJECT
}
});
let requestId = 0;
const pendingRequests = new Map();
const rl = createInterface({
input: server.stdout,
crlfDelay: Infinity
});
rl.on('line', (line) => {
try {
const response = JSON.parse(line);
console.log('š„ Server Response:', JSON.stringify(response, null, 2));
if (response.id && pendingRequests.has(response.id)) {
const resolve = pendingRequests.get(response.id);
pendingRequests.delete(response.id);
resolve(response);
}
} catch (e) {
console.log('š Server output:', line);
}
});
server.on('error', (error) => {
console.error('ā Server error:', error);
process.exit(1);
});
server.on('exit', (code) => {
console.log(`Server exited with code ${code}`);
process.exit(code);
});
function sendRequest(method, params = {}) {
return new Promise((resolve) => {
const id = ++requestId;
const request = {
jsonrpc: '2.0',
id,
method,
params
};
console.log('\nš¤ Sending Request:', JSON.stringify(request, null, 2));
server.stdin.write(JSON.stringify(request) + '\n');
pendingRequests.set(id, resolve);
});
}
const wait = (ms) => new Promise(resolve => setTimeout(resolve, ms));
async function runTests() {
try {
console.log('š Testing datastore_listKinds\n');
await wait(1000);
console.log('\n=== Test 1: Initialize ===');
await sendRequest('initialize', {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: {
name: 'test-client',
version: '1.0.0'
}
});
await wait(500);
console.log('\n=== Test 2: List Kinds ===');
await sendRequest('tools/call', {
name: 'datastore_listKinds',
arguments: {}
});
await wait(500);
console.log('\nā
Test completed!');
} catch (error) {
console.error('ā Test failed:', error);
} finally {
await wait(1000);
server.kill();
process.exit(0);
}
}
runTests();