EU Parliament Monitor — API Documentation - v0.9.24
    Preparing search index...

    Class IMFMCPClient

    Index

    Constructors

    • Create a new IMF SDMX 3.0 client.

      Resolves the API base URL, timeout, fetch implementation, and Azure-APIM subscription keys from the explicit options, then from environment variables (IMF_API_BASE_URL, IMF_API_TIMEOUT_MS, IMF_API_PRIMARY_KEY, IMF_API_SECONDARY_KEY, FETCH_MCP_GATEWAY_URL, EP_MCP_GATEWAY_API_KEY), and finally module-level defaults.

      Parameters

      • options: IMFClientOptions = {}

        Optional overrides for base URL, timeout, fetch impl, and the optional fetch-proxy gateway used for restricted networks.

      Returns IMFMCPClient

    Methods

    • Base URL currently in use (read-only — set at construction time).

      Returns string

      The fully-qualified IMF SDMX base URL (no trailing slash).

    • Per-request timeout in milliseconds.

      Returns number

      The timeout currently applied to every fetch() call.

    • Mark the client as ready. HTTP is stateless so there is no real connection, but callers historically invoke connect() before use — this is preserved for API compatibility and also exercises the base URL to catch misconfiguration early.

      Returns Promise<void>

      A resolved promise; never throws for valid URLs.

    • Reset the connected flag. No real socket to close.

      Returns void

    • List every IMF database (dataflow) exposed by the SDMX 3.0 API.

      Virtual tool: imf-list-databases. Hits the umbrella /structure/dataflow endpoint which returns every published dataflow across all IMF sub-agencies (IMF.RES, IMF.STA, IMF.FAD, IMF.WHD, IMF.MCM, …) — typically ~190 entries. Each row includes the publishing agency so callers know which agency to use when calling getParameterDefs or fetchData.

      Returns Promise<MCPToolResult>

      MCP-shaped result whose content[0].text carries a JSON array of { id, name, description, agency, version } entries. Empty on error.

    • Search IMF databases by free-text keyword (case-insensitive substring match against id / name / description).

      Virtual tool: imf-search-databases. Runs client-side over the full dataflow list so a single SDMX round-trip serves every keyword query in a workflow run.

      Parameters

      • keyword: string

        Free-text keyword (e.g. "inflation", "trade").

      Returns Promise<MCPToolResult>

      Filtered list in MCP-shaped result; empty on error or when keyword is blank.

    • Fetch the dimension (parameter) definitions for a specific IMF dataflow. Essential before building an SDMX key for fetchData because each database has its own dimension set.

      Virtual tool: imf-get-parameter-defs. Uses the /structure/dataflow/{agency}/{id}/+?references=datastructure endpoint because the legacy /structure/datastructure/IMF/{id}/+ shape returns 204 on api.imf.org after the September-2025 IMF Data Portal migration retired the umbrella IMF agency.

      Parameters

      • databaseId: string

        IMF dataflow identifier (e.g. "WEO", "FM").

      • OptionalagencyId: string

        Optional override; defaults to resolveAgency.

      Returns Promise<MCPToolResult>

      MCP-shaped result whose content[0].text carries the ordered list of dimensions ([{ id, name }]). Empty on error.

    • List valid codes for a single dimension of an IMF dataflow, with an optional free-text filter to narrow the result.

      Virtual tool: imf-get-parameter-codes. Uses /structure/dataflow/{agency}/{id}/+?references=all to fetch the DSD plus its referenced conceptSchemes and codelists in one round-trip — SDMX 3.0 binds the codelist on the concept (coreRepresentation.enumeration), so resolving codes requires walking dim → conceptIdentity → conceptScheme → concept → codelist.

      Parameters

      • databaseId: string

        IMF dataflow identifier.

      • parameter: string

        Dimension name (e.g. "COUNTRY", "INDICATOR"; matched case-insensitively).

      • Optionalsearch: string

        Optional free-text search (case-insensitive substring).

      • OptionalagencyId: string

        Optional agency override; defaults to resolveAgency.

      Returns Promise<MCPToolResult>

      MCP-shaped result with [{ id, name }] rows; empty on error.

    • Fetch a time-series slice from an IMF dataflow as SDMX-JSON.

      Virtual tool: imf-fetch-data. The response is already in SDMX-JSON format; callers read the series under data.dataSets[0].series using any standard SDMX-JSON reader. (The earlier helper parseSDMXJSON in src/utils/imf-data.ts was purged in the April-2026 aggregator-pipeline migration.)

      Parameters

      • options: {
            databaseId: string;
            startYear: number;
            endYear: number;
            filters: Readonly<Record<string, readonly string[]>>;
            dimensionOrder?: readonly string[];
            agencyId?: string;
        }

        Fetch parameters.

        • databaseId: string

          IMF dataflow ID ("WEO", "FM", ...).

        • startYear: number

          Inclusive start year (e.g. 2015).

        • endYear: number

          Inclusive end year (e.g. 2030 for WEO forecasts).

        • filters: Readonly<Record<string, readonly string[]>>

          Map of dimension → selected codes. Filter keys are matched case-insensitively against the DSD dimensions (legacy lowercase country/indicator/frequency continue to work).

        • OptionaldimensionOrder?: readonly string[]

          Optional override of the dimension order used to build the SDMX key. Defaults to defaultDimensionOrder for the database.

        • OptionalagencyId?: string

          Optional SDMX agency override (e.g. "IMF.RES", "IMF.STA"). Defaults to resolveAgency.

      Returns Promise<MCPToolResult>

      MCP-shaped result whose content[0].text carries the raw SDMX-JSON response. Empty on error or invalid inputs.

    Properties

    _apiBaseUrl: string
    _timeoutMs: number
    _fetchImpl: {
        (input: URL | RequestInfo, init?: RequestInit): Promise<Response>;
        (input: string | URL | Request, init?: RequestInit): Promise<Response>;
    }

    Type Declaration

      • (input: URL | RequestInfo, init?: RequestInit): Promise<Response>
      • Parameters

        • input: URL | RequestInfo
        • Optionalinit: RequestInit

        Returns Promise<Response>

      • (input: string | URL | Request, init?: RequestInit): Promise<Response>
      • Parameters

        • input: string | URL | Request
        • Optionalinit: RequestInit

        Returns Promise<Response>

    _fetchProxyGatewayUrl: string | undefined
    _fetchProxyApiKey: string | undefined
    _imfSubscriptionKeys: readonly string[]
    _connected: boolean = false