test-ai-resource.mjs•2.21 kB
#!/usr/bin/env node
import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Test the ember://ai-docs resource
async function testResource() {
console.log('Testing the ember://ai-docs resource...');
// Start the MCP server
const serverProcess = spawn('node', ['dist/index.js'], {
cwd: __dirname,
stdio: ['pipe', 'pipe', 'pipe']
});
serverProcess.stderr.on('data', (data) => {
console.error(`Error: ${data}`);
});
// Send initialization
const initMessage = {
jsonrpc: '2.0',
id: 1,
method: 'initialize',
params: {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: {
name: 'test-client',
version: '1.0.0'
}
}
};
serverProcess.stdin.write(JSON.stringify(initMessage) + '\n');
// Send resource read request
const resourceMessage = {
jsonrpc: '2.0',
id: 2,
method: 'resources/read',
params: {
uri: 'ember://ai-docs'
}
};
serverProcess.stdin.write(JSON.stringify(resourceMessage) + '\n');
return new Promise((resolve) => {
let responseCount = 0;
serverProcess.stdout.on('data', (data) => {
const lines = data.toString().split('\n').filter(line => line.trim());
for (const line of lines) {
try {
const response = JSON.parse(line);
responseCount++;
if (responseCount === 2) { // Resource response
console.log('Resource response received!');
console.log('Content type:', response.result?.contents?.[0]?.mimeType);
console.log('Content length:', response.result?.contents?.[0]?.text?.length);
console.log('First 200 characters:');
console.log(response.result?.contents?.[0]?.text?.substring(0, 200) + '...');
serverProcess.kill();
resolve();
}
} catch (e) {
// Skip non-JSON lines
}
}
});
});
}
testResource().then(() => {
console.log('\nResource test completed');
}).catch(console.error);