Skip to main content
Glama
self-tech-labs

Online Kommentar MCP Server

get_commentary_by_id

Retrieve detailed legal commentary content by specifying its unique ID using the Model Context Protocol for Swiss legal resources.

Instructions

Retrieves a specific commentary by its ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesThe ID of the commentary to retrieve.

Implementation Reference

  • The handler function fetches commentary data from the API by ID, formats it nicely, and returns it as text content. Handles 404 and other errors.
    async ({ id }: { id: string }) => { try { const response = await fetch(`${API_BASE_URL}/commentaries/${id}`, { headers: { "Accept": "application/json" } }); if (!response.ok) { if (response.status === 404) { return { content: [{ type: "text", text: `Commentary with ID '${id}' not found.` }], isError: true, }; } throw new Error(`API request failed with status ${response.status}`); } const data = (await response.json()) as { data: Commentary }; const commentary = data.data; // Let's format the output nicely for the user const authors = commentary.authors.map(a => a.name).join(', '); const editors = commentary.editors ? commentary.editors.map(e => e.name).join(', ') : 'None listed'; const resultText = ` Title: ${commentary.title} ID: ${commentary.id} Language: ${commentary.language} Publication Date: ${commentary.date} Legislative Act: ${commentary.legislative_act.title} Legal Domain: ${commentary.legal_domain?.name || 'Not specified'} Authors: ${authors} Editors: ${editors} URL: ${commentary.html_link} Content: ${commentary.content || 'Full content not available in summary.'} `.trim(); return { content: [{ type: "text", text: resultText }], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : "An unknown error occurred"; return { content: [{ type: "text", text: `Error retrieving commentary: ${errorMessage}` }], isError: true, }; } }
  • The tool schema defining title, description, and input validation using Zod for the commentary ID.
    { title: "Get Commentary by ID", description: "Retrieves a specific commentary by its ID.", inputSchema: { id: z.string().describe("The ID of the commentary to retrieve."), }, },
  • src/index.ts:91-147 (registration)
    Registers the 'get_commentary_by_id' tool on the MCP server with schema and inline handler function.
    server.registerTool( "get_commentary_by_id", { title: "Get Commentary by ID", description: "Retrieves a specific commentary by its ID.", inputSchema: { id: z.string().describe("The ID of the commentary to retrieve."), }, }, async ({ id }: { id: string }) => { try { const response = await fetch(`${API_BASE_URL}/commentaries/${id}`, { headers: { "Accept": "application/json" } }); if (!response.ok) { if (response.status === 404) { return { content: [{ type: "text", text: `Commentary with ID '${id}' not found.` }], isError: true, }; } throw new Error(`API request failed with status ${response.status}`); } const data = (await response.json()) as { data: Commentary }; const commentary = data.data; // Let's format the output nicely for the user const authors = commentary.authors.map(a => a.name).join(', '); const editors = commentary.editors ? commentary.editors.map(e => e.name).join(', ') : 'None listed'; const resultText = ` Title: ${commentary.title} ID: ${commentary.id} Language: ${commentary.language} Publication Date: ${commentary.date} Legislative Act: ${commentary.legislative_act.title} Legal Domain: ${commentary.legal_domain?.name || 'Not specified'} Authors: ${authors} Editors: ${editors} URL: ${commentary.html_link} Content: ${commentary.content || 'Full content not available in summary.'} `.trim(); return { content: [{ type: "text", text: resultText }], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : "An unknown error occurred"; return { content: [{ type: "text", text: `Error retrieving commentary: ${errorMessage}` }], isError: true, }; } } );
  • TypeScript interface defining the structure of a Commentary object used in the handler.
    interface Commentary { id: string; title: string; language: string; date: string; legislative_act: { id: string; title: string; }; legal_domain?: { id: string; name: string; }; authors: { id: string; name: string; }[]; editors?: { id: string; name: string; }[]; html_link: string; content?: string; }

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/self-tech-labs/onlinekommentar-mcp'

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