topic-scout-mcp
Version:
MCP Server para buscar notícias e identificar tendências sobre tópicos específicos
95 lines (81 loc) • 2.64 kB
JavaScript
// Teste completo do Topic Scout MCP Server
import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
console.log('🧪 Teste Completo do Topic Scout MCP Server...\n');
// Configurar variável de ambiente para teste
process.env.NEWS_API_KEY = 'test_key';
// Executar o servidor
const server = spawn('node', [join(__dirname, 'dist', 'index.js')], {
stdio: ['pipe', 'pipe', 'pipe']
});
let testStep = 0;
// Função para enviar comando
function sendCommand(method, params = {}) {
const request = {
jsonrpc: "2.0",
id: testStep + 1,
method: method,
params: params
};
console.log(`📤 Enviando: ${method}`);
server.stdin.write(JSON.stringify(request) + '\n');
}
// Capturar resposta
server.stdout.on('data', (data) => {
const response = data.toString().trim();
console.log(`📥 Resposta: ${response.substring(0, 200)}...`);
testStep++;
if (testStep === 1) {
// Teste 1: Listar tools
console.log('\n🔍 Teste 1: Listando tools disponíveis');
sendCommand('tools/list');
} else if (testStep === 2) {
// Teste 2: Buscar fontes de notícias
console.log('\n📰 Teste 2: Buscando fontes de notícias');
sendCommand('tools/call', {
name: 'get_news_sources',
arguments: {
category: 'technology',
language: 'en'
}
});
} else if (testStep === 3) {
// Teste 3: Buscar artigos (sem API key real)
console.log('\n📰 Teste 3: Buscando artigos (simulado)');
sendCommand('tools/call', {
name: 'search_news_articles',
arguments: {
topic: 'Technology',
timeframe: '7d',
max_articles: 10,
language: 'en'
}
});
} else {
// Finalizar teste
setTimeout(() => {
server.kill();
console.log('\n✅ Teste completo concluído!');
console.log('📋 Servidor está funcionando corretamente');
console.log('🔧 Tools disponíveis:');
console.log(' - search_news_articles');
console.log(' - get_news_sources');
}, 1000);
}
});
server.stderr.on('data', (data) => {
console.log(`⚠️ Log: ${data.toString().trim()}`);
});
server.on('error', (error) => {
console.error('❌ Erro ao executar servidor:', error);
});
server.on('close', (code) => {
console.log(`🏁 Servidor encerrado com código: ${code}`);
});
// Iniciar teste
setTimeout(() => {
sendCommand('tools/list');
}, 500);