skilled-feishu-mcp
Version:
A Model Context Protocol (MCP) server that integrates with Feishu's Open Platform APIs
73 lines (65 loc) • 2.01 kB
JavaScript
const { spawn } = require('child_process');
const path = require('path');
// Start the MCP server as a child process
const server = spawn('node', [path.join(__dirname, 'dist', 'index.js')], {
env: { ...process.env, NODE_ENV: 'development' },
stdio: ['pipe', 'pipe', 'inherit'] // Pipe stdin, pipe stdout, inherit stderr
});
// Listen for server output
server.stdout.on('data', (data) => {
const message = data.toString().trim();
try {
const response = JSON.parse(message);
console.log('\nReceived response from server:', JSON.stringify(response, null, 2));
// If we get an initialization response, send a list_tools request
if (response.jsonrpc === '2.0' && response.id === 1 && response.result) {
console.log('\nSending list_tools request...');
const listToolsRequest = {
jsonrpc: '2.0',
id: 2,
method: 'list_tools',
params: {}
};
server.stdin.write(JSON.stringify(listToolsRequest) + '\n');
}
// If we get a list_tools response, terminate the test
else if (response.jsonrpc === '2.0' && response.id === 2) {
console.log('\nTest completed successfully! Shutting down...');
server.kill();
process.exit(0);
}
} catch (error) {
console.log('Non-JSON server output:', message);
}
});
// Initialize the MCP server
console.log('Sending initialization request...');
const initRequest = {
jsonrpc: '2.0',
id: 1,
method: 'initialize',
params: {
protocolVersion: '0.3',
clientInfo: {
name: 'test-client',
version: '1.0.0'
},
capabilities: {
tools: {}
}
}
};
// Send the initialization request
server.stdin.write(JSON.stringify(initRequest) + '\n');
// Handle server exit
server.on('close', (code) => {
console.log(`MCP server process exited with code ${code}`);
process.exit(code);
});
// Set a timeout
setTimeout(() => {
console.log('Test timeout. Terminating...');
server.kill();
process.exit(1);
}, 15000);