browse_legislation
Browse Canadian legislation by database (e.g., Ontario Statutes, Canada Statutes). Retrieve legislation IDs for metadata lookup with filters for publication, modification, and decision dates.
Instructions
List all legislation items in a specific database. Use to find legislation IDs for metadata lookup. Key statutes by database — ons: Children's Law Reform Act, Family Law Act, Employment Standards Act. cas: Divorce Act, Criminal Code, Canada Labour Code, Federal Child Support Guidelines.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| language | No | Language: 'en' for English (default), 'fr' for French | en |
| databaseId | Yes | Legislation database ID (e.g., 'ons' for Ontario Statutes, 'cas' for Canada Statutes, 'onr' for Ontario Regulations) | |
| publishedBefore | No | Date first published on CanLII (YYYY-MM-DD) | |
| publishedAfter | No | Date first published on CanLII (YYYY-MM-DD) | |
| modifiedBefore | No | Date content last modified on CanLII (YYYY-MM-DD) | |
| modifiedAfter | No | Date content last modified on CanLII (YYYY-MM-DD) | |
| changedBefore | No | Date metadata or content last changed on CanLII (YYYY-MM-DD) | |
| changedAfter | No | Date metadata or content last changed on CanLII (YYYY-MM-DD) | |
| decisionDateBefore | No | Decision date upper bound (YYYY-MM-DD) | |
| decisionDateAfter | No | Decision date lower bound (YYYY-MM-DD) |
Implementation Reference
- src/index.ts:434-472 (handler)The main handler for the browse_legislation tool. It constructs a CanLII API URL for browsing legislation in a given database, calls apiFetch with rate limiting, validates the response with LegislationItemResponseSchema, and returns the result.
// ============================================================ // TOOL: browse_legislation // ============================================================ server.tool( "browse_legislation", "List all legislation items in a specific database. Use to find legislation IDs for metadata lookup. " + "Key statutes by database — ons: Children's Law Reform Act, Family Law Act, Employment Standards Act. " + "cas: Divorce Act, Criminal Code, Canada Labour Code, Federal Child Support Guidelines.", { 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, 'cas' for Canada Statutes, 'onr' for Ontario Regulations)"), ...dateParametersSchema, }, async (params) => { try { const { language, databaseId, ...dateParams } = params; const urlParams = new URLSearchParams({ api_key: apiKey }); buildDateParams(urlParams, dateParams); const response = await apiFetch( `https://api.canlii.org/v1/legislationBrowse/${language}/${encodeURIComponent(databaseId)}/?${urlParams.toString()}` ); if (!response.ok) { return errorResponse(`Error: Failed to fetch legislation list (${response.status})`); } const data = await response.json(); const parsed = LegislationItemResponseSchema.parse(data); return jsonResponse(parsed); } catch (error) { return errorResponse( `Error: ${error instanceof Error ? error.message : "Unknown error"}` ); } } ); - src/index.ts:437-448 (registration)Registration of the browse_legislation tool on the MCP server with name, description, and input schema (language, databaseId, and date parameters).
server.tool( "browse_legislation", "List all legislation items in a specific database. Use to find legislation IDs for metadata lookup. " + "Key statutes by database — ons: Children's Law Reform Act, Family Law Act, Employment Standards Act. " + "cas: Divorce Act, Criminal Code, Canada Labour Code, Federal Child Support Guidelines.", { 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, 'cas' for Canada Statutes, 'onr' for Ontario Regulations)"), ...dateParametersSchema, }, - src/schema.ts:88-90 (schema)LegislationItemResponseSchema - zod schema used to parse the API response for browse_legislation, containing an array of legislation items.
export const LegislationItemResponseSchema = z.object({ legislations: z.array(LegislationItemSchema), }).passthrough(); - src/schema.ts:80-86 (schema)LegislationItemSchema - zod schema for each individual legislation item returned by browse_legislation (databaseId, legislationId, title, citation, type).
export const LegislationItemSchema = z.object({ databaseId: z.string(), legislationId: z.string(), title: z.string(), citation: z.string(), type: z.string(), }).passthrough(); - src/index.ts:69-87 (helper)buildDateParams helper function used by browse_legislation to add optional date filter parameters to the API request URL.
function buildDateParams(params: URLSearchParams, options: { publishedBefore?: string; publishedAfter?: string; modifiedBefore?: string; modifiedAfter?: string; changedBefore?: string; changedAfter?: string; decisionDateBefore?: string; decisionDateAfter?: string; }) { if (options.publishedBefore) params.append('publishedBefore', options.publishedBefore); if (options.publishedAfter) params.append('publishedAfter', options.publishedAfter); if (options.modifiedBefore) params.append('modifiedBefore', options.modifiedBefore); if (options.modifiedAfter) params.append('modifiedAfter', options.modifiedAfter); if (options.changedBefore) params.append('changedBefore', options.changedBefore); if (options.changedAfter) params.append('changedAfter', options.changedAfter); if (options.decisionDateBefore) params.append('decisionDateBefore', options.decisionDateBefore); if (options.decisionDateAfter) params.append('decisionDateAfter', options.decisionDateAfter); }