UNPKG

fred-mcp-server

Version:

Federal Reserve Economic Data (FRED) MCP Server - Access all 800,000+ economic time series with search, browse, and data retrieval capabilities

73 lines (72 loc) 2.13 kB
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; import * as fredServer from "./index.js"; /** * Wrapper class for the FRED MCP Server * Designed to be easily tested by providing mocking points */ export class FREDServerWrapper { // References to dependency functions _createServer; _startServer; // Store server and transport as instance variables _server = null; _transport = null; /** * Create a new wrapper for the FRED server * Allows for dependency injection during tests */ constructor(createServerFn = fredServer.createServer, startServerFn = fredServer.startServer) { this._createServer = createServerFn; this._startServer = startServerFn; } /** * Get access to the server instance */ get server() { return this._server; } /** * Create the server instance */ initialize() { this._server = this._createServer(); return this._server; } /** * Start the server with the given transport * If no transport is provided, a new StdioServerTransport is created */ async start(transport) { if (!this._server) { this.initialize(); } this._transport = transport || new StdioServerTransport(); // Start the server return await this._startServer(this._server, this._transport); } /** * Convenience method to create and start the server in one step */ async createAndStart() { this.initialize(); return await this.start(); } } /** * Main entry point when this file is executed directly */ async function main() { const wrapper = new FREDServerWrapper(); const success = await wrapper.createAndStart(); if (!success) { process.exit(1); } } // Only run the main function if this file is executed directly if (import.meta.url === `file://${process.argv[1]}`) { main().catch((error) => { console.error("Fatal error in main():", error); process.exit(1); }); } export default new FREDServerWrapper();