# All files / src/prompts index.ts

100% Statements 58/58
87.17% Branches 34/39
100% Functions 13/13
100% Lines 57/57

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
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536

    3x

    3x

    3x

    3x

    3x

    3x

    3x

    3x

    3x

    3x

    3x

    3x

    3x

    3x

    3x

    3x
    3x

    3x

    3x
    3x

    3x

    3x
    3x
    3x
    3x
    1x

    3x
    1x

    3x

    3x

    1x

    1x

    1x

    1x

    2x
    2x
    2x

    2x

    3x
    3x

    3x

    41x

    23x

    23x

    23x
    23x
    3x

    73x
    19x
    19x
    35x

    10x
    10x

    3x

    19x
    3x

    16x

     /**
     * MCP Prompts for European Parliament Intelligence Analysis
     *
     * Pre-built prompt templates for common EU parliamentary intelligence queries.
     * These prompts guide AI assistants through structured analysis using EP data.
     *
     * **Intelligence Perspective:** Standardized analytical templates ensure consistent,
     * reproducible intelligence products—from MEP briefings to coalition assessments.
     *
     * **Business Perspective:** Pre-built prompts lower the barrier to entry for users
     * and demonstrate the full analytical capability of the MCP server.
     *
     * ISMS Policy: SC-002 (Input Validation), AC-003 (Least Privilege)
     *
     * @see https://spec.modelcontextprotocol.io/specification/server/prompts/
     */

    import { z } from 'zod';

    /**
     * Prompt metadata for MCP listing
     */
    export interface PromptMetadata {
      name: string;
      description: string;
      arguments?: {
        name: string;
        description: string;
        required: boolean;
      }[];
    }

    /**
     * Prompt message content
     */
    export interface PromptMessage {
      role: 'user' | 'assistant';
      content: {
        type: 'text';
        text: string;
      };
    }

    /**
     * Prompt result
     */
    export interface PromptResult {
      description: string;
      messages: PromptMessage[];
      [key: string]: unknown;
    }

    const mepBriefingPrompt: PromptMetadata = {
      name: 'mep_briefing',
      description: 'Generate a comprehensive MEP intelligence briefing covering voting record, committee roles, legislative activity, and influence assessment.',
      arguments: [
        { name: 'mepId', description: 'MEP identifier', required: true },
        { name: 'period', description: 'Analysis period (e.g., "2024", "last-6-months")', required: false }
      ]
    };

    const coalitionAnalysisPrompt: PromptMetadata = {
      name: 'coalition_analysis',
      description: 'Analyze coalition dynamics and voting blocs in the European Parliament, identifying cross-party alliances and emerging political alignments.',
      arguments: [
        { name: 'policyArea', description: 'Policy area to focus on (e.g., "environment", "digital", "trade")', required: false },
        { name: 'period', description: 'Analysis period', required: false }
      ]
    };

    const legislativeTrackingPrompt: PromptMetadata = {
      name: 'legislative_tracking',
      description: 'Track and analyze the progress of legislative procedures through the European Parliament, including committee stages, amendments, and voting outcomes.',
      arguments: [
        { name: 'procedureId', description: 'Legislative procedure identifier', required: false },
        { name: 'committee', description: 'Committee abbreviation to filter by', required: false }
      ]
    };

    const politicalGroupComparisonPrompt: PromptMetadata = {
      name: 'political_group_comparison',
      description: 'Compare political groups across voting discipline, legislative output, attendance, and cohesion metrics.',
      arguments: [
        { name: 'groups', description: 'Comma-separated political group names (e.g., "EPP,S&D,Renew")', required: false }
      ]
    };

    const committeeActivityPrompt: PromptMetadata = {
      name: 'committee_activity_report',
      description: 'Generate an activity report for a European Parliament committee, covering meetings, documents produced, legislative opinions, and member engagement.',
      arguments: [
        { name: 'committeeId', description: 'Committee abbreviation (e.g., "ENVI", "ITRE", "LIBE")', required: true }
      ]
    };

    const votingPatternAnalysisPrompt: PromptMetadata = {
      name: 'voting_pattern_analysis',
      description: 'Analyze voting patterns to identify trends, anomalies, and cross-party alignments on specific policy topics.',
      arguments: [
        { name: 'topic', description: 'Policy topic or keyword', required: false },
        { name: 'mepId', description: 'Focus on specific MEP', required: false }
      ]
    };

    const PromptArgsSchema = z.record(
      z.string().min(1).max(50),
      z.string().min(1).max(200)
    );

    /**
     * Typed Zod schema for MEP briefing prompt arguments.
     * Exported for use in integration tests and client validation.
     */
    export const MepBriefingArgsSchema = z.object({
      mepId: z.string().min(1).max(100).describe('MEP identifier'),
      period: z.string().min(1).max(50).optional().describe('Analysis period'),
    });

    /**
     * Typed Zod schema for coalition analysis prompt arguments.
     */
    export const CoalitionAnalysisArgsSchema = z.object({
      policyArea: z.string().min(1).max(100).optional().describe('Policy area to focus on'),
      period: z.string().min(1).max(50).optional().describe('Analysis period'),
    });

    /**
     * Typed Zod schema for legislative tracking prompt arguments.
     */
    export const LegislativeTrackingArgsSchema = z.object({
      procedureId: z.string().min(1).max(100).optional().describe('Legislative procedure identifier'),
      committee: z.string().min(1).max(10).optional().describe('Committee abbreviation'),
    });

    /**
     * Typed Zod schema for political group comparison prompt arguments.
     */
    export const PoliticalGroupComparisonArgsSchema = z.object({
      groups: z.string().min(1).max(200).optional().describe('Comma-separated political group names'),
    });

    /**
     * Typed Zod schema for committee activity report prompt arguments.
     */
    export const CommitteeActivityArgsSchema = z.object({
      committeeId: z.string().min(1).max(10).describe('Committee abbreviation'),
    });

    /**
     * Typed Zod schema for voting pattern analysis prompt arguments.
     */
    export const VotingPatternArgsSchema = z.object({
      topic: z.string().min(1).max(200).optional().describe('Policy topic or keyword'),
      mepId: z.string().min(1).max(100).optional().describe('Focus on specific MEP'),
    });

    /**
     * Typed Zod schema for country delegation analysis prompt arguments.
     */
    export const CountryDelegationArgsSchema = z.object({
      country: z.string().min(1).max(50).describe('EU member state name or ISO country code'),
      period: z.string().min(1).max(50).optional().describe('Analysis period'),
    });

    /** @internal Country delegation analysis prompt metadata */
    const countryDelegationAnalysisPrompt: PromptMetadata = {
      name: 'country_delegation_analysis',
      description: 'Analyse the MEP delegation from a specific EU member state, including voting cohesion, committee presence, legislative contribution, and cross-party dynamics.',
      arguments: [
        { name: 'country', description: 'EU member state name or ISO country code', required: true },
        { name: 'period', description: 'Analysis period (e.g., "2024", "current-term")', required: false },
      ],
    };

    /**
     * Generate an MEP intelligence briefing prompt
     *
     * @param args - Prompt arguments containing mepId and optional period
     * @returns Structured prompt result for MEP profiling analysis
     */
    function generateMepBriefing(args: Record<string, string>): PromptResult {
      const mepId = args['mepId'] ?? 'unknown';
      const period = args['period'] ?? 'current term';

      return {
        description: `MEP Intelligence Briefing for ${mepId}`,
        messages: [
          {
            role: 'user',
            content: {
              type: 'text',
              text: `Generate a comprehensive intelligence briefing for MEP ${mepId} covering the ${period} period.

    Use these European Parliament MCP tools to gather data:
    1. **get_mep_details** — Get MEP profile, committee memberships, and contact info
    2. **analyze_voting_patterns** — Analyze voting record and political group alignment
    3. **assess_mep_influence** — Compute composite influence score across 5 dimensions
    4. **get_parliamentary_questions** — Review parliamentary questions filed

    Structure the briefing as follows:
    - **Executive Summary**: Key findings and overall assessment
    - **Profile Overview**: Political group, country, committee roles, tenure
    - **Voting Record**: Attendance rate, party loyalty, key votes
    - **Legislative Activity**: Reports authored, amendments, opinions
    - **Influence Assessment**: Score, rank, dimension breakdown
    - **Parliamentary Questions**: Focus areas, question trends
    - **Analytical Judgments**: Confidence-rated assessments of influence trajectory

    Data source: European Parliament Open Data Portal
    Confidence levels: HIGH (>80% data coverage), MEDIUM (50-80%), LOW (<50%)`
            }
          }
        ]
      };
    }

    /**
     * Generate a coalition dynamics analysis prompt
     *
     * @param args - Prompt arguments containing optional policyArea and period
     * @returns Structured prompt result for coalition mapping
     */
    function generateCoalitionAnalysis(args: Record<string, string>): PromptResult {
      const policyArea = args['policyArea'] ?? 'all policy areas';
      const period = args['period'] ?? 'current term';

      return {
        description: `Coalition dynamics analysis for ${policyArea}`,
        messages: [
          {
            role: 'user',
            content: {
              type: 'text',
              text: `Analyze coalition dynamics in the European Parliament for ${policyArea} during ${period}.

    Use these MCP tools:
    1. **analyze_coalition_dynamics** — Detect voting blocs and cross-party alliances
    2. **compare_political_groups** — Compare group metrics across dimensions
    3. **detect_voting_anomalies** — Identify unexpected voting behavior
    4. **get_voting_records** — Retrieve raw voting data

    Analysis framework:
    - **Current Coalition Map**: Identify active voting blocs and alliances
    - **Grand Coalition Analysis**: EPP + S&D vs alternative majority patterns
    - **Cross-Party Bridges**: MEPs or groups acting as coalition brokers
    - **Cohesion Metrics**: Internal discipline within each political group
    - **Emerging Trends**: New alignments or shifting alliances
    - **Anomaly Detection**: Unexpected voting patterns signaling realignment
    - **Risk Assessment**: Coalition stability and fracture probability

    Data source: European Parliament Open Data Portal`
            }
          }
        ]
      };
    }

    /**
     * Generate a legislative tracking prompt
     *
     * @param args - Prompt arguments containing optional procedureId and committee
     * @returns Structured prompt result for legislative pipeline monitoring
     */
    function generateLegislativeTracking(args: Record<string, string>): PromptResult {
      const procedureId = args['procedureId'];
      const committee = args['committee'];
      const focusParts: string[] = [];
      if (procedureId !== undefined) {
        focusParts.push(`procedure ${procedureId}`);
      }
      if (committee !== undefined) {
        focusParts.push(`committee ${committee}`);
      }
      const focus = focusParts.length > 0
        ? focusParts.join(', ')
        : 'active legislative pipeline';

      return {
        description: `Legislative tracking for ${focus}`,
        messages: [
          {
            role: 'user',
            content: {
              type: 'text',
              text: `Track and analyze the legislative pipeline for ${focus}.

    Use these MCP tools:
    1. **track_legislation** — Get procedure status, timeline, and key actors
    2. **monitor_legislative_pipeline** — Pipeline overview with status filtering
    3. **search_documents** — Find related legislative documents
    4. **analyze_legislative_effectiveness** — Measure legislative output metrics

    Deliver a report covering:
    - **Pipeline Status**: Current stage, next milestones, timeline
    - **Key Actors**: Rapporteur, shadow rapporteurs, committee responsibilities
    - **Amendment Analysis**: Volume, success rate, key contested provisions
    - **Voting Outlook**: Probable outcome based on political alignment
    - **Timeline Assessment**: On-track vs delayed with contributing factors
    - **Related Procedures**: Cross-referencing linked legislative files

    Data source: European Parliament Open Data Portal`
            }
          }
        ]
      };
    }

    /**
     * Generate a political group comparison prompt
     *
     * @param args - Prompt arguments containing optional groups list
     * @returns Structured prompt result for multi-group comparison
     */
    function generateGroupComparison(args: Record<string, string>): PromptResult {
      const groups = args['groups'] ?? 'EPP, S&D, Renew Europe, Greens/EFA, ECR, ID, The Left';

      return {
        description: `Political group comparison: ${groups}`,
        messages: [
          {
            role: 'user',
            content: {
              type: 'text',
              text: `Compare the following European Parliament political groups: ${groups}

    Use these MCP tools:
    1. **compare_political_groups** — Multi-dimensional comparison
    2. **analyze_coalition_dynamics** — Cross-group voting patterns
    3. **get_meps** — Group membership and composition data
    4. **get_voting_records** — Group-level voting statistics

    Compare across these dimensions:
    - **Size & Composition**: Member count, national delegation breakdown
    - **Voting Discipline**: Cohesion rate, dissent patterns
    - **Legislative Output**: Reports, amendments, opinions authored
    - **Attendance**: Plenary and committee participation rates
    - **Policy Alignment**: Voting patterns on key policy domains
    - **Coalition Behavior**: Alliance frequencies and preferred partners
    - **Effectiveness Metrics**: Legislative success rate

    Data source: European Parliament Open Data Portal`
            }
          }
        ]
      };
    }

    /**
     * Generate a committee activity report prompt
     *
     * @param args - Prompt arguments containing committeeId
     * @returns Structured prompt result for committee workload analysis
     */
    function generateCommitteeActivity(args: Record<string, string>): PromptResult {
      const committeeId = args['committeeId'] ?? 'unknown';

      return {
        description: `Committee activity report for ${committeeId}`,
        messages: [
          {
            role: 'user',
            content: {
              type: 'text',
              text: `Generate a comprehensive activity report for the ${committeeId} committee.

    Use these MCP tools:
    1. **get_committee_info** — Committee membership, leadership, responsibilities
    2. **search_documents** — Documents produced by the committee
    3. **monitor_legislative_pipeline** — Active legislative files in committee
    4. **analyze_legislative_effectiveness** — Committee effectiveness metrics

    Report structure:
    - **Committee Overview**: Mandate, membership, leadership, meeting frequency
    - **Legislative Workload**: Active files, opinions requested, reports adopted
    - **Document Production**: Reports, opinions, amendments volume
    - **Meeting Activity**: Frequency, attendance, agenda topics
    - **Key Legislative Files**: Priority items and their status
    - **Cross-Committee Coordination**: Joint work with other committees

    Data source: European Parliament Open Data Portal`
            }
          }
        ]
      };
    }

    /**
     * Generate a voting pattern analysis prompt
     *
     * @param args - Prompt arguments containing optional topic and mepId
     * @returns Structured prompt result for voting pattern detection
     */
    function generateVotingAnalysis(args: Record<string, string>): PromptResult {
      const topic = args['topic'] ?? 'key legislative votes';
      const mepId = args['mepId'];
      const focus = mepId !== undefined ? `MEP ${mepId} on ${topic}` : topic;

      return {
        description: `Voting pattern analysis: ${focus}`,
        messages: [
          {
            role: 'user',
            content: {
              type: 'text',
              text: `Analyze voting patterns for ${focus} in the European Parliament.

    Use these MCP tools:
    1. **get_voting_records** — Retrieve voting data
    2. **analyze_voting_patterns** — Pattern detection and group alignment${mepId !== undefined ? `\n3. **assess_mep_influence** — MEP influence metrics for ${mepId}` : ''}
    4. **detect_voting_anomalies** — Identify anomalous patterns
    5. **analyze_coalition_dynamics** — Coalition formation on these votes

    Analysis framework:
    - **Voting Distribution**: For/Against/Abstain breakdowns
    - **Group Alignment**: How political groups voted
    - **Cross-Party Patterns**: Unexpected cross-group voting blocs
    - **Anomaly Detection**: Statistically unusual voting behavior
    - **Trend Analysis**: Evolution of voting patterns over time
    - **Predictive Assessment**: Likely voting direction for upcoming related votes

    Data source: European Parliament Open Data Portal`
            }
          }
        ]
      };
    }

    /**
     * Generate a country delegation analysis prompt
     *
     * @param args - Prompt arguments containing country and optional period
     * @returns Structured prompt result for country delegation intelligence
     */
    function generateCountryDelegationAnalysis(args: Record<string, string>): PromptResult {
      const country = args['country'] ?? 'unknown';
      const period = args['period'] ?? 'current term';

      return {
        description: `Country delegation analysis: ${country} (${period})`,
        messages: [
          {
            role: 'user',
            content: {
              type: 'text',
              text: `Analyse the European Parliament delegation from ${country} for the ${period} period.

    Use these MCP tools to gather data:
    1. **get_meps** — List all MEPs from ${country}
    2. **get_mep_details** — Individual MEP profiles and committee roles
    3. **analyze_voting_patterns** — Voting record and group alignment per MEP
    4. **analyze_country_delegation** — Aggregate delegation analytics
    5. **analyze_coalition_dynamics** — Cross-party alliances within delegation
    6. **assess_mep_influence** — Influence scores for key delegation members

    Analysis framework:
    - **Delegation Overview**: Total MEPs, political group distribution, parliamentary term
    - **Committee Presence**: Which committees delegation members chair or sit on
    - **Legislative Contributions**: Reports, amendments, opinions authored
    - **Voting Cohesion**: Intra-delegation agreement rate; deviations from group line
    - **Cross-Party Dynamics**: Alliances formed with MEPs from other member states
    - **Influence Profile**: Top-3 most influential MEPs and their policy focus areas
    - **Policy Priorities**: Recurring legislative topics championed by delegation

    Data source: European Parliament Open Data Portal`
            }
          }
        ]
      };
    }

    /**
     * Get all prompt metadata for MCP listing
     */
    export function getPromptMetadataArray(): PromptMetadata[] {
      return [
        mepBriefingPrompt,
        coalitionAnalysisPrompt,
        legislativeTrackingPrompt,
        politicalGroupComparisonPrompt,
        committeeActivityPrompt,
        votingPatternAnalysisPrompt,
        countryDelegationAnalysisPrompt,
      ];
    }

    /**
     * Handle GetPrompt request
     *
     * @param name - Prompt name
     * @param args - Prompt arguments
     * @returns Prompt result with messages
     * @throws Error if prompt name is unknown
     */
    export function handleGetPrompt(
      name: string,
      args?: Record<string, string>
    ): PromptResult {
      const validatedArgs = args !== undefined
        ? PromptArgsSchema.parse(args)
        : {};

      const promptGenerators: Record<string, (a: Record<string, string>) => PromptResult> = {
        'mep_briefing': generateMepBriefing,
        'coalition_analysis': generateCoalitionAnalysis,
        'legislative_tracking': generateLegislativeTracking,
        'political_group_comparison': generateGroupComparison,
        'committee_activity_report': generateCommitteeActivity,
        'voting_pattern_analysis': generateVotingAnalysis,
        'country_delegation_analysis': generateCountryDelegationAnalysis,
      };

      const generator = promptGenerators[name];
      if (generator === undefined) {
        throw new Error(`Unknown prompt: ${name}`);
      }

      const metadata = getPromptMetadataArray().find((prompt) => prompt.name === name);
      Eif (metadata?.arguments !== undefined) {
        const missingRequired = metadata.arguments
          .filter((arg) => arg.required)
          .filter((arg) => {
            const value = validatedArgs[arg.name];
            return value === undefined || (typeof value === 'string' && value.trim() === '');
          })
          .map((arg) => arg.name);

        if (missingRequired.length > 0) {
          throw new Error(
            `Missing required argument(s) for prompt "${name}": ${missingRequired.join(', ')}`
          );
        }
      }

      return generator(validatedArgs);
    }