test-tool.jsโข1.25 kB
// Quick test script to verify the MCP tool works
// Run with: node test-tool.js
import { spawn } from 'child_process';
const testMCPTool = () => {
console.log('๐งช Testing crop-price MCP tool...');
// Sample MCP request
const mcpRequest = {
jsonrpc: "2.0",
id: 1,
method: "tools/call",
params: {
name: "crop-price",
arguments: {
state: "Punjab",
commodity: "Wheat",
limit: 5
}
}
};
const server = spawn('node', ['dist/server.js'], {
stdio: ['pipe', 'pipe', 'pipe']
});
server.stdin.write(JSON.stringify(mcpRequest) + '\n');
server.stdin.end();
server.stdout.on('data', (data) => {
console.log('๐ Server response:', data.toString());
});
server.stderr.on('data', (data) => {
console.error('โ Server error:', data.toString());
});
server.on('close', (code) => {
console.log(`โ
Test completed with exit code ${code}`);
});
};
// Check if built
import { existsSync } from 'fs';
if (!existsSync('./dist/server.js')) {
console.log('โ ๏ธ Please run "npm run build" first');
process.exit(1);
}
testMCPTool();