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 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 | 10x 10x 10x 10x 10x 10x 10x 10x 147x 147x 147x 67x 67x 67x 3x 8x 8x 8x 8x 5x 8x 5x 8x 7x 7x 7x 7x 1x 1x 1x 7x 7x 7x 7x 7x 5x 7x 6x 6x 6x 6x 1x 6x 6x 3x 3x 1x 1x 2x 2x 3x 3x 1x 1x 2x 2x 2x 3x 3x 4x 4x 3x 1x 1x 2x 4x 2x 2x 2x 2x 4x 2x 2x 2x 4x 2x 2x 2x 4x 2x 2x 2x 2x 2x 3x 1x 1x 2x 2x 2x 2x 2x 2x 2x 4x 2x 2x 2x 4x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 4x 2x 2x 2x 4x 2x 2x 2x 4x 2x 2x 2x 4x 2x 2x 2x 2x 2x 2x 4x 2x 2x 2x 2x 4x 10x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 10x 3x 2x 2x 3x 5x 2x 2x | // SPDX-FileCopyrightText: 2024-2026 Hack23 AB
// SPDX-License-Identifier: Apache-2.0
/**
* @module MCP/EPMCPClient
* @description European Parliament MCP client — domain-specific tool wrappers
* built on top of the generic {@link MCPConnection} transport.
*/
import { MCPConnection } from './mcp-connection.js';
import type {
MCPClientOptions,
MCPToolResult,
GetMEPsOptions,
GetPlenarySessionsOptions,
SearchDocumentsOptions,
GetParliamentaryQuestionsOptions,
GetCommitteeInfoOptions,
MonitorLegislativePipelineOptions,
AssessMEPInfluenceOptions,
AnalyzeCoalitionDynamicsOptions,
DetectVotingAnomaliesOptions,
ComparePoliticalGroupsOptions,
VotingRecordsOptions,
VotingPatternsOptions,
GenerateReportOptions,
AnalyzeLegislativeEffectivenessOptions,
AnalyzeCommitteeActivityOptions,
TrackMEPAttendanceOptions,
AnalyzeCountryDelegationOptions,
GeneratePoliticalLandscapeOptions,
GetCurrentMEPsOptions,
GetSpeechesOptions,
GetProceduresOptions,
GetAdoptedTextsOptions,
GetEventsOptions,
GetMeetingActivitiesOptions,
GetMeetingDecisionsOptions,
GetMEPDeclarationsOptions,
GetIncomingMEPsOptions,
GetOutgoingMEPsOptions,
GetHomonymMEPsOptions,
GetPlenaryDocumentsOptions,
GetCommitteeDocumentsOptions,
GetPlenarySessionDocumentsOptions,
GetPlenarySessionDocumentItemsOptions,
GetControlledVocabulariesOptions,
GetExternalDocumentsOptions,
GetMeetingForeseenActivitiesOptions,
GetProcedureEventsOptions,
GetMeetingPlenarySessionDocumentsOptions,
GetMeetingPlenarySessionDocumentItemsOptions,
NetworkAnalysisOptions,
SentimentTrackerOptions,
EarlyWarningSystemOptions,
ComparativeIntelligenceOptions,
CorrelateIntelligenceOptions,
GetAllGeneratedStatsOptions,
GetMEPsFeedOptions,
GetEventsFeedOptions,
GetProceduresFeedOptions,
GetAdoptedTextsFeedOptions,
GetMEPDeclarationsFeedOptions,
GetDocumentsFeedOptions,
GetPlenaryDocumentsFeedOptions,
GetCommitteeDocumentsFeedOptions,
GetPlenarySessionDocumentsFeedOptions,
GetExternalDocumentsFeedOptions,
GetParliamentaryQuestionsFeedOptions,
GetCorporateBodiesFeedOptions,
GetControlledVocabulariesFeedOptions,
} from '../types/index.js';
/** Fallback payload for analyze_legislative_effectiveness when validation fails or tool is unavailable */
const EFFECTIVENESS_FALLBACK = '{"effectiveness": null}';
/** Fallback payload for MEP list tools */
const MEPS_FALLBACK = '{"meps": []}';
/** Fallback payload for document list tools */
const DOCUMENTS_FALLBACK = '{"documents": []}';
/** Fallback payload for event list tools */
const EVENTS_FALLBACK = '{"events": []}';
/** Fallback payload for activity list tools */
const ACTIVITIES_FALLBACK = '{"activities": []}';
/** Fallback payload for item list tools */
const ITEMS_FALLBACK = '{"items": []}';
/** Fallback payload for intelligence analysis tools */
const INTELLIGENCE_FALLBACK = '{"analysis": null}';
/** Fallback payload for precomputed statistics */
const STATS_FALLBACK = '{"stats": null}';
/**
* MCP Client for European Parliament data access.
* Extends {@link MCPConnection} with EP-specific tool wrapper methods.
*/
export class EuropeanParliamentMCPClient extends MCPConnection {
/**
* Generic error-safe wrapper around {@link callToolWithRetry}.
* Retries transient failures (timeouts, connection drops) with a bounded
* back-off delay before falling back. Non-retriable errors (session expiry,
* rate limits, programmer errors) are caught immediately without additional delay.
* Catches any error thrown by the tool (or by the args factory), logs a warning,
* and returns a fallback payload.
*
* Accepts either a plain args object or a factory function `() => object`.
* Using a factory ensures that options normalization/destructuring runs inside
* the try/catch so invalid runtime inputs fall back gracefully.
*
* @param toolName - MCP tool name
* @param args - Tool arguments or a factory that builds them
* @param fallbackText - JSON text to return when the tool is unavailable
* @returns Tool result or fallback
*/
private async safeCallTool(
toolName: string,
args: object | (() => object),
fallbackText: string
): Promise<MCPToolResult> {
try {
const resolvedArgs = typeof args === 'function' ? args() : args;
return await this.callToolWithRetry(toolName, resolvedArgs);
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
console.warn(`${toolName} not available:`, message);
return { content: [{ type: 'text', text: fallbackText }] };
}
}
/**
* Get Members of European Parliament
*
* @param options - Filter options
* @returns List of MEPs
*/
async getMEPs(options: GetMEPsOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('get_meps', options, MEPS_FALLBACK);
}
/**
* Get plenary sessions
*
* @param options - Filter options. `dateFrom` is mapped to `startDate` and `dateTo` to `endDate`
* per the tool schema when the canonical fields are absent.
* @returns Plenary sessions data
*/
async getPlenarySessions(options: GetPlenarySessionsOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool(
'get_plenary_sessions',
() => {
const { dateFrom, dateTo, ...rest } = options;
const normalizedOptions: Record<string, unknown> = { ...rest };
if (normalizedOptions['startDate'] === undefined && dateFrom !== undefined) {
normalizedOptions['startDate'] = dateFrom;
}
if (normalizedOptions['endDate'] === undefined && dateTo !== undefined) {
normalizedOptions['endDate'] = dateTo;
}
return normalizedOptions;
},
'{"sessions": []}'
);
}
/**
* Search legislative documents
*
* @param options - Search options (normalizes `query` to `keyword` if `keyword` is absent,
* since the MCP tool schema requires the `keyword` parameter)
* @returns Search results
*/
async searchDocuments(options: SearchDocumentsOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool(
'search_documents',
() => {
const { query, ...rest } = options;
const normalizedOptions: Record<string, unknown> = { ...rest };
// MCP tool schema expects 'keyword', not 'query'
if (normalizedOptions['keyword'] === undefined && query !== undefined) {
const trimmed = String(query).trim();
Eif (trimmed.length > 0) {
normalizedOptions['keyword'] = trimmed;
}
}
return normalizedOptions;
},
DOCUMENTS_FALLBACK
);
}
/**
* Get parliamentary questions
*
* @param options - Filter options. `dateFrom` is mapped to `startDate` per the tool schema.
* `dateTo` is intentionally ignored because the `get_parliamentary_questions` tool schema
* only supports `startDate` as a date filter; passing `dateTo` would have no effect.
* @returns Parliamentary questions data
*/
async getParliamentaryQuestions(
options: GetParliamentaryQuestionsOptions = {}
): Promise<MCPToolResult> {
return this.safeCallTool(
'get_parliamentary_questions',
() => {
const { dateFrom, dateTo: _dateTo, ...rest } = options;
const toolOptions: Record<string, unknown> = { ...rest };
if (toolOptions['startDate'] === undefined && dateFrom !== undefined) {
toolOptions['startDate'] = dateFrom;
}
return toolOptions;
},
'{"questions": []}'
);
}
/**
* Get committee information
*
* @param options - Filter options
* @returns Committee info data
*/
async getCommitteeInfo(options: GetCommitteeInfoOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool(
'get_committee_info',
() => {
const { committeeId, ...rest } = options;
const toolOptions: Record<string, unknown> = { ...rest };
// MCP tool schema expects 'abbreviation', not 'committeeId'
if (toolOptions['abbreviation'] === undefined && committeeId !== undefined) {
toolOptions['abbreviation'] = committeeId;
}
return toolOptions;
},
'{"committees": []}'
);
}
/**
* Monitor legislative pipeline
*
* @param options - Filter options
* @returns Legislative pipeline data
*/
async monitorLegislativePipeline(
options: MonitorLegislativePipelineOptions = {}
): Promise<MCPToolResult> {
return this.safeCallTool('monitor_legislative_pipeline', options, '{"procedures": []}');
}
/**
* Analyze legislative effectiveness of an MEP or committee
*
* @param options - Options including subjectType and subjectId
* @returns Legislative effectiveness data
*/
async analyzeLegislativeEffectiveness(
options: AnalyzeLegislativeEffectivenessOptions
): Promise<MCPToolResult> {
const { subjectType, subjectId } = options;
if (subjectId.trim().length === 0) {
console.warn(
'analyze_legislative_effectiveness called without valid subjectId (non-empty string required)'
);
return { content: [{ type: 'text', text: EFFECTIVENESS_FALLBACK }] };
}
const trimmedSubjectId = subjectId.trim();
return this.safeCallTool(
'analyze_legislative_effectiveness',
{ ...options, subjectType, subjectId: trimmedSubjectId },
EFFECTIVENESS_FALLBACK
);
}
/**
* Assess MEP influence using 5-dimension scoring model
*
* @param options - Options including required mepId and optional date range
* @returns MEP influence score and breakdown
*/
async assessMEPInfluence(options: AssessMEPInfluenceOptions): Promise<MCPToolResult> {
const trimmedMepId = options && typeof options.mepId === 'string' ? options.mepId.trim() : '';
if (trimmedMepId.length === 0) {
console.warn('assess_mep_influence called without valid mepId (non-empty string required)');
return { content: [{ type: 'text', text: '{"influence": {}}' }] };
}
return this.safeCallTool(
'assess_mep_influence',
{ ...options, mepId: trimmedMepId },
'{"influence": {}}'
);
}
/**
* Analyze coalition dynamics and cohesion
*
* @param options - Options including optional political groups and date range
* @returns Coalition cohesion and stress analysis
*/
async analyzeCoalitionDynamics(
options: AnalyzeCoalitionDynamicsOptions = {}
): Promise<MCPToolResult> {
return this.safeCallTool('analyze_coalition_dynamics', options, '{"coalitions": []}');
}
/**
* Detect voting anomalies and party defections
*
* @param options - Options including optional MEP id, political group, and date
* @returns Anomaly detection results
*/
async detectVotingAnomalies(options: DetectVotingAnomaliesOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('detect_voting_anomalies', options, '{"anomalies": []}');
}
/**
* Compare political groups across dimensions
*
* @param options - Options including required groups and optional metrics and date
* @returns Cross-group comparative analysis
*/
async comparePoliticalGroups(options: ComparePoliticalGroupsOptions): Promise<MCPToolResult> {
const rawGroups = options && Array.isArray(options.groups) ? options.groups : [];
const groups = rawGroups
.map((g) => (typeof g === 'string' ? g.trim() : ''))
.filter((g) => g.length > 0);
if (groups.length === 0) {
console.warn(
'compare_political_groups called without valid groups (non-empty string array required)'
);
return { content: [{ type: 'text', text: '{"comparison": {}}' }] };
}
return this.safeCallTool(
'compare_political_groups',
{ ...options, groups },
'{"comparison": {}}'
);
}
/**
* Get detailed information about a specific MEP
*
* @param id - MEP identifier (must be non-empty)
* @returns Detailed MEP information including biography, contact, and activities
*/
async getMEPDetails(id: string): Promise<MCPToolResult> {
if (typeof id !== 'string' || id.trim().length === 0) {
console.warn('get_mep_details called without valid id (non-empty string required)');
return { content: [{ type: 'text', text: '{"mep": null}' }] };
}
return this.safeCallTool('get_mep_details', { id: id.trim() }, '{"mep": null}');
}
/**
* Retrieve voting records with optional filters
*
* @param options - Filter options (mepId, sessionId, limit)
* @returns Voting records data
*/
async getVotingRecords(options: VotingRecordsOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('get_voting_records', options, '{"votes": []}');
}
/**
* Analyze voting behavior patterns for an MEP
*
* @param options - Analysis options (mepId required non-empty, dateFrom, compareWithGroup)
* @returns Voting pattern analysis
*/
async analyzeVotingPatterns(options: VotingPatternsOptions): Promise<MCPToolResult> {
if (typeof options.mepId !== 'string' || options.mepId.trim().length === 0) {
console.warn(
'analyze_voting_patterns called without valid mepId (non-empty string required)'
);
return { content: [{ type: 'text', text: '{"patterns": null}' }] };
}
return this.safeCallTool(
'analyze_voting_patterns',
{ ...options, mepId: options.mepId.trim() },
'{"patterns": null}'
);
}
/**
* Track a legislative procedure by its identifier
*
* @param procedureId - Legislative procedure identifier (must be non-empty)
* @returns Procedure status and timeline
*/
async trackLegislation(procedureId: string): Promise<MCPToolResult> {
if (typeof procedureId !== 'string' || procedureId.trim().length === 0) {
console.warn(
'track_legislation called without valid procedureId (non-empty string required)'
);
return { content: [{ type: 'text', text: '{"procedure": null}' }] };
}
return this.safeCallTool(
'track_legislation',
{ procedureId: procedureId.trim() },
'{"procedure": null}'
);
}
/**
* Generate an analytical report
*
* @param options - Report options (reportType required non-empty, subjectId, dateFrom)
* @returns Generated report data
*/
async generateReport(options: GenerateReportOptions): Promise<MCPToolResult> {
if (typeof options.reportType !== 'string' || options.reportType.trim().length === 0) {
console.warn('generate_report called without valid reportType (non-empty string required)');
return { content: [{ type: 'text', text: '{"report": null}' }] };
}
return this.safeCallTool(
'generate_report',
{ ...options, reportType: options.reportType.trim() },
'{"report": null}'
);
}
/**
* Analyze committee activity, workload, and engagement
*
* @param options - Options including optional committeeId and date range
* @returns Committee activity analysis data
*/
async analyzeCommitteeActivity(
options: AnalyzeCommitteeActivityOptions = {}
): Promise<MCPToolResult> {
return this.safeCallTool('analyze_committee_activity', options, '{"activity": null}');
}
/**
* Track MEP attendance patterns and trends
*
* @param options - Options including optional mepId and date range
* @returns MEP attendance data
*/
async trackMEPAttendance(options: TrackMEPAttendanceOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('track_mep_attendance', options, '{"attendance": null}');
}
/**
* Analyze country delegation voting behavior and composition
*
* @param options - Options including required country code and optional date range
* @returns Country delegation analysis data
*/
async analyzeCountryDelegation(options: AnalyzeCountryDelegationOptions): Promise<MCPToolResult> {
if (typeof options.country !== 'string' || options.country.trim().length === 0) {
console.warn(
'analyze_country_delegation called without valid country (non-empty string required)'
);
return { content: [{ type: 'text', text: '{"delegation": null}' }] };
}
return this.safeCallTool(
'analyze_country_delegation',
{ ...options, country: options.country.trim() },
'{"delegation": null}'
);
}
/**
* Generate a parliament-wide political landscape overview
*
* @param options - Options including optional date range and detail level
* @returns Political landscape overview data
*/
async generatePoliticalLandscape(
options: GeneratePoliticalLandscapeOptions = {}
): Promise<MCPToolResult> {
return this.safeCallTool('generate_political_landscape', options, '{"landscape": null}');
}
/**
* Get currently active Members of European Parliament
*
* @param options - Pagination options
* @returns Active MEPs data
*/
async getCurrentMEPs(options: GetCurrentMEPsOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('get_current_meps', options, MEPS_FALLBACK);
}
/**
* Get plenary speeches and debate contributions
*
* @param options - Filter options including optional speechId or date range
* @returns Speeches data
*/
async getSpeeches(options: GetSpeechesOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('get_speeches', options, '{"speeches": []}');
}
/**
* Get legislative procedures
*
* @param options - Filter options including optional processId or year
* @returns Procedures data
*/
async getProcedures(options: GetProceduresOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('get_procedures', options, '{"procedures": []}');
}
/**
* Get adopted texts (legislative resolutions, positions, non-legislative resolutions)
*
* @param options - Filter options including optional docId or year
* @returns Adopted texts data
*/
async getAdoptedTexts(options: GetAdoptedTextsOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('get_adopted_texts', options, '{"texts": []}');
}
/**
* Get European Parliament events (hearings, conferences, seminars)
*
* @param options - Filter options including optional eventId or date range
* @returns Events data
*/
async getEvents(options: GetEventsOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('get_events', options, EVENTS_FALLBACK);
}
/**
* Get activities linked to a specific plenary sitting
*
* @param options - Options including required sittingId
* @returns Meeting activities data
*/
async getMeetingActivities(options: GetMeetingActivitiesOptions): Promise<MCPToolResult> {
if (typeof options.sittingId !== 'string' || options.sittingId.trim().length === 0) {
console.warn(
'get_meeting_activities called without valid sittingId (non-empty string required)'
);
return { content: [{ type: 'text', text: ACTIVITIES_FALLBACK }] };
}
return this.safeCallTool(
'get_meeting_activities',
{ ...options, sittingId: options.sittingId.trim() },
ACTIVITIES_FALLBACK
);
}
/**
* Get decisions made in a specific plenary sitting
*
* @param options - Options including required sittingId
* @returns Meeting decisions data
*/
async getMeetingDecisions(options: GetMeetingDecisionsOptions): Promise<MCPToolResult> {
if (typeof options.sittingId !== 'string' || options.sittingId.trim().length === 0) {
console.warn(
'get_meeting_decisions called without valid sittingId (non-empty string required)'
);
return { content: [{ type: 'text', text: '{"decisions": []}' }] };
}
return this.safeCallTool(
'get_meeting_decisions',
{ ...options, sittingId: options.sittingId.trim() },
'{"decisions": []}'
);
}
/**
* Get MEP declarations of financial interests
*
* @param options - Filter options including optional docId or year
* @returns MEP declarations data
*/
async getMEPDeclarations(options: GetMEPDeclarationsOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('get_mep_declarations', options, '{"declarations": []}');
}
/**
* Get incoming Members of European Parliament
*
* @param options - Pagination options
* @returns Incoming MEPs data
*/
async getIncomingMEPs(options: GetIncomingMEPsOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('get_incoming_meps', options, MEPS_FALLBACK);
}
/**
* Get outgoing Members of European Parliament
*
* @param options - Pagination options
* @returns Outgoing MEPs data
*/
async getOutgoingMEPs(options: GetOutgoingMEPsOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('get_outgoing_meps', options, MEPS_FALLBACK);
}
/**
* Get homonym MEPs (MEPs with identical names)
*
* @param options - Pagination options
* @returns Homonym MEPs data
*/
async getHomonymMEPs(options: GetHomonymMEPsOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('get_homonym_meps', options, MEPS_FALLBACK);
}
/**
* Get plenary documents
*
* @param options - Filter options including optional docId or year
* @returns Plenary documents data
*/
async getPlenaryDocuments(options: GetPlenaryDocumentsOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('get_plenary_documents', options, DOCUMENTS_FALLBACK);
}
/**
* Get committee documents
*
* @param options - Filter options including optional docId or year
* @returns Committee documents data
*/
async getCommitteeDocuments(options: GetCommitteeDocumentsOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('get_committee_documents', options, DOCUMENTS_FALLBACK);
}
/**
* Get plenary session documents (agendas, minutes, voting lists)
*
* @param options - Filter options including optional docId
* @returns Plenary session documents data
*/
async getPlenarySessionDocuments(
options: GetPlenarySessionDocumentsOptions = {}
): Promise<MCPToolResult> {
return this.safeCallTool('get_plenary_session_documents', options, DOCUMENTS_FALLBACK);
}
/**
* Get plenary session document items
*
* @param options - Pagination options
* @returns Plenary session document items data
*/
async getPlenarySessionDocumentItems(
options: GetPlenarySessionDocumentItemsOptions = {}
): Promise<MCPToolResult> {
return this.safeCallTool('get_plenary_session_document_items', options, ITEMS_FALLBACK);
}
/**
* Get controlled vocabularies (standardized classification terms)
*
* @param options - Filter options including optional vocId
* @returns Controlled vocabularies data
*/
async getControlledVocabularies(
options: GetControlledVocabulariesOptions = {}
): Promise<MCPToolResult> {
return this.safeCallTool('get_controlled_vocabularies', options, '{"vocabularies": []}');
}
/**
* Get external documents (non-EP documents such as Council positions)
*
* @param options - Filter options including optional docId or year
* @returns External documents data
*/
async getExternalDocuments(options: GetExternalDocumentsOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('get_external_documents', options, DOCUMENTS_FALLBACK);
}
/**
* Get foreseen (planned) activities for a specific plenary sitting
*
* @param options - Options including required sittingId
* @returns Foreseen activities data
*/
async getMeetingForeseenActivities(
options: GetMeetingForeseenActivitiesOptions
): Promise<MCPToolResult> {
if (typeof options.sittingId !== 'string' || options.sittingId.trim().length === 0) {
console.warn(
'get_meeting_foreseen_activities called without valid sittingId (non-empty string required)'
);
return { content: [{ type: 'text', text: ACTIVITIES_FALLBACK }] };
}
return this.safeCallTool(
'get_meeting_foreseen_activities',
{ ...options, sittingId: options.sittingId.trim() },
ACTIVITIES_FALLBACK
);
}
/**
* Get events linked to a specific legislative procedure
*
* @param options - Options including required processId
* @returns Procedure events data
*/
async getProcedureEvents(options: GetProcedureEventsOptions): Promise<MCPToolResult> {
if (typeof options.processId !== 'string' || options.processId.trim().length === 0) {
console.warn(
'get_procedure_events called without valid processId (non-empty string required)'
);
return { content: [{ type: 'text', text: EVENTS_FALLBACK }] };
}
return this.safeCallTool(
'get_procedure_events',
{ ...options, processId: options.processId.trim() },
EVENTS_FALLBACK
);
}
/**
* Get plenary session documents linked to a specific meeting
*
* @param options - Options including required sittingId
* @returns Meeting plenary session documents data
*/
async getMeetingPlenarySessionDocuments(
options: GetMeetingPlenarySessionDocumentsOptions
): Promise<MCPToolResult> {
if (typeof options.sittingId !== 'string' || options.sittingId.trim().length === 0) {
console.warn(
'get_meeting_plenary_session_documents called without valid sittingId (non-empty string required)'
);
return { content: [{ type: 'text', text: DOCUMENTS_FALLBACK }] };
}
return this.safeCallTool(
'get_meeting_plenary_session_documents',
{ ...options, sittingId: options.sittingId.trim() },
DOCUMENTS_FALLBACK
);
}
/**
* Get plenary session document items linked to a specific meeting
*
* @param options - Options including required sittingId
* @returns Meeting plenary session document items data
*/
async getMeetingPlenarySessionDocumentItems(
options: GetMeetingPlenarySessionDocumentItemsOptions
): Promise<MCPToolResult> {
if (typeof options.sittingId !== 'string' || options.sittingId.trim().length === 0) {
console.warn(
'get_meeting_plenary_session_document_items called without valid sittingId (non-empty string required)'
);
return { content: [{ type: 'text', text: ITEMS_FALLBACK }] };
}
return this.safeCallTool(
'get_meeting_plenary_session_document_items',
{ ...options, sittingId: options.sittingId.trim() },
ITEMS_FALLBACK
);
}
/**
* MEP relationship network mapping using committee co-membership
*
* @param options - Options including optional mepId, analysisType, and depth
* @returns Network analysis with centrality scores and clusters
*/
async networkAnalysis(options: NetworkAnalysisOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('network_analysis', options, INTELLIGENCE_FALLBACK);
}
/**
* Track political group institutional positioning and sentiment
*
* @param options - Options including optional groupId and timeframe
* @returns Sentiment tracking data
*/
async sentimentTracker(options: SentimentTrackerOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('sentiment_tracker', options, INTELLIGENCE_FALLBACK);
}
/**
* Detect emerging political shifts and coalition fracture signals
*
* @param options - Options including optional sensitivity and focusArea
* @returns Early warning alerts and trend indicators
*/
async earlyWarningSystem(options: EarlyWarningSystemOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('early_warning_system', options, INTELLIGENCE_FALLBACK);
}
/**
* Cross-reference MEP activities for comparative multi-dimensional profiling
*
* @param options - Options including required mepIds array and optional dimensions
* @returns Comparative intelligence profiles
*/
async comparativeIntelligence(options: ComparativeIntelligenceOptions): Promise<MCPToolResult> {
if (!Array.isArray(options.mepIds) || options.mepIds.length < 2) {
console.warn(
'comparative_intelligence called without valid mepIds (array of at least 2 required)'
);
return { content: [{ type: 'text', text: INTELLIGENCE_FALLBACK }] };
}
return this.safeCallTool('comparative_intelligence', options, INTELLIGENCE_FALLBACK);
}
/**
* Cross-tool OSINT intelligence correlation engine
*
* @param options - Options including optional mepId and correlation scenarios
* @returns Correlated intelligence alerts and insights
*/
async correlateIntelligence(options: CorrelateIntelligenceOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('correlate_intelligence', options, INTELLIGENCE_FALLBACK);
}
/**
* Retrieve precomputed European Parliament activity statistics (EP6–EP10, 2004–2025).
* Includes yearly stats, category rankings, political landscape history, and
* average-based predictions for 2026–2030. Static data refreshed weekly — no live API calls.
*
* @param options - Filter options including optional year range, category, and flags
* @returns Precomputed EP statistics data
*/
async getAllGeneratedStats(options: GetAllGeneratedStatsOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('get_all_generated_stats', options, STATS_FALLBACK);
}
// ─── EP API v2 Feed Endpoint Methods ────────────────────────────────────────
/** Fallback payload for feed tools */
private static readonly FEED_FALLBACK = '{"feed": []}';
/**
* Get MEPs feed (most recent updates via EP API v2)
*
* @param options - Pagination options
* @returns MEPs feed data
*/
async getMEPsFeed(options: GetMEPsFeedOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('get_meps_feed', options, EuropeanParliamentMCPClient.FEED_FALLBACK);
}
/**
* Get events feed (most recent updates via EP API v2)
*
* @param options - Pagination options
* @returns Events feed data
*/
async getEventsFeed(options: GetEventsFeedOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool('get_events_feed', options, EuropeanParliamentMCPClient.FEED_FALLBACK);
}
/**
* Get procedures feed (most recent updates via EP API v2)
*
* @param options - Pagination options
* @returns Procedures feed data
*/
async getProceduresFeed(options: GetProceduresFeedOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool(
'get_procedures_feed',
options,
EuropeanParliamentMCPClient.FEED_FALLBACK
);
}
/**
* Get adopted texts feed (most recent updates via EP API v2)
*
* @param options - Pagination options
* @returns Adopted texts feed data
*/
async getAdoptedTextsFeed(options: GetAdoptedTextsFeedOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool(
'get_adopted_texts_feed',
options,
EuropeanParliamentMCPClient.FEED_FALLBACK
);
}
/**
* Get MEP declarations feed (most recent updates via EP API v2)
*
* @param options - Pagination options
* @returns MEP declarations feed data
*/
async getMEPDeclarationsFeed(
options: GetMEPDeclarationsFeedOptions = {}
): Promise<MCPToolResult> {
return this.safeCallTool(
'get_mep_declarations_feed',
options,
EuropeanParliamentMCPClient.FEED_FALLBACK
);
}
/**
* Get documents feed (most recent updates via EP API v2)
*
* @param options - Pagination options
* @returns Documents feed data
*/
async getDocumentsFeed(options: GetDocumentsFeedOptions = {}): Promise<MCPToolResult> {
return this.safeCallTool(
'get_documents_feed',
options,
EuropeanParliamentMCPClient.FEED_FALLBACK
);
}
/**
* Get plenary documents feed (most recent updates via EP API v2)
*
* @param options - Pagination options
* @returns Plenary documents feed data
*/
async getPlenaryDocumentsFeed(
options: GetPlenaryDocumentsFeedOptions = {}
): Promise<MCPToolResult> {
return this.safeCallTool(
'get_plenary_documents_feed',
options,
EuropeanParliamentMCPClient.FEED_FALLBACK
);
}
/**
* Get committee documents feed (most recent updates via EP API v2)
*
* @param options - Pagination options
* @returns Committee documents feed data
*/
async getCommitteeDocumentsFeed(
options: GetCommitteeDocumentsFeedOptions = {}
): Promise<MCPToolResult> {
return this.safeCallTool(
'get_committee_documents_feed',
options,
EuropeanParliamentMCPClient.FEED_FALLBACK
);
}
/**
* Get plenary session documents feed (most recent updates via EP API v2)
*
* @param options - Pagination options
* @returns Plenary session documents feed data
*/
async getPlenarySessionDocumentsFeed(
options: GetPlenarySessionDocumentsFeedOptions = {}
): Promise<MCPToolResult> {
return this.safeCallTool(
'get_plenary_session_documents_feed',
options,
EuropeanParliamentMCPClient.FEED_FALLBACK
);
}
/**
* Get external documents feed (most recent updates via EP API v2)
*
* @param options - Pagination options
* @returns External documents feed data
*/
async getExternalDocumentsFeed(
options: GetExternalDocumentsFeedOptions = {}
): Promise<MCPToolResult> {
return this.safeCallTool(
'get_external_documents_feed',
options,
EuropeanParliamentMCPClient.FEED_FALLBACK
);
}
/**
* Get parliamentary questions feed (most recent updates via EP API v2)
*
* @param options - Pagination options
* @returns Parliamentary questions feed data
*/
async getParliamentaryQuestionsFeed(
options: GetParliamentaryQuestionsFeedOptions = {}
): Promise<MCPToolResult> {
return this.safeCallTool(
'get_parliamentary_questions_feed',
options,
EuropeanParliamentMCPClient.FEED_FALLBACK
);
}
/**
* Get corporate bodies feed (most recent updates via EP API v2)
*
* @param options - Pagination options
* @returns Corporate bodies feed data
*/
async getCorporateBodiesFeed(
options: GetCorporateBodiesFeedOptions = {}
): Promise<MCPToolResult> {
return this.safeCallTool(
'get_corporate_bodies_feed',
options,
EuropeanParliamentMCPClient.FEED_FALLBACK
);
}
/**
* Get controlled vocabularies feed (most recent updates via EP API v2)
*
* @param options - Pagination options
* @returns Controlled vocabularies feed data
*/
async getControlledVocabulariesFeed(
options: GetControlledVocabulariesFeedOptions = {}
): Promise<MCPToolResult> {
return this.safeCallTool(
'get_controlled_vocabularies_feed',
options,
EuropeanParliamentMCPClient.FEED_FALLBACK
);
}
}
let clientInstance: EuropeanParliamentMCPClient | null = null;
/**
* Get or create singleton MCP client instance
*
* @param options - Client options
* @returns Connected MCP client
*/
export async function getEPMCPClient(
options: MCPClientOptions = {}
): Promise<EuropeanParliamentMCPClient> {
if (!clientInstance) {
clientInstance = new EuropeanParliamentMCPClient(options);
await clientInstance.connect();
}
return clientInstance;
}
/**
* Close and cleanup singleton MCP client
*/
export async function closeEPMCPClient(): Promise<void> {
if (clientInstance) {
clientInstance.disconnect();
clientInstance = null;
}
}
|