# All files / src/tools getDocumentsFeed.ts

68.75% Statements 11/16
66.66% Branches 4/6
50% Functions 1/2
71.42% Lines 10/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72

    9x
    9x

    9x
    9x
    7x
    1x

    6x

    2x
    1x

    4x

     /**
     * MCP Tool: get_documents_feed
     *
     * Get recently updated documents from the feed.
     * This is a **fixed-window feed** — the EP API does not accept a timeframe
     * or start-date parameter. It returns updates from a server-defined default
     * window (typically one month).
     *
     * **EP API Endpoint:**
     * - `GET /documents/feed`
     *
     * ISMS Policy: SC-002 (Input Validation), AC-003 (Least Privilege)
     */

    import { GetDocumentsFeedSchema } from '../schemas/europeanParliament.js';
    import { epClient } from '../clients/europeanParliamentClient.js';
    import { ToolError } from './shared/errors.js';
    import { isUpstream404, buildEmptyFeedResponse, isErrorInBody, buildFeedSuccessResponse, FIXED_WINDOW_FEED_INPUT_SCHEMA } from './shared/feedUtils.js';
    import { z } from 'zod';
    import type { ToolResult } from './shared/types.js';

    /**
     * Handles the get_documents_feed MCP tool request.
     *
     * @param args - Raw tool arguments, validated against {@link GetDocumentsFeedSchema}
     * @returns MCP tool result containing recently updated documents data
     * @security Input is validated with Zod before any API call.
     */
    export async function handleGetDocumentsFeed(args: unknown): Promise<ToolResult> {
      try {
        GetDocumentsFeedSchema.parse(args);
      } catch (error: unknown) {
        if (error instanceof z.ZodError) {
          const fieldErrors = error.issues.map((e) => `${e.path.join('.')}: ${e.message}`).join('; ');
          throw new ToolError({
            toolName: 'get_documents_feed',
            operation: 'validateInput',
            message: `Invalid parameters: ${fieldErrors}`,
            isRetryable: false,
            cause: error,
          });
        }
        throw error;
      }

      try {
        const result = await epClient.getDocumentsFeed();
        if (isErrorInBody(result)) {
          return buildEmptyFeedResponse(
            'EP API returned an error-in-body response for get_documents_feed — the upstream enrichment step may have failed.',
          );
        }
        return buildFeedSuccessResponse(result);
      } catch (error: unknown) {
        if (isUpstream404(error)) return buildEmptyFeedResponse();
        throw new ToolError({
          toolName: 'get_documents_feed',
          operation: 'fetchData',
          message: 'Failed to retrieve documents feed',
          isRetryable: true,
          cause: error,
        });
      }
    }
    /** Tool metadata for get_documents_feed */
    export const getDocumentsFeedToolMetadata = {
      name: 'get_documents_feed',
      description:
        'Get recently updated documents from the EP Open Data Portal feed. This is a fixed-window feed — the upstream EP API always returns items updated within a server-defined default window (typically one month). For contract uniformity with sliding-window feed tools, the common feed parameters (timeframe, startDate, limit, offset) are accepted but informational-only — they are silently ignored. Data source: European Parliament Open Data Portal.',
      inputSchema: FIXED_WINDOW_FEED_INPUT_SCHEMA,
    };