import 'dotenv/config';
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
/**
* Integration test for LangSearch MCP Server
*/
async function testServer() {
console.log('๐งช LangSearch MCP Server Integration Test\n');
console.log('='.repeat(60));
// Create client and connect to server
const transport = new StdioClientTransport({
command: 'node',
args: ['dist/index.js']
});
const client = new Client({
name: 'test-client',
version: '1.0.0'
}, {
capabilities: {}
});
try {
console.log('\nโ
Step 1: Connecting to server...');
await client.connect(transport);
console.log(' Connected successfully!');
// Test 2: List available tools
console.log('\nโ
Step 2: Listing available tools...');
const toolsResult = await client.listTools();
console.log(` Found ${toolsResult.tools.length} tools:`);
toolsResult.tools.forEach((tool, idx) => {
console.log(` ${idx + 1}. ${tool.name}`);
console.log(` ${tool.description?.substring(0, 80)}...`);
});
// Test 3: Call web search tool
console.log('\nโ
Step 3: Testing Web Search Tool...');
console.log(' Query: "TypeScript MCP development"');
const searchResult = await client.callTool({
name: 'langsearch_web_search',
arguments: {
query: 'TypeScript MCP development',
count: 3,
summary: true,
freshness: 'month'
}
});
if (searchResult.isError) {
console.log(' โ Error:', searchResult.content[0].text);
} else {
console.log(' โ
Success! Received search results:');
const text = searchResult.content[0].text;
const lines = text.split('\n').slice(0, 8);
lines.forEach(line => console.log(` ${line}`));
console.log(' ...');
}
// Test 4: Call semantic rerank tool
console.log('\nโ
Step 4: Testing Semantic Rerank Tool...');
console.log(' Query: "machine learning optimization"');
const rerankResult = await client.callTool({
name: 'langsearch_semantic_rerank',
arguments: {
query: 'machine learning optimization',
documents: [
'Deep learning models require careful hyperparameter tuning for optimal performance',
'The weather forecast shows sunny skies for the weekend',
'Gradient descent and backpropagation are fundamental to neural network training',
'Pizza is a popular food choice for dinner',
'Stochastic gradient descent with momentum improves convergence speed'
],
top_n: 3,
return_documents: true
}
});
if (rerankResult.isError) {
console.log(' โ Error:', rerankResult.content[0].text);
} else {
console.log(' โ
Success! Reranked documents:');
const text = rerankResult.content[0].text;
const lines = text.split('\n').slice(0, 12);
lines.forEach(line => console.log(` ${line}`));
}
// Close connection
console.log('\nโ
Step 5: Closing connection...');
await client.close();
console.log(' Connection closed.');
console.log('\n' + '='.repeat(60));
console.log('โ
All Tests Passed!\n');
console.log('๐ Your LangSearch MCP server is working perfectly!');
console.log('๐ก Ready to use with Claude Desktop or any MCP client.\n');
} catch (error) {
console.error('\nโ Test Failed:', error.message);
console.error(error);
process.exit(1);
}
}
testServer();