Skip to main content
Glama
r-huijts

OpenTK Model Context Protocol Server

by r-huijts

get_document_details

Retrieves structured metadata for Dutch parliamentary documents, including title, type, document number, dates, version, and links to PDF and official web pages, using a unique identifier.

Instructions

Retrieves metadata about a parliamentary document in a structured JSON format, without downloading the actual document content. Returns information including title, type, document number, dates, version number, and clickable links to both the PDF version and the official Tweede Kamer webpage. This tool is ideal for getting quick information about a document and obtaining the relevant links for further access. To actually download the document content, use the 'download_document' tool instead.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nummerYesDocument number (e.g., '2024D39058') - the unique identifier for the parliamentary document you want information about

Implementation Reference

  • src/index.ts:351-395 (registration)
    Registration of the 'get_document_details' MCP tool. Defines the tool name, description, input schema (document 'nummer'), and handler function that fetches HTML from the document page and extracts structured details using extractDocumentDetailsFromHtml.
    "get_document_details", "Retrieves metadata about a parliamentary document in a structured JSON format, without downloading the actual document content. Returns information including title, type, document number, dates, version number, and links to both the PDF version and the official Tweede Kamer webpage.", { nummer: z.string().describe("Document number (e.g., '2024D39058') - the unique identifier for the parliamentary document you want information about") }, async ({ nummer }) => { try { const html = await apiService.fetchHtml(`/document.html?nummer=${encodeURIComponent(nummer)}`); if (!html) { return { content: [{ type: "text", text: JSON.stringify({ error: `No content found for document ${nummer}` }) }] }; } const details = extractDocumentDetailsFromHtml(html, BASE_URL); if (!details) { return { content: [{ type: "text", text: JSON.stringify({ error: `Failed to parse details for document ${nummer}` }) }] }; } return { content: [{ type: "text", text: JSON.stringify(details, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: JSON.stringify({ error: `Error fetching document details: ${error.message || 'Unknown error'}` }) }] }; } } );
  • Handler function for get_document_details tool: fetches the document.html page using apiService, extracts details using the helper function, formats as JSON, and returns as MCP content or error response.
    async ({ nummer }) => { try { const html = await apiService.fetchHtml(`/document.html?nummer=${encodeURIComponent(nummer)}`); if (!html) { return { content: [{ type: "text", text: JSON.stringify({ error: `No content found for document ${nummer}` }) }] }; } const details = extractDocumentDetailsFromHtml(html, BASE_URL); if (!details) { return { content: [{ type: "text", text: JSON.stringify({ error: `Failed to parse details for document ${nummer}` }) }] }; } return { content: [{ type: "text", text: JSON.stringify(details, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: JSON.stringify({ error: `Error fetching document details: ${error.message || 'Unknown error'}` }) }] }; } }
  • Input schema using Zod: requires 'nummer' string parameter for the document ID.
    { nummer: z.string().describe("Document number (e.g., '2024D39058') - the unique identifier for the parliamentary document you want information about") },
  • Core helper function that implements the document details extraction logic by parsing HTML with regex patterns to pull title, type, nummer, datum, bijgewerkt, versie, direct PDF link, Tweede Kamer link, and attachment info (bijlageBij). Uses shared extractValue utility.
    export function extractDocumentDetailsFromHtml(html: string, baseUrl: string): DocumentDetails | null { if (!html) { return null; } const details: DocumentDetails = { title: null, type: null, nummer: null, datum: null, bijgewerkt: null, versie: null, directLinkPdf: null, tweedekamerLink: null, bijlageBij: null, }; // Extract basic info details.title = extractValue(html, /<hblock>\s*<h2>([\s\S]*?)<\/h2>/i); details.type = extractValue(html, /<\/hblock>[\s\S]*?<p><em>([\s\S]*?)<\/em><\/p>/i); // Extract metadata line const metadataMatch = html.match(/<p>Nummer: <b>(.*?)<\/b>, datum: <b>(.*?)<\/b>, bijgewerkt: <b>(.*?)<\/b>, versie: (\d+)/i); if (metadataMatch) { details.nummer = metadataMatch[1]?.trim() || null; details.datum = metadataMatch[2]?.trim() || null; details.bijgewerkt = metadataMatch[3]?.trim() || null; details.versie = metadataMatch[4] ? parseInt(metadataMatch[4], 10) : null; } // Extract links const directLinkMatch = html.match(/<a href="(getraw\/[^"']+)">Directe link naar document<\/a>/i); if (directLinkMatch && directLinkMatch[1]) { // Ensure the URL includes the /tkconv/ path const rawPath = directLinkMatch[1]; // If baseUrl already includes /tkconv/, this will work correctly // If not, we need to add it manually if (baseUrl.endsWith('/tkconv')) { details.directLinkPdf = `${baseUrl}/${rawPath}`; } else if (baseUrl.includes('/tkconv/')) { details.directLinkPdf = new URL(rawPath, baseUrl).href; } else { // Ensure we have /tkconv/ in the path details.directLinkPdf = `${baseUrl}/tkconv/${rawPath}`; } } details.tweedekamerLink = extractValue(html, /<a href="(https:\/\/www\.tweedekamer\.nl\/[^"']+)">link naar pagina op de Tweede Kamer site<\/a>/i); // Extract bijlage bij info const bijlageMatch = html.match(/<p>Bijlage bij: <a href="(document\.html\?nummer=[^"]+)">([\s\S]*?)<\/a> \(([^)]+)\)<\/p>/i); if (bijlageMatch && bijlageMatch[1]) { details.bijlageBij = { title: bijlageMatch[2]?.trim() || null, nummer: bijlageMatch[3]?.trim() || null, link: new URL(bijlageMatch[1], baseUrl).href, }; } return details; }
  • TypeScript interface defining the structure of the document details object returned by the tool's extraction logic.
    interface DocumentDetails { title: string | null; type: string | null; nummer: string | null; datum: string | null; bijgewerkt: string | null; versie: number | null; directLinkPdf: string | null; tweedekamerLink: string | null; bijlageBij: { title: string | null; nummer: string | null; link: string; } | null; }

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