import 'dotenv/config';
import OpenAI from 'openai';
const CONFIG = {
apiKey: process.env.GEMINI_API_KEY || '',
baseURL: process.env.GEMINI_BASE_URL || '',
model: process.env.GEMINI_MODEL || 'gemini-3-pro-preview'
};
console.log('Config:', {
baseURL: CONFIG.baseURL,
model: CONFIG.model,
apiKeySet: !!CONFIG.apiKey
});
const openai = new OpenAI({
apiKey: CONFIG.apiKey,
baseURL: CONFIG.baseURL
});
async function callGemini(
messages: Array<{ role: 'system' | 'user' | 'assistant'; content: string }>,
options: { temperature?: number } = {}
): Promise<string> {
const response = await openai.chat.completions.create({
model: CONFIG.model,
messages,
temperature: options.temperature ?? 0.7,
});
return response.choices[0]?.message?.content ?? '';
}
// Test 1: gemini_query (basic connectivity)
async function testQuery() {
console.log('\n=== Test 1: gemini_query ===');
console.log('Sending simple query...');
const response = await callGemini([
{ role: 'user', content: 'Say "Hello, MCP!" and nothing else.' }
], { temperature: 0.3 });
console.log('Response:', response);
return response.includes('Hello');
}
// Test 2: gemini_think
async function testThink() {
console.log('\n=== Test 2: gemini_think ===');
console.log('Testing deep analysis...');
const systemPrompt = `You are a world-class analytical thinker. Use rigorous logical analysis.
Your response should be thorough and well-structured.`;
const response = await callGemini([
{ role: 'system', content: systemPrompt },
{ role: 'user', content: 'Analyze the pros and cons of microservices vs monolithic architecture in 3 sentences.' }
], { temperature: 0.7 });
console.log('Response:', response.substring(0, 300) + '...');
return response.length > 50;
}
// Test 3: gemini_brainstorm
async function testBrainstorm() {
console.log('\n=== Test 3: gemini_brainstorm ===');
console.log('Testing brainstorming with JSON output...');
const systemPrompt = `You are a creative strategist. Generate 2 distinct ideas.
IMPORTANT: Respond in valid JSON format:
{
"ideas": [
{ "title": "...", "description": "...", "pros": ["..."], "cons": ["..."] }
]
}`;
const response = await callGemini([
{ role: 'system', content: systemPrompt },
{ role: 'user', content: 'Topic: Ways to improve developer productivity. Generate 2 ideas.' }
], { temperature: 1.0 });
console.log('Response:', response.substring(0, 400) + '...');
// Try to parse JSON
try {
const jsonMatch = response.match(/\{[\s\S]*\}/);
if (jsonMatch) {
const parsed = JSON.parse(jsonMatch[0]);
console.log('Parsed ideas count:', parsed.ideas?.length || 0);
return true;
}
} catch (e) {
console.log('JSON parsing failed, but got response');
}
return response.length > 50;
}
// Test 4: gemini_review
async function testReview() {
console.log('\n=== Test 4: gemini_review ===');
console.log('Testing code review...');
const systemPrompt = `You are an expert code reviewer.
Review this code and respond in JSON format:
{
"summary": "...",
"issues": [{ "severity": "minor|major|critical", "description": "...", "recommendation": "..." }],
"score": 7.5
}`;
const codeToReview = `
function fetchData(url) {
let data = null;
fetch(url).then(r => r.json()).then(d => data = d);
return data;
}`;
const response = await callGemini([
{ role: 'system', content: systemPrompt },
{ role: 'user', content: `CODE REVIEW\n\nContent to review:\n${codeToReview}` }
], { temperature: 0.3 });
console.log('Response:', response.substring(0, 400) + '...');
// Try to parse JSON
try {
const jsonMatch = response.match(/\{[\s\S]*\}/);
if (jsonMatch) {
const parsed = JSON.parse(jsonMatch[0]);
console.log('Review score:', parsed.score);
console.log('Issues found:', parsed.issues?.length || 0);
return true;
}
} catch (e) {
console.log('JSON parsing failed, but got response');
}
return response.length > 50;
}
// Run all tests
async function runTests() {
console.log('Starting Gemini MCP Tools Tests...');
console.log('================================\n');
const results: Record<string, boolean> = {};
try {
results['query'] = await testQuery();
} catch (e) {
console.error('Query test failed:', e);
results['query'] = false;
}
try {
results['think'] = await testThink();
} catch (e) {
console.error('Think test failed:', e);
results['think'] = false;
}
try {
results['brainstorm'] = await testBrainstorm();
} catch (e) {
console.error('Brainstorm test failed:', e);
results['brainstorm'] = false;
}
try {
results['review'] = await testReview();
} catch (e) {
console.error('Review test failed:', e);
results['review'] = false;
}
console.log('\n================================');
console.log('Test Results:');
console.log('================================');
for (const [name, passed] of Object.entries(results)) {
console.log(` ${name}: ${passed ? '✅ PASSED' : '❌ FAILED'}`);
}
const allPassed = Object.values(results).every(v => v);
console.log(`\nOverall: ${allPassed ? '✅ ALL TESTS PASSED' : '❌ SOME TESTS FAILED'}`);
process.exit(allPassed ? 0 : 1);
}
runTests();