Skip to main content
Glama
r-huijts

OpenTK Model Context Protocol Server

by r-huijts

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

TableJSON Schema
NameRequiredDescriptionDefault
formatNoFormat of the results: 'full' for complete data or 'summary' for a more structured version with renamed fields (default: 'full'). Both formats include party information.
limitNoMaximum number of voting results to return (default: 20, max: 100)

Implementation Reference

  • 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)
            }]
          };
        }
      }
    );
  • 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.")
    },
  • 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;
    }
  • 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;
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses that the response is a structured JSON object sorted by date and includes detailed information like vote counts and party alignments, but it lacks details on permissions, rate limits, or error handling. For a read operation with no annotations, this is adequate but not comprehensive.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with purpose and usage, but it includes verbose sentences like 'This tool is particularly valuable for tracking political alignments...' that add minimal operational value. It could be more concise by focusing on essential details without the explanatory fluff.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, 100% schema coverage, and no output schema, the description adequately covers purpose, usage, and basic behavioral traits. However, it lacks details on response structure (e.g., JSON fields) and error cases, which would improve completeness for a tool with no output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters (format and limit) thoroughly. The description adds minor context by explaining that 'summary' format provides a more structured representation with renamed fields, but this largely repeats schema information. Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'retrieves' and the resource 'recent voting results on parliamentary motions and bills,' distinguishing it from siblings like get_committee_details or list_persons by focusing on voting outcomes rather than committees, documents, or persons.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It explicitly states when to 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.' This provides clear context and distinguishes it from alternatives like search_tk or get_overview.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/r-huijts/opentk-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server