get_voting_results
Retrieve structured JSON data on recent parliamentary voting results, including motion details, vote counts, and party positions. Use the 'limit' parameter to control results and 'format' to choose between full or summary views for analyzing political alignments and coalition dynamics.
Instructions
Retrieves recent voting results on parliamentary motions and bills. The response contains a structured JSON object with voting results sorted by date (newest first). Each result includes detailed information such as the title of the motion/bill, the date of the vote, the submitter, whether it was accepted or rejected, the vote counts (for/against), and which political parties voted for or against. Use this tool when a user asks about recent parliamentary votes, wants to know how parties voted on specific issues, or needs to analyze voting patterns. You can control the number of results with the 'limit' parameter and choose between 'full' or 'summary' format. The 'summary' format provides a more structured representation with renamed fields, while both formats include complete party voting information. This tool is particularly valuable for tracking political alignments, understanding coalition dynamics, and analyzing how different parties position themselves on important issues.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | No | Format of the results: 'full' for complete data or 'summary' for a more structured version with renamed fields (default: 'full'). Both formats include party information. | |
| limit | No | Maximum number of voting results to return (default: 20, max: 100) |
Implementation Reference
- src/index.ts:597-669 (handler)The handler function for the get_voting_results tool. Fetches HTML from /stemmingen.html using apiService, extracts voting results using extractVotingResultsFromHtml, sorts by date (newest first), limits results, optionally formats to summary, and returns structured JSON response.async ({ limit = 20, format = "full" }) => { try { // Validate and cap the limit const validatedLimit = Math.min(Math.max(1, limit), 100); const html = await apiService.fetchHtml("/stemmingen.html"); const votingResults = extractVotingResultsFromHtml(html, BASE_URL); if (votingResults.length === 0) { return { content: [{ type: "text", text: JSON.stringify({ error: "No voting results found or there was an error retrieving the voting results list. Please try again later.", url: `${BASE_URL}/stemmingen.html` }, null, 2) }] }; } // Sort voting results by date (most recent first) and limit the results const sortedResults = [...votingResults].sort((a, b) => { const dateA = new Date(a.date); const dateB = new Date(b.date); return dateB.getTime() - dateA.getTime(); // Descending order (newest first) }).slice(0, validatedLimit); // Format the results based on the requested format let formattedResults; if (format === "summary") { // Create a summary version with only essential fields formattedResults = sortedResults.map(item => ({ id: item.id, title: item.title, date: item.date, result: item.result, submitter: item.submitter, votes: item.votes ? { voorAantal: item.votes.voorAantal, tegenAantal: item.votes.tegenAantal, voorPartijen: item.votes.voor, tegenPartijen: item.votes.tegen } : undefined, url: item.url })); } else { // Use the full data formattedResults = sortedResults; } return { content: [{ type: "text", text: JSON.stringify({ total: votingResults.length, limit: validatedLimit, format, results: formattedResults }, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: JSON.stringify({ error: `Error fetching voting results: ${error.message || 'Unknown error'}`, url: `${BASE_URL}/stemmingen.html` }, null, 2) }] }; } }
- src/index.ts:590-670 (registration)Registers the get_voting_results tool with the MCP server using mcp.tool(), providing the tool name, detailed description, input schema with zod validation, and references the handler function.mcp.tool( "get_voting_results", "Retrieves recent voting results on parliamentary motions and bills. The response contains a structured JSON object with voting results sorted by date (newest first). Each result includes detailed information such as the title of the motion/bill, the date of the vote, the submitter, whether it was accepted or rejected, the vote counts (for/against), and which political parties voted for or against. The 'limit' parameter controls the number of results (default: 20, max: 100) and 'format' parameter allows choosing between 'full' or 'summary' format. The 'summary' format provides a more structured representation with renamed fields, while both formats include complete party voting information.", { limit: z.number().optional().describe("Maximum number of voting results to return (default: 20, max: 100)"), format: z.enum(["full", "summary"]).optional().describe("Format of the results: 'full' for complete data or 'summary' for a more structured version with renamed fields (default: 'full'). Both formats include party information.") }, async ({ limit = 20, format = "full" }) => { try { // Validate and cap the limit const validatedLimit = Math.min(Math.max(1, limit), 100); const html = await apiService.fetchHtml("/stemmingen.html"); const votingResults = extractVotingResultsFromHtml(html, BASE_URL); if (votingResults.length === 0) { return { content: [{ type: "text", text: JSON.stringify({ error: "No voting results found or there was an error retrieving the voting results list. Please try again later.", url: `${BASE_URL}/stemmingen.html` }, null, 2) }] }; } // Sort voting results by date (most recent first) and limit the results const sortedResults = [...votingResults].sort((a, b) => { const dateA = new Date(a.date); const dateB = new Date(b.date); return dateB.getTime() - dateA.getTime(); // Descending order (newest first) }).slice(0, validatedLimit); // Format the results based on the requested format let formattedResults; if (format === "summary") { // Create a summary version with only essential fields formattedResults = sortedResults.map(item => ({ id: item.id, title: item.title, date: item.date, result: item.result, submitter: item.submitter, votes: item.votes ? { voorAantal: item.votes.voorAantal, tegenAantal: item.votes.tegenAantal, voorPartijen: item.votes.voor, tegenPartijen: item.votes.tegen } : undefined, url: item.url })); } else { // Use the full data formattedResults = sortedResults; } return { content: [{ type: "text", text: JSON.stringify({ total: votingResults.length, limit: validatedLimit, format, results: formattedResults }, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: JSON.stringify({ error: `Error fetching voting results: ${error.message || 'Unknown error'}`, url: `${BASE_URL}/stemmingen.html` }, null, 2) }] }; } } );
- src/index.ts:593-596 (schema)Zod input schema for the get_voting_results tool, defining optional parameters 'limit' (number) and 'format' (enum: 'full' or 'summary') with descriptions.{ limit: z.number().optional().describe("Maximum number of voting results to return (default: 20, max: 100)"), format: z.enum(["full", "summary"]).optional().describe("Format of the results: 'full' for complete data or 'summary' for a more structured version with renamed fields (default: 'full'). Both formats include party information.") },
- src/utils/html-parser.ts:53-66 (schema)TypeScript interface defining the structure of a VotingResult object, used as output type for voting data including id, title, date, result, submitter, vote counts and parties, and URL.interface VotingResult { id: string; title: string; date: string; result: 'Aangenomen' | 'Verworpen' | 'Ingetrokken' | 'Aangehouden' | string; submitter?: string; votes?: { voor: string[]; tegen: string[]; voorAantal: number; tegenAantal: number; }; url: string; }
- src/utils/html-parser.ts:505-637 (helper)Helper function that parses the stemmingen.html page, extracts all voting results from table tbody sections, populates VotingResult objects with details like title, date, result, submitter, vote counts, parties for/against, and URLs.export function extractVotingResultsFromHtml(html: string, baseUrl: string): VotingResult[] { if (!html) { return []; } const votingResults: VotingResult[] = []; // Extract all tbody sections (each contains a voting result and its details) const tbodyRegex = /<tbody>([\s\S]*?)<\/tbody>/gi; let tbodyMatch: RegExpExecArray | null; while ((tbodyMatch = tbodyRegex.exec(html)) !== null) { if (!tbodyMatch[1]) continue; const tbodyContent = tbodyMatch[1]; // Extract rows within this tbody const rows: string[] = []; const rowRegex = /<tr[^>]*>([\s\S]*?)<\/tr>/gi; let rowMatch: RegExpExecArray | null; while ((rowMatch = rowRegex.exec(tbodyContent)) !== null) { if (rowMatch[1]) { rows.push(rowMatch[1]); } } // Need at least the main row and the parties row if (rows.length < 2) continue; // Process the main row (first row) const mainRowContent = rows[0]; // Extract cells from the main row const cellRegex = /<td[^>]*>([\s\S]*?)<\/td>/gi; const cells: string[] = []; let cellMatch: RegExpExecArray | null; while ((cellMatch = cellRegex.exec(mainRowContent as string)) !== null) { if (cellMatch[1]) { cells.push(cellMatch[1].trim()); } } // Need at least date, title, submitter, result, and vote counts if (cells.length < 5) continue; // Extract date const dateCell = cells[0] || ""; const date = dateCell.replace(/<[^>]+>/g, "").trim(); // Extract title and link const titleCell = cells[1] || ""; const titleMatch = titleCell.match(/<a href="(zaak\.html\?nummer=([^"]+))">([^<]+)<\/a>/); if (!titleMatch || !titleMatch[1] || !titleMatch[2] || !titleMatch[3]) continue; const id = titleMatch[2]; const url = new URL(titleMatch[1], baseUrl).href; const title = titleMatch[3].trim(); // Extract submitter const submitter = cells[2] ? cells[2].replace(/<[^>]+>/g, "").trim() : null; // Extract result const resultCell = cells[3] || ""; const result = resultCell.replace(/<[^>]+>/g, "").trim(); // Extract vote counts const forVotes = cells[4] ? parseInt(cells[4].replace(/<[^>]+>/g, "").trim(), 10) : 0; const againstVotes = cells[5] ? parseInt(cells[5].replace(/<[^>]+>/g, "").trim(), 10) : 0; // Process the parties row (second row) const partiesRowContent = rows[1]; // Extract cells from the parties row const partiesCells: string[] = []; let partiesCellMatch: RegExpExecArray | null; const partiesCellRegex = /<td[^>]*>([\s\S]*?)<\/td>/gi; while ((partiesCellMatch = partiesCellRegex.exec(partiesRowContent as string)) !== null) { if (partiesCellMatch[1]) { partiesCells.push(partiesCellMatch[1].trim()); } } // Extract parties that voted for and against let forParties: string[] = []; let againstParties: string[] = []; // Find the cell with "Voor" parties const forPartiesCell = partiesCells.find(cell => cell.includes("<b>Voor</b>:")) || ""; if (forPartiesCell) { // Extract the text after "<b>Voor</b>:" const forPartiesMatch = forPartiesCell.match(/<b>Voor<\/b>:\s*(.*?)(?:<\/td>|$)/i); if (forPartiesMatch && forPartiesMatch[1]) { const forPartiesText = forPartiesMatch[1].trim(); // Split by "|" and trim each party name forParties = forPartiesText.split("|").map(p => p.trim()).filter(p => p); } } // Find the cell with "Tegen" parties const againstPartiesCell = partiesCells.find(cell => cell.includes("<b>Tegen</b>:")) || ""; if (againstPartiesCell) { // Extract the text after "<b>Tegen</b>:" const againstPartiesMatch = againstPartiesCell.match(/<b>Tegen<\/b>:\s*(.*?)(?:<\/td>|$)/i); if (againstPartiesMatch && againstPartiesMatch[1]) { const againstPartiesText = againstPartiesMatch[1].trim(); // Split by "|" and trim each party name againstParties = againstPartiesText.split("|").map(p => p.trim()).filter(p => p); } } // Create the voting result object with all details votingResults.push({ id, title, date, result, submitter: submitter || undefined, votes: { voor: forParties, tegen: againstParties, voorAantal: forVotes, tegenAantal: againstVotes }, url }); } return votingResults; }