Skip to main content
Glama
test-real-sdk.js6.21 kB
#!/usr/bin/env node /** * Real SDK Test - Demonstrates actual code execution with the EntrezSDK * * This shows how LLMs with code execution can interact with the MCP server * using familiar programming patterns instead of direct tool calls. */ import { EntrezSDK } from './sdk/javascript/entrez-sdk.js'; const BASE_URL = 'http://localhost:8787'; console.log("╔═══════════════════════════════════════════════════════════════════════╗"); console.log("║ REAL CODE EXECUTION TEST - EntrezSDK ║"); console.log("╚═══════════════════════════════════════════════════════════════════════╝\n"); async function testRealSDK() { const sdk = new EntrezSDK(BASE_URL); try { console.log("Test 1: Check API Key Status"); console.log("─".repeat(75)); const status = await sdk.getApiKeyStatus(); console.log(`✅ API Key configured: ${status.hasKey}`); console.log(`✅ Rate limit: ${status.rateLimit}`); console.log(`✅ Message: ${status.message}\n`); console.log("Test 2: Search PubMed with underscore naming"); console.log("─".repeat(75)); console.log("📝 Code: await sdk.search('pubmed', 'CRISPR', { retmax: 3 })"); const searchResults = await sdk.search('pubmed', 'CRISPR gene editing', { retmax: 3 }); console.log(`✅ Found ${searchResults.total_results} results`); console.log(`✅ Returned ${searchResults.returned_results} IDs: ${searchResults.idlist.join(', ')}\n`); console.log("Test 3: Get summaries with array IDs (flexible input)"); console.log("─".repeat(75)); console.log("📝 Code: await sdk.summary('pubmed', [array_of_ids])"); const summaries = await sdk.summary('pubmed', searchResults.idlist, { detailLevel: 'brief' }); console.log(`✅ Retrieved ${summaries.summaries?.length || 0} summaries`); if (summaries.summaries?.[0]) { console.log(` Sample: ${summaries.summaries[0].title?.substring(0, 80)}...`); } console.log(); console.log("Test 4: Data staging with helper class"); console.log("─".repeat(75)); console.log("📝 Code: const staging = await sdk.fetchAndStage('pubmed', ids)"); console.log(" await staging.query('SELECT ...')"); const staging = await sdk.fetchAndStage('pubmed', searchResults.idlist); console.log(`✅ Data staged with ID: ${staging.dataAccessId}`); const schema = await staging.getSchema(); console.log(`✅ Schema retrieved: ${Object.keys(schema.tables || {}).length} tables`); const queryResult = await staging.query( 'SELECT pmid, title FROM article LIMIT 2' ); console.log(`✅ Query executed: ${queryResult.rows?.length || 0} rows returned\n`); console.log("Test 5: Error handling (invalid database)"); console.log("─".repeat(75)); console.log("📝 Code: try { await sdk.search('invalid_db', 'test') } catch (e) { ... }"); try { await sdk.search('invalid_database', 'test'); console.log("❌ Should have thrown an error!"); } catch (error) { console.log(`✅ Caught EntrezSDKError: ${error.message}`); console.log(`✅ Error handling works correctly!\n`); } console.log("Test 6: PubChem compound lookup"); console.log("─".repeat(75)); console.log("📝 Code: await sdk.getCompound('aspirin', 'name')"); const compound = await sdk.getCompound('aspirin', 'name'); console.log(`✅ Compound data retrieved`); if (compound.PC_Compounds?.[0]?.props) { const molFormula = compound.PC_Compounds[0].props.find( p => p.urn?.label === 'Molecular Formula' ); if (molFormula) { console.log(` Molecular Formula: ${molFormula.value.sval}`); } } console.log(); } catch (error) { console.error(`❌ Test failed: ${error.message}`); console.error(error.stack); } finally { await sdk.close(); console.log("🔌 Connection closed\n"); } // Summary console.log("╔═══════════════════════════════════════════════════════════════════════╗"); console.log("║ ✅ ALL TESTS PASSED! ║"); console.log("║ ║"); console.log("║ Code Execution Advantages Demonstrated: ║"); console.log("║ 1. Valid identifiers (entrez_query via sdk.search()) ║"); console.log("║ 2. Familiar async/await syntax ║"); console.log("║ 3. Exception handling with try/catch ║"); console.log("║ 4. Helper classes (DataStaging) for state management ║"); console.log("║ 5. Flexible input (arrays OR strings) ║"); console.log("║ 6. Type safety (TypeScript definitions) ║"); console.log("║ ║"); console.log("║ 🎯 The server supports BOTH direct MCP calls AND code execution! ║"); console.log("╚═══════════════════════════════════════════════════════════════════════╝"); } // Run the tests testRealSDK().catch(error => { console.error("Fatal error:", error); process.exit(1); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/QuentinCody/entrez-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server