Skip to main content
Glama

get_legislation_regulation_metadata

Retrieve metadata for a specific statute or regulation, including its CanLII URL, citation, and table of contents. Provides direct link to full legislation text on canlii.org.

Instructions

Get metadata for a specific statute or regulation including its CanLII URL, citation, and table of contents. The URL links directly to the full legislation text on canlii.org — always provide this to the user.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
languageNoLanguage: 'en' for English (default), 'fr' for Frenchen
databaseIdYesLegislation database ID (e.g., 'ons' for Ontario Statutes)
legislationIdYesSpecific legislation ID from browse results

Implementation Reference

  • The handler/registration for the get_legislation_regulation_metadata tool. Fetches legislation metadata from the CanLII API (legislationBrowse endpoint) and returns the parsed response.
    // TOOL: get_legislation_regulation_metadata
    // ============================================================
    server.tool(
    	"get_legislation_regulation_metadata",
    	"Get metadata for a specific statute or regulation including its CanLII URL, citation, and table of contents. " +
    	"The URL links directly to the full legislation text on canlii.org — always provide this to the user.",
    	{
    		language: z.enum(["en", "fr"]).default("en")
    			.describe("Language: 'en' for English (default), 'fr' for French"),
    		databaseId: pathSegmentSchema
    			.describe("Legislation database ID (e.g., 'ons' for Ontario Statutes)"),
    		legislationId: pathSegmentSchema
    			.describe("Specific legislation ID from browse results"),
    	},
    	async ({ language, databaseId, legislationId }) => {
    		try {
    			const params = new URLSearchParams({ api_key: apiKey });
    
    			const response = await apiFetch(
    				`https://api.canlii.org/v1/legislationBrowse/${language}/${encodeURIComponent(databaseId)}/${encodeURIComponent(legislationId)}/?${params.toString()}`
    			);
    
    			if (!response.ok) {
    				return errorResponse(`Error: Failed to fetch legislation metadata (${response.status})`);
    			}
    
    			const data = await response.json();
    			const parsed = LegislationMetadataSchema.parse(data);
    			return jsonResponse(parsed);
    		} catch (error) {
    			return errorResponse(
    				`Error: ${error instanceof Error ? error.message : "Unknown error"}`
    			);
    		}
    	}
    );
  • Zod validation schema for the legislation metadata response, defining the shape of data returned by the tool.
    export const LegislationMetadataSchema = z.object({
        legislationId: z.string(),
        url: z.string(),
        title: z.string(),
        citation: z.string(),
        language: z.string().optional(),
        dateScheme: z.string().optional(),
        startDate: z.string().optional(),
        endDate: z.string().optional(),
        repealed: z.string().optional(),
        content: z.array(LegislationMetadataContentSchema).optional(),
    }).passthrough();
  • Sub-schema for the table of contents (content array) items within the legislation metadata.
    export const LegislationMetadataContentSchema = z.object({
        partId: z.string(),
        partName: z.string(),
    }).passthrough();
  • Helper rate-limited API fetch function used by the tool to call the CanLII API.
    async function apiFetch(url: string): Promise<Response> {
    	return new Promise((resolve, reject) => {
    		requestQueue = requestQueue.then(async () => {
    			const today = new Date().toDateString();
    			if (today !== dailyResetDate) {
    				dailyCount = 0;
    				dailyResetDate = today;
    			}
    			if (dailyCount >= 5000) {
    				throw new Error("Daily API limit reached (5,000 queries). Try again tomorrow.");
    			}
    			const now = Date.now();
    			const elapsed = now - lastRequestTime;
    			if (elapsed < MIN_INTERVAL_MS) {
    				await new Promise(r => setTimeout(r, MIN_INTERVAL_MS - elapsed));
    			}
    			lastRequestTime = Date.now();
    			dailyCount++;
    			return fetch(url);
    		}).then(resolve, reject);
    	});
    }
  • Helper response formatters: jsonResponse serializes data to JSON, errorResponse formats error messages (with API key redaction).
    function jsonResponse(data: unknown) {
    	return textResponse(JSON.stringify(data, null, 2));
    }
    
    function sanitizeError(message: string): string {
    	return message.replace(/api_key=[^&\s]*/gi, "api_key=REDACTED");
    }
    
    function errorResponse(message: string) {
    	return textResponse(sanitizeError(message));
    }
Behavior3/5

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

No annotations exist, so description bears full burden. It reveals what is returned but does not disclose that it is read-only, any side effects, permissions, or rate limits.

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

Conciseness5/5

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

Two sentences: first states purpose and content, second provides actionable instruction. No wasted words, information is front-loaded.

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 the tool's simplicity and absence of output schema, the description adequately covers the return content and user instruction. However, it could mention that the IDs come from browse results.

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?

Input schema has 100% description coverage, so the description adds minimal extra meaning beyond the schema's field descriptions. The mention of 'CanLII URL, citation, and table of contents' provides general context but not parameter details.

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 tool retrieves metadata for a specific statute/regulation, including URL, citation, and table of contents, distinguishing it from sibling tools like browse_legislation.

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

Usage Guidelines3/5

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

The description implies usage (when you need metadata for a specific legislation), but does not provide explicit guidance on when to prefer this over siblings or exclude certain cases.

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

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/mohammadfarooqi/canlii-mcp'

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