# Function handleSearchDocuments

- handleSearchDocuments(args: unknown): Promise<ToolResult>

  Handles the search_documents MCP tool request.

  Searches European Parliament legislative documents by keyword and optional filters, or retrieves a single document by `docId`. Supports filtering by document type, date range, and responsible committee. Returned document metadata includes titles, authors, status, and links to PDF/XML versions.

  #### Parameters

  - args: unknown

    Raw tool arguments, validated against SearchDocumentsSchema

  #### Returns Promise<ToolResult>

  MCP tool result containing matching legislative documents or a single document

  #### Throws

  - If `args` fails schema validation (e.g., keyword exceeds 200 chars, bad date format)
  - If the European Parliament API is unreachable or returns an error response

  #### Example

      // Full-text keyword search with filters
      const result = await handleSearchDocuments({
        keyword: 'climate change',
        documentType: 'REPORT',
        dateFrom: '2024-01-01',
        limit: 20
      });
      // Returns up to 20 EP reports matching "climate change" from 2024 onwards

      // Single document lookup by ID
      const doc = await handleSearchDocuments({ docId: 'A9-0234/2024' });
      // Returns the full metadata for document A9-0234/2024

  #### Security

  Input is validated with Zod before any API call. Keyword pattern is restricted to alphanumeric characters, spaces, hyphens, and underscores to prevent injection. Personal data in responses is minimised per GDPR Article 5(1)(c). All requests are rate-limited and audit-logged per ISMS Policy AU-002.

  #### Since

  0.8.0

  #### See

  - searchDocumentsToolMetadata for MCP schema registration
  - handleGetExternalDocuments for non-EP (external) document retrieval
  - Defined in tools/searchDocuments.ts:67