VOOZH about

URL: https://deepwiki.com/Digilac/simap-mcp/3.3-api-integration-layer

⇱ API Integration Layer | Digilac/simap-mcp | DeepWiki


Loading...
Menu

API Integration Layer

Purpose and Scope

This document describes the API Integration Layer, which provides a centralized HTTP client for communicating with the SIMAP.ch REST API. The layer consists of the SimapClient class, endpoint definitions, and error handling mechanisms. This page focuses on the internal HTTP communication infrastructure used by all MCP tools, including rate limiting, URL building, and validation logic.

For information about the external SIMAP.ch API itself (versioning, data formats, limitations), see 5. SIMAP.ch API Integration For information about how tools are implemented and use this layer, see 3.2. Tool Architecture


Component Overview

The API Integration Layer is implemented in the src/api/ directory and consists of three main components:

ComponentFilePurpose
SimapClientsrc/api/client.ts32-101HTTP client with request handling, timeout management, and schema validation.
SlidingWindowRateLimitersrc/api/rate-limiter.ts32-116FIFO queue-based rate limiter ensuring compliance with API limits.
Endpoint Constantssrc/api/endpoints.ts5-31Centralized definitions of all SIMAP.ch API endpoints.

Sources: src/api/client.ts1-137 src/api/rate-limiter.ts1-117 src/api/endpoints.ts1-32


SimapClient Class

Class Structure

The SimapClient class implements the core HTTP communication logic. It is typically used via the default singleton instance simap src/api/client.ts136 It leverages a SlidingWindowRateLimiter to manage request pacing and supports optional Zod schema validation for responses.

Diagram: SimapClient Internal Structure


Sources: src/api/client.ts32-42 src/api/client.ts23-27 src/api/client.ts136

Rate Limiting (Sliding Window)

The SlidingWindowRateLimiter src/api/rate-limiter.ts32-116 ensures that the client does not exceed the allowed request frequency. It uses a FIFO queue to serve concurrent callers in order src/api/rate-limiter.ts7-9

Sources: src/api/rate-limiter.ts27-30 src/api/rate-limiter.ts61-72 src/api/rate-limiter.ts87-103


HTTP Request Flow

The SimapClient.get<T>() method src/api/client.ts47-100 orchestrates the complete HTTP request lifecycle.

Diagram: Request Lifecycle


Sources: src/api/client.ts47-100 src/api/rate-limiter.ts61-72


Endpoint Management

ENDPOINTS Constant

All SIMAP.ch API endpoints are defined in the ENDPOINTS object src/api/endpoints.ts7-31 This centralizes path logic and provides helper functions for dynamic paths (e.g., those requiring a projectId).

Mapping Endpoints to Entities

The following diagram bridges the code identifiers in endpoints.ts to the conceptual entities and the tools that consume them.

Diagram: Code Entity to Tool Mapping


Sources: src/api/endpoints.ts7-31 src/api/client.ts136


URL Building and Query Parameters

The buildUrl function src/api/client.ts109-131 handles the assembly of the final request URL.

  1. Path Normalization: It ensures the baseUrl trailing slash and endpoint leading slash do not result in double slashes src/api/client.ts115
  2. Serialization: It iterates through the params record src/api/client.ts118

Sources: src/api/client.ts109-131


Error Handling and Debugging

SimapApiError

When the API returns a non-OK status code, the client throws a SimapApiError src/api/client.ts72-78 This error includes the status code and the endpoint, allowing tool handlers to perform specific logic (such as mapping to user-friendly messages).

Debug Logging

The client supports a verbose debug mode enabled via the SIMAP_MCP_DEBUG environment variable src/api/client.ts15-18

Sources: src/api/client.ts15-18 src/api/client.ts54-58 src/api/client.ts81-91


Timeout Management

The client enforces a 30-second timeout by default src/api/client.ts61 It uses an AbortController to signal the fetch call to terminate if the timeout is reached src/api/client.ts60-69 The timer is cleared in a finally block to prevent resource leaks src/api/client.ts97-99

Sources: src/api/client.ts60-61 src/api/client.ts97-99