list_nodit_aptos_indexer_api_query_root
Retrieve all query roots for the Nodit Aptos Indexer GraphQL API to simplify access to blockchain data for AI-driven applications.
Instructions
Lists all query roots available in the Nodit Aptos Indexer GraphQL API.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/aptos-indexer.ts:23-53 (handler)The main execution logic of the tool: loads the Nodit Aptos Indexer API spec, iterates through sources and tables to collect custom_name query roots, sorts them, and returns a formatted text list. Handles errors with createErrorResponse.async () => { const toolName = "list_nodit_aptos_indexer_api_query_root"; try { if (!noditAptosIndexerApiSpec || !noditAptosIndexerApiSpec.metadata || !noditAptosIndexerApiSpec.metadata.sources) { return createErrorResponse("Failed to load or parse the Aptos Indexer API schema", toolName); } const queryRoots: string[] = []; for (const source of noditAptosIndexerApiSpec.metadata.sources) { if (source.tables) { for (const tableInfo of source.tables) { if (tableInfo.configuration && tableInfo.configuration.custom_name) { queryRoots.push(tableInfo.configuration.custom_name); } } } } if (queryRoots.length === 0) { return createErrorResponse("No query roots found in the Aptos Indexer API schema", toolName); } queryRoots.sort(); const resultText = `Available Aptos Indexer API query roots:\n\n${queryRoots.join('\n')}`; return { content: [{ type: "text", text: resultText }] }; } catch (error) { return createErrorResponse(`Error processing Aptos Indexer API schema: ${(error as Error).message}`, toolName); } }
- src/tools/aptos-indexer.ts:18-54 (registration)Registers the 'list_nodit_aptos_indexer_api_query_root' tool on the MCP server within registerAptosIndexerTools, providing description and empty input schema ({}). Loads the API spec beforehand.const noditAptosIndexerApiSpec: AptosIndexerApiSpec = loadNoditAptosIndexerApiSpec(); server.tool( "list_nodit_aptos_indexer_api_query_root", "Lists all query roots available in the Nodit Aptos Indexer GraphQL API.", {}, async () => { const toolName = "list_nodit_aptos_indexer_api_query_root"; try { if (!noditAptosIndexerApiSpec || !noditAptosIndexerApiSpec.metadata || !noditAptosIndexerApiSpec.metadata.sources) { return createErrorResponse("Failed to load or parse the Aptos Indexer API schema", toolName); } const queryRoots: string[] = []; for (const source of noditAptosIndexerApiSpec.metadata.sources) { if (source.tables) { for (const tableInfo of source.tables) { if (tableInfo.configuration && tableInfo.configuration.custom_name) { queryRoots.push(tableInfo.configuration.custom_name); } } } } if (queryRoots.length === 0) { return createErrorResponse("No query roots found in the Aptos Indexer API schema", toolName); } queryRoots.sort(); const resultText = `Available Aptos Indexer API query roots:\n\n${queryRoots.join('\n')}`; return { content: [{ type: "text", text: resultText }] }; } catch (error) { return createErrorResponse(`Error processing Aptos Indexer API schema: ${(error as Error).message}`, toolName); } } );
- loadNoditAptosIndexerApiSpec function loads the '../nodit-aptos-indexer-api-schema.json' file, which provides the metadata sources and tables used to derive query roots.export function loadNoditAptosIndexerApiSpec(): AptosIndexerApiSpec { const schemaPath = path.resolve(__dirname, '../nodit-aptos-indexer-api-schema.json'); return loadOpenapiSpecFile(schemaPath) as AptosIndexerApiSpec; }
- AptosIndexerApiSpec TypeScript interface defines the structure expected for the schema JSON, including metadata.sources[].tables[] with configuration.custom_name for query roots.export interface AptosIndexerApiSpec { metadata?: { sources?: Array<{ tables?: Array<{ table?: string; configuration?: { custom_name?: string; }; select_permissions?: Array<{ permission?: { columns?: string[]; }; }>; object_relationships?: Array<Relationship>; array_relationships?: Array<Relationship>; }>; }>; }; }
- createErrorResponse utility formats error responses consistently, used multiple times in the tool handler.export function createErrorResponse(message: string, toolName: string): { content: { type: "text"; text: string }[] } { log(`Tool Error (${toolName}): ${message}`); return { content: [{ type: "text" as const, text: `Tool Error: ${message}` }] }; }