import { spawn } from 'child_process'
// Test the MCP server with proper initialization and tool calls
const server = spawn('node', ['dist/index.js'], {
stdio: ['pipe', 'pipe', 'pipe']
})
let requestId = 1
function sendRequest(method, params = {}) {
const request = {
jsonrpc: '2.0',
id: requestId++,
method,
params
}
server.stdin.write(JSON.stringify(request) + '\n')
}
server.stdout.on('data', (data) => {
try {
const response = JSON.parse(data.toString().trim())
console.log('โ
Response:', JSON.stringify(response, null, 2))
} catch (e) {
console.log('๐ Raw output:', data.toString())
}
})
server.stderr.on('data', (data) => {
console.log('โ Error:', data.toString())
})
server.on('close', (code) => {
console.log('๐ Server closed with code:', code)
})
// Test sequence
setTimeout(() => {
console.log('๐ Testing MCP server...')
// 1. Initialize the server
sendRequest('initialize', {
protocolVersion: '2024-11-05',
capabilities: {
tools: {}
},
clientInfo: {
name: 'test-client',
version: '1.0.0'
}
})
}, 100)
setTimeout(() => {
// 2. Send initialized notification
sendRequest('notifications/initialized', {})
}, 200)
setTimeout(() => {
// 3. List available tools
sendRequest('tools/list', {})
}, 300)
setTimeout(() => {
// 4. Test compare_texts tool
sendRequest('tools/call', {
name: 'compare_texts',
arguments: {
text1: 'Hello World',
text2: 'Hello World'
}
})
}, 400)
setTimeout(() => {
// 5. Test with different texts
sendRequest('tools/call', {
name: 'compare_texts',
arguments: {
text1: 'Hello World',
text2: 'Hello World!'
}
})
}, 500)
setTimeout(() => {
// 6. Test detailed diff
sendRequest('tools/call', {
name: 'get_detailed_diff',
arguments: {
text1: 'Line 1\nLine 2\nLine 3',
text2: 'Line 1\nLine 2 Modified\nLine 3'
}
})
}, 600)
setTimeout(() => {
server.kill()
console.log('๐งช Test completed')
}, 2000)