# Function handleAnalyzeVotingPatterns

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

  Handles the analyze_voting_patterns MCP tool request.

  Analyses an MEP's voting behaviour over an optional date range, computing group alignment rate, cross-party voting frequency, attendance rate, and a data-quality confidence level. When `compareWithGroup` is `true`, group alignment metrics are included in the result.

  #### Parameters

  - args: unknown

    Raw tool arguments, validated against AnalyzeVotingPatternsSchema

  #### Returns Promise<ToolResult>

  MCP tool result containing a VotingPatternAnalysis object, or a `dataAvailable: false` notice when voting statistics are unavailable from the EP API

  #### Throws

  - If `args` fails schema validation (e.g., missing required `mepId`, bad date format)
  - If the European Parliament API is unreachable or returns an error response

  #### Example

      const result = await handleAnalyzeVotingPatterns({
        mepId: 'MEP-124810',
        dateFrom: '2024-01-01',
        dateTo: '2024-12-31',
        compareWithGroup: true
      });
      // Returns voting statistics, group alignment, and confidence level for MEP-124810

  #### Security

  Input is validated with Zod before any API call. Personal data (MEP name, voting records) is minimised per GDPR Article 5(1)(c). All requests are rate-limited and audit-logged per ISMS Policy AU-002. Internal errors are wrapped before propagation to avoid leaking API details.

  #### Since

  0.8.0

  #### See

  - analyzeVotingPatternsToolMetadata for MCP schema registration
  - handleAnalyzeLegislativeEffectiveness for broader legislative effectiveness scoring
  - Defined in tools/analyzeVotingPatterns.ts:142