UNPKG

@chainlink/mcp-server

Version:
100 lines 3.96 kB
#!/usr/bin/env node "use strict"; /** * @fileoverview Main entry point for the Chainlink MCP Server * * This MCP (Model Context Protocol) server provides AI models with access to * Chainlink documentation and knowledge through various tools and services. */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js"); const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js"); const dotenv_1 = __importDefault(require("dotenv")); const fs_1 = require("fs"); const path_1 = require("path"); // Load environment variables from .env file FIRST dotenv_1.default.config(); const tools_1 = require("./tools"); const logger_1 = require("./utils/logger"); // Read version from package.json const packageJson = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, "..", "package.json"), "utf8")); const VERSION = packageJson.version; // Load environment variables from .env file dotenv_1.default.config(); /** * MCP Server instance configured for Chainlink documentation services * * Provides capabilities for: * - CCIP chain configuration management // TODO @dev: Expand to support VRF, Data Feeds, Functions, Automation * - Knowledge base querying and retrieval * - Document processing and vector search */ const mcpServer = new mcp_js_1.McpServer({ name: "chainlink-mcp-server", version: VERSION, capabilities: tools_1.capabilities, prompts: {}, logging: true, }); /** * Initialize all MCP tools and services * * Sets up the server with available tools for AI model interaction. * Each tool provides specific functionality for Chainlink ecosystem queries. * * @param server - The MCP server instance to configure * @throws {Error} When tool initialization fails */ async function init(server) { // Validate required configuration files exist before starting tools const missingRequirements = []; try { const [ccipMainnet, ccipTestnet, dataFeedsIndex] = await Promise.all([ (0, tools_1.loadCcipDataSources)("ccip", "mainnet"), (0, tools_1.loadCcipDataSources)("ccip", "testnet"), (0, tools_1.loadDataFeedsIndex)(), ]); if (!ccipMainnet) missingRequirements.push("CCIP combined config (mainnet)"); if (!ccipTestnet) missingRequirements.push("CCIP combined config (testnet)"); if (!dataFeedsIndex) missingRequirements.push("Data Feeds index"); } catch (error) { // If loaders themselves throw unexpectedly, treat as missing required config missingRequirements.push(`Configuration loading error: ${String(error)}`); } if (missingRequirements.length > 0) { const message = `Required configuration missing: ${missingRequirements.join(", ")}`; logger_1.Logger.error(message); throw new Error(message); } await (0, tools_1.startChainlinkDeveloperAssistant)(server); } /** * Main application entry point * * Initializes the MCP server, connects to stdio transport, and starts * listening for requests from AI models. The server will continue running * until explicitly terminated or an unrecoverable error occurs. * * @throws {Error} When server initialization or connection fails */ async function main() { logger_1.Logger.info(`Starting Chainlink MCP Server v${VERSION}`); await init(mcpServer); const transport = new stdio_js_1.StdioServerTransport(); await mcpServer.connect(transport); logger_1.Logger.info(`MCP Server Version ${VERSION} running on stdio`); } // Start the server with error handling main().catch((error) => { logger_1.Logger.error(`Fatal error in main(): ${String(error)}`); mcpServer.close(); process.exit(1); }); //# sourceMappingURL=index.js.map