UNPKG

synaptra

Version:

A high-performance Model Context Protocol server for GraphQL APIs with advanced features, type-safety, and developer experience improvements

104 lines 4.95 kB
#!/usr/bin/env node "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createMcpGraphQLServer = exports.McpGraphQLServer = void 0; const fs_1 = require("fs"); const path_1 = require("path"); const server_1 = require("./server"); Object.defineProperty(exports, "McpGraphQLServer", { enumerable: true, get: function () { return server_1.McpGraphQLServer; } }); Object.defineProperty(exports, "createMcpGraphQLServer", { enumerable: true, get: function () { return server_1.createMcpGraphQLServer; } }); const types_1 = require("./types"); __exportStar(require("./types"), exports); __exportStar(require("./services/graphql-client"), exports); __exportStar(require("./utils/logger"), exports); // CLI functionality async function main() { try { // Get configuration from environment variables or config file const config = getConfiguration(); // Create and start the server const server = (0, server_1.createMcpGraphQLServer)(config); // Handle graceful shutdown process.on('SIGINT', async () => { console.log('\nReceived SIGINT, shutting down gracefully...'); await server.stop(); process.exit(0); }); process.on('SIGTERM', async () => { console.log('\nReceived SIGTERM, shutting down gracefully...'); await server.stop(); process.exit(0); }); // Start the server await server.start(); } catch (error) { console.error('Failed to start MCP GraphQL server:', error); process.exit(1); } } function getConfiguration() { // Try to load from config file first const configPath = process.env.SYNAPTRA_CONFIG || './synaptra.config.json'; try { const configFile = (0, fs_1.readFileSync)((0, path_1.resolve)(configPath), 'utf-8'); const fileConfig = JSON.parse(configFile); return types_1.McpConfigSchema.parse(fileConfig); } catch (_error) { // If config file doesn't exist or is invalid, use environment variables console.warn(`Config file not found or invalid (${configPath}), using environment variables`); } // Build config from environment variables const config = { name: process.env.SYNAPTRA_NAME || 'synaptra', endpoint: process.env.SYNAPTRA_ENDPOINT || 'http://localhost:4000/graphql', headers: process.env.SYNAPTRA_HEADERS ? JSON.parse(process.env.SYNAPTRA_HEADERS) : {}, defaultApiKey: process.env.SYNAPTRA_API_KEY, allowMutations: process.env.SYNAPTRA_ALLOW_MUTATIONS === 'true', allowSubscriptions: process.env.SYNAPTRA_ALLOW_SUBSCRIPTIONS === 'true', timeout: process.env.SYNAPTRA_TIMEOUT ? parseInt(process.env.SYNAPTRA_TIMEOUT) : 30000, retries: process.env.SYNAPTRA_RETRIES ? parseInt(process.env.SYNAPTRA_RETRIES) : 3, }; // Security configuration if (process.env.SYNAPTRA_MAX_DEPTH !== undefined || process.env.SYNAPTRA_MAX_COMPLEXITY !== undefined) { config.security = { maxDepth: process.env.SYNAPTRA_MAX_DEPTH ? parseInt(process.env.SYNAPTRA_MAX_DEPTH) : 10, maxComplexity: process.env.SYNAPTRA_MAX_COMPLEXITY ? parseInt(process.env.SYNAPTRA_MAX_COMPLEXITY) : 1000, allowIntrospection: process.env.SYNAPTRA_ALLOW_INTROSPECTION !== 'false', rateLimiting: { enabled: process.env.SYNAPTRA_RATE_LIMIT_ENABLED === 'true', windowMs: process.env.SYNAPTRA_RATE_LIMIT_WINDOW ? parseInt(process.env.SYNAPTRA_RATE_LIMIT_WINDOW) : 60000, max: process.env.SYNAPTRA_RATE_LIMIT_MAX ? parseInt(process.env.SYNAPTRA_RATE_LIMIT_MAX) : 100, }, }; } // Logging configuration if (process.env.SYNAPTRA_LOG_LEVEL !== undefined) { config.logging = { level: process.env.SYNAPTRA_LOG_LEVEL || 'info', queries: process.env.SYNAPTRA_LOG_QUERIES === 'true', performance: process.env.SYNAPTRA_LOG_PERFORMANCE === 'true', }; } return types_1.McpConfigSchema.parse(config); } // Run CLI if this file is executed directly if (require.main === module) { main().catch(console.error); } //# sourceMappingURL=index.js.map