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 | 5x 84x 5x 5x 5x 22x 22x 22x 22x 5x 1x 1x 4x 1x 1x 3x 3x 3x 17x 17x 8x 8x 8x 8x 8x 9x 9x 5x 15x 15x 15x 5x 5x 5x 5x 5x 5x 5x 5x 10x 5x 11x 11x 11x 11x 11x 8x 11x 11x 6x 7x 5x 2x 3x 3x 3x 3x 4x 11x 5x 2x 5x 5x 5x 2x 5x 2x 5x 2x 5x 6x 5x 2x 5x 2x 5x 3x 5x 2x 5x 2x 5x 6x 2x 2x 4x 1x 1x 3x 5x 2x | // SPDX-FileCopyrightText: 2024-2026 Hack23 AB
// SPDX-License-Identifier: Apache-2.0
/**
* @module MCP/ep/tools-feeds
* @description EP API v2 feed endpoint method mixins for
* {@link EuropeanParliamentMCPClient}. Augments the class prototype with
* all feed-related methods, plus getServerHealth and getProcedureEventById.
*/
import { EuropeanParliamentMCPClient } from './client.js';
import type {
MCPToolResult,
MCPContentItem,
GetMEPsFeedOptions,
GetEventsFeedOptions,
GetProceduresFeedOptions,
GetAdoptedTextsFeedOptions,
GetMEPDeclarationsFeedOptions,
GetDocumentsFeedOptions,
GetPlenaryDocumentsFeedOptions,
GetCommitteeDocumentsFeedOptions,
GetPlenarySessionDocumentsFeedOptions,
GetExternalDocumentsFeedOptions,
GetParliamentaryQuestionsFeedOptions,
GetCorporateBodiesFeedOptions,
GetControlledVocabulariesFeedOptions,
GetProcedureEventByIdOptions,
} from '../../types/index.js';
import { PROCEDURE_EVENT_FALLBACK, SERVER_HEALTH_FALLBACK } from './fallbacks.js';
import { _parseResultPayload } from './parse.js';
import { classifyToolError, isFeedUnavailable } from './error-classifier.js';
import { detectProceduresFeedStaleTail } from './staleness.js';
/** Fallback payload for feed tools */
const FEED_FALLBACK = '{"feed": []}';
// \u2500\u2500\u2500 Declaration merging \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
declare module './client.js' {
interface EuropeanParliamentMCPClient {
getMEPsFeed(options?: GetMEPsFeedOptions): Promise<MCPToolResult>;
getEventsFeed(options?: GetEventsFeedOptions): Promise<MCPToolResult>;
getProceduresFeed(options?: GetProceduresFeedOptions): Promise<MCPToolResult>;
getAdoptedTextsFeed(options?: GetAdoptedTextsFeedOptions): Promise<MCPToolResult>;
getMEPDeclarationsFeed(options?: GetMEPDeclarationsFeedOptions): Promise<MCPToolResult>;
getDocumentsFeed(options?: GetDocumentsFeedOptions): Promise<MCPToolResult>;
getPlenaryDocumentsFeed(options?: GetPlenaryDocumentsFeedOptions): Promise<MCPToolResult>;
getCommitteeDocumentsFeed(options?: GetCommitteeDocumentsFeedOptions): Promise<MCPToolResult>;
getPlenarySessionDocumentsFeed(
options?: GetPlenarySessionDocumentsFeedOptions
): Promise<MCPToolResult>;
getExternalDocumentsFeed(options?: GetExternalDocumentsFeedOptions): Promise<MCPToolResult>;
getCommissionWorkProgramme(
options?: Omit<GetExternalDocumentsFeedOptions, 'workType'>
): Promise<MCPToolResult>;
getCouncilPresidencyProgramme(
options?: Omit<GetExternalDocumentsFeedOptions, 'workType'>
): Promise<MCPToolResult>;
getParliamentaryQuestionsFeed(
options?: GetParliamentaryQuestionsFeedOptions
): Promise<MCPToolResult>;
getCorporateBodiesFeed(options?: GetCorporateBodiesFeedOptions): Promise<MCPToolResult>;
getControlledVocabulariesFeed(
options?: GetControlledVocabulariesFeedOptions
): Promise<MCPToolResult>;
getProcedureEventById(options: GetProcedureEventByIdOptions): Promise<MCPToolResult>;
getServerHealth(): Promise<MCPToolResult>;
}
}
// \u2500\u2500\u2500 Type helper for accessing protected internals from prototype methods \u2500\u2500\u2500\u2500
type ClientInternal = {
safeCallTool(
name: string,
args: object | (() => object),
fallback: string
): Promise<MCPToolResult>;
safeCallToolWithReliabilityTimeout(
name: string,
args: object | (() => object),
fallback: string
): Promise<MCPToolResult>;
callToolWithRetry(name: string, args: object, maxRetries?: number): Promise<MCPToolResult>;
_calledTools: Set<string>;
_failedTools: Map<string, string>;
_slowFeedWarnings: Map<string, string>;
_recordToolFailure(name: string, error: string, fallback: string): MCPToolResult;
};
function _self(client: EuropeanParliamentMCPClient): ClientInternal {
return client as unknown as ClientInternal;
}
// \u2500\u2500\u2500 Prototype method implementations \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
EuropeanParliamentMCPClient.prototype.getMEPsFeed = async function (
this: EuropeanParliamentMCPClient,
options: GetMEPsFeedOptions = {}
): Promise<MCPToolResult> {
return _self(this).safeCallTool('get_meps_feed', options, FEED_FALLBACK);
};
EuropeanParliamentMCPClient.prototype.getEventsFeed = async function (
this: EuropeanParliamentMCPClient,
options: GetEventsFeedOptions = {}
): Promise<MCPToolResult> {
const internals = _self(this);
internals._calledTools.add('get_events_feed');
try {
const result = await internals.callToolWithRetry('get_events_feed', options);
if (result.isError === true) {
internals._slowFeedWarnings.delete('get_events_feed');
return internals._recordToolFailure(
'get_events_feed',
result.content?.[0]?.text ?? '',
FEED_FALLBACK
);
}
if (isFeedUnavailable(result)) {
internals._slowFeedWarnings.delete('get_events_feed');
return internals._recordToolFailure(
'get_events_feed',
`UPSTREAM_404: ${result.content?.[0]?.text?.slice(0, 200) ?? 'feed unavailable'}`,
FEED_FALLBACK
);
}
internals._failedTools.delete('get_events_feed');
internals._slowFeedWarnings.delete('get_events_feed');
return result;
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
if (classifyToolError(message) === 'TIMEOUT') {
const warningMsg = `SLOW_FEED: ${message.slice(0, 200)}`;
internals._failedTools.delete('get_events_feed');
internals._slowFeedWarnings.set('get_events_feed', warningMsg);
console.warn(
'\ud83d\udfe1 get_events_feed slow-feed warning [SLOW_FEED]:',
message.slice(0, 200)
);
return { content: [{ type: 'text', text: '{"feed":[],"slowFeedWarning":true}' }] };
}
internals._slowFeedWarnings.delete('get_events_feed');
return internals._recordToolFailure('get_events_feed', message, FEED_FALLBACK);
}
};
EuropeanParliamentMCPClient.prototype.getProceduresFeed = async function (
this: EuropeanParliamentMCPClient,
options: GetProceduresFeedOptions = {}
): Promise<MCPToolResult> {
const result = await _self(this).safeCallTool('get_procedures_feed', options, FEED_FALLBACK);
const payload = _parseResultPayload(result);
if (detectProceduresFeedStaleTail(payload)) {
console.warn(
'\ud83d\udfe1 procedures-feed: stale historical tail \u2014 newest procedure year is <2020; use get_adopted_texts({ year: $YEAR }) or track_legislation({ procedureId }) instead'
);
const existingWarnings = Array.isArray(payload?.['dataQualityWarnings'])
? (payload['dataQualityWarnings'] as string[])
: [];
const augmented: Record<string, unknown> = {
...(payload as Record<string, unknown>),
staleTail: true,
dataQualityWarnings: [
...existingWarnings,
'STALE_TAIL: procedures-feed returned stale historical tail (max year <2020) \u2014 likely upstream ordering degradation; fallback: get_adopted_texts({ year: $YEAR }) or track_legislation({ procedureId })',
],
};
const augmentedText = JSON.stringify(augmented);
const originalContent = result.content;
const updatedContent: MCPContentItem[] =
Array.isArray(originalContent) && originalContent.length > 0
? originalContent.map((item, index) =>
index === 0 ? { ...item, text: augmentedText } : item
)
: [{ type: 'text', text: augmentedText }];
return { ...result, content: updatedContent };
}
return result;
};
EuropeanParliamentMCPClient.prototype.getAdoptedTextsFeed = async function (
this: EuropeanParliamentMCPClient,
options: GetAdoptedTextsFeedOptions = {}
): Promise<MCPToolResult> {
const internals = _self(this);
const result = await internals.safeCallTool('get_adopted_texts_feed', options, FEED_FALLBACK);
const payload = _parseResultPayload(result);
const rawWarnings = payload?.['dataQualityWarnings'];
const warnings: string[] = Array.isArray(rawWarnings)
? rawWarnings.filter((w): w is string => typeof w === 'string')
: [];
const freshnessWarnings = warnings.filter((w) => w.startsWith('FRESHNESS_FALLBACK'));
if (freshnessWarnings.length === 0) {
return result;
}
const failedWarning = freshnessWarnings.find((w) => w.startsWith('FRESHNESS_FALLBACK_FAILED'));
if (failedWarning !== undefined) {
return internals._recordToolFailure(
'get_adopted_texts_feed',
`ANALYSIS_ONLY: ${failedWarning.slice(0, 200)}`,
FEED_FALLBACK
);
}
const augmented: Record<string, unknown> = {
...(payload as Record<string, unknown>),
freshness: 'augmented',
dataFreshnessWarnings: freshnessWarnings,
};
const augmentedText = JSON.stringify(augmented);
const originalContent = result.content;
const updatedContent: MCPContentItem[] =
Array.isArray(originalContent) && originalContent.length > 0
? originalContent.map((item, index) =>
index === 0 ? { ...item, text: augmentedText } : item
)
: [{ type: 'text', text: augmentedText }];
return { ...result, content: updatedContent };
};
EuropeanParliamentMCPClient.prototype.getMEPDeclarationsFeed = async function (
this: EuropeanParliamentMCPClient,
options: GetMEPDeclarationsFeedOptions = {}
): Promise<MCPToolResult> {
return _self(this).safeCallTool('get_mep_declarations_feed', options, FEED_FALLBACK);
};
EuropeanParliamentMCPClient.prototype.getDocumentsFeed = async function (
this: EuropeanParliamentMCPClient,
options: GetDocumentsFeedOptions = {}
): Promise<MCPToolResult> {
return _self(this).safeCallTool('get_documents_feed', options, FEED_FALLBACK);
};
EuropeanParliamentMCPClient.prototype.getPlenaryDocumentsFeed = async function (
this: EuropeanParliamentMCPClient,
options: GetPlenaryDocumentsFeedOptions = {}
): Promise<MCPToolResult> {
return _self(this).safeCallTool('get_plenary_documents_feed', options, FEED_FALLBACK);
};
EuropeanParliamentMCPClient.prototype.getCommitteeDocumentsFeed = async function (
this: EuropeanParliamentMCPClient,
options: GetCommitteeDocumentsFeedOptions = {}
): Promise<MCPToolResult> {
return _self(this).safeCallToolWithReliabilityTimeout(
'get_committee_documents_feed',
options,
FEED_FALLBACK
);
};
EuropeanParliamentMCPClient.prototype.getPlenarySessionDocumentsFeed = async function (
this: EuropeanParliamentMCPClient,
options: GetPlenarySessionDocumentsFeedOptions = {}
): Promise<MCPToolResult> {
return _self(this).safeCallTool('get_plenary_session_documents_feed', options, FEED_FALLBACK);
};
EuropeanParliamentMCPClient.prototype.getExternalDocumentsFeed = async function (
this: EuropeanParliamentMCPClient,
options: GetExternalDocumentsFeedOptions = {}
): Promise<MCPToolResult> {
return _self(this).safeCallToolWithReliabilityTimeout(
'get_external_documents_feed',
options,
FEED_FALLBACK
);
};
EuropeanParliamentMCPClient.prototype.getCommissionWorkProgramme = async function (
this: EuropeanParliamentMCPClient,
options: Omit<GetExternalDocumentsFeedOptions, 'workType'> = {}
): Promise<MCPToolResult> {
return this.getExternalDocumentsFeed({ ...options, workType: 'COM_WORK_PROGRAMME' });
};
EuropeanParliamentMCPClient.prototype.getCouncilPresidencyProgramme = async function (
this: EuropeanParliamentMCPClient,
options: Omit<GetExternalDocumentsFeedOptions, 'workType'> = {}
): Promise<MCPToolResult> {
return this.getExternalDocumentsFeed({ ...options, workType: 'COUNCIL_PRESIDENCY_PROGRAMME' });
};
EuropeanParliamentMCPClient.prototype.getParliamentaryQuestionsFeed = async function (
this: EuropeanParliamentMCPClient,
options: GetParliamentaryQuestionsFeedOptions = {}
): Promise<MCPToolResult> {
return _self(this).safeCallTool('get_parliamentary_questions_feed', options, FEED_FALLBACK);
};
EuropeanParliamentMCPClient.prototype.getCorporateBodiesFeed = async function (
this: EuropeanParliamentMCPClient,
options: GetCorporateBodiesFeedOptions = {}
): Promise<MCPToolResult> {
return _self(this).safeCallTool('get_corporate_bodies_feed', options, FEED_FALLBACK);
};
EuropeanParliamentMCPClient.prototype.getControlledVocabulariesFeed = async function (
this: EuropeanParliamentMCPClient,
options: GetControlledVocabulariesFeedOptions = {}
): Promise<MCPToolResult> {
return _self(this).safeCallTool('get_controlled_vocabularies_feed', options, FEED_FALLBACK);
};
EuropeanParliamentMCPClient.prototype.getProcedureEventById = async function (
this: EuropeanParliamentMCPClient,
options: GetProcedureEventByIdOptions
): Promise<MCPToolResult> {
if (typeof options.processId !== 'string' || options.processId.trim().length === 0) {
console.warn(
'get_procedure_event_by_id called without valid processId (non-empty string required)'
);
return { content: [{ type: 'text', text: PROCEDURE_EVENT_FALLBACK }] };
}
if (typeof options.eventId !== 'string' || options.eventId.trim().length === 0) {
console.warn(
'get_procedure_event_by_id called without valid eventId (non-empty string required)'
);
return { content: [{ type: 'text', text: PROCEDURE_EVENT_FALLBACK }] };
}
return _self(this).safeCallTool(
'get_procedure_event_by_id',
{ processId: options.processId.trim(), eventId: options.eventId.trim() },
PROCEDURE_EVENT_FALLBACK
);
};
EuropeanParliamentMCPClient.prototype.getServerHealth = async function (
this: EuropeanParliamentMCPClient
): Promise<MCPToolResult> {
return _self(this).safeCallTool('get_server_health', {}, SERVER_HEALTH_FALLBACK);
};
|