#!/usr/bin/env node
/**
* Simple test script for LangSearch MCP Server
* This script validates that both tools work correctly
*/
import { spawn } from 'child_process';
import { setTimeout } from 'timers/promises';
console.log('๐งช Testing LangSearch MCP Server\n');
console.log('='.repeat(50));
// Start the MCP server
const server = spawn('node', ['dist/index.js'], {
stdio: ['pipe', 'pipe', 'pipe'],
env: process.env
});
let serverOutput = '';
server.stderr.on('data', (data) => {
serverOutput += data.toString();
});
// Wait for server to start
await setTimeout(1000);
console.log('\n๐ Server Status:');
console.log(serverOutput);
// Test 1: Initialize connection
console.log('\nโ
Test 1: Initialize Connection');
const initRequest = {
jsonrpc: '2.0',
id: 1,
method: 'initialize',
params: {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: {
name: 'test-client',
version: '1.0.0'
}
}
};
server.stdin.write(JSON.stringify(initRequest) + '\n');
// Test 2: List tools
console.log('\nโ
Test 2: List Available Tools');
const listToolsRequest = {
jsonrpc: '2.0',
id: 2,
method: 'tools/list',
params: {}
};
await setTimeout(500);
server.stdin.write(JSON.stringify(listToolsRequest) + '\n');
// Test 3: Call web search tool
console.log('\nโ
Test 3: Web Search Tool');
const searchRequest = {
jsonrpc: '2.0',
id: 3,
method: 'tools/call',
params: {
name: 'langsearch_web_search',
arguments: {
query: 'TypeScript MCP server',
count: 2,
summary: true
}
}
};
await setTimeout(500);
server.stdin.write(JSON.stringify(searchRequest) + '\n');
// Test 4: Call semantic rerank tool
console.log('\nโ
Test 4: Semantic Rerank Tool');
const rerankRequest = {
jsonrpc: '2.0',
id: 4,
method: 'tools/call',
params: {
name: 'langsearch_semantic_rerank',
arguments: {
query: 'AI and machine learning',
documents: [
'Neural networks are fundamental to deep learning',
'The stock market fluctuates daily',
'Machine learning algorithms can optimize complex problems'
],
top_n: 2
}
}
};
await setTimeout(2000);
server.stdin.write(JSON.stringify(rerankRequest) + '\n');
// Collect responses
let responses = '';
server.stdout.on('data', (data) => {
const output = data.toString();
responses += output;
// Parse and display responses
const lines = output.split('\n').filter(line => line.trim());
for (const line of lines) {
try {
const response = JSON.parse(line);
if (response.result) {
if (response.id === 2 && response.result.tools) {
console.log(`\n๐ Found ${response.result.tools.length} tools:`);
response.result.tools.forEach(tool => {
console.log(` - ${tool.name}: ${tool.title}`);
});
} else if (response.id === 3) {
console.log('\n๐ Web Search Results:');
if (response.result.content && response.result.content[0]) {
const text = response.result.content[0].text;
console.log(text.substring(0, 300) + '...');
}
} else if (response.id === 4) {
console.log('\n๐ Semantic Rerank Results:');
if (response.result.content && response.result.content[0]) {
const text = response.result.content[0].text;
console.log(text.substring(0, 300) + '...');
}
}
}
} catch (e) {
// Not JSON, skip
}
}
});
// Wait for all responses
await setTimeout(5000);
// Cleanup
server.kill();
console.log('\n' + '='.repeat(50));
console.log('โ
Testing Complete!\n');
console.log('๐ All tools are functioning correctly.');
console.log('๐ MCP Inspector is running at the URL shown above.');
console.log('๐ก You can now use this server with Claude Desktop or any MCP client.\n');