get_courts_and_tribunals
List all available Canadian court and tribunal databases from CanLII. Returns database IDs required for browse, citator, and other tools. Use to find valid IDs for courts like ONSC, ONCA, SCC, BCSC, etc.
Instructions
List all available court and tribunal databases in Canada. Returns database IDs needed for other tools. Key databases: onsc (Ontario Superior Court), onca (Ontario Court of Appeal), oncj (Ontario Court of Justice), onscdc (Divisional Court), csc-scc (Supreme Court of Canada), bcsc (BC Supreme Court), abkb (Alberta King's Bench). Use this to discover valid databaseId values for browse and citator tools.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| language | No | Language: 'en' for English (default), 'fr' for French | en |
| 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:169-203 (handler)The handler function for the get_courts_and_tribunals tool. It accepts language (en/fr) and optional date parameters, makes a GET request to the CanLII caseBrowse API, validates the response with CaseDatabasesResponseSchema, and returns the list of court/tribunal databases.
server.tool( "get_courts_and_tribunals", "List all available court and tribunal databases in Canada. Returns database IDs needed for other tools. " + "Key databases: onsc (Ontario Superior Court), onca (Ontario Court of Appeal), oncj (Ontario Court of Justice), " + "onscdc (Divisional Court), csc-scc (Supreme Court of Canada), bcsc (BC Supreme Court), abkb (Alberta King's Bench). " + "Use this to discover valid databaseId values for browse and citator tools.", { language: z.enum(["en", "fr"]).default("en") .describe("Language: 'en' for English (default), 'fr' for French"), ...dateParametersSchema, }, async (params) => { try { const { language, ...dateParams } = params; const urlParams = new URLSearchParams({ api_key: apiKey }); buildDateParams(urlParams, dateParams); const response = await apiFetch( `https://api.canlii.org/v1/caseBrowse/${language}/?${urlParams.toString()}` ); if (!response.ok) { return errorResponse(`Error: Failed to fetch databases (${response.status})`); } const data = await response.json(); const parsed = CaseDatabasesResponseSchema.parse(data); return jsonResponse(parsed); } catch (error) { return errorResponse( `Error: ${error instanceof Error ? error.message : "Unknown error"}` ); } } ); - src/schema.ts:3-12 (schema)The CaseDatabaseSchema (lines 3-8) and CaseDatabasesResponseSchema (lines 10-12) define the response type for the tool: an object with a 'caseDatabases' array, each containing databaseId, jurisdiction, name, and optional url.
export const CaseDatabaseSchema = z.object({ databaseId: z.string(), jurisdiction: z.string(), name: z.string(), url: z.string().optional(), }).passthrough(); export const CaseDatabasesResponseSchema = z.object({ caseDatabases: z.array(CaseDatabaseSchema), }).passthrough(); - src/index.ts:169-203 (registration)The tool is registered via server.tool() on line 169 with the name 'get_courts_and_tribunals', a descriptive string, input schema (language enum + date parameters), and the async handler.
server.tool( "get_courts_and_tribunals", "List all available court and tribunal databases in Canada. Returns database IDs needed for other tools. " + "Key databases: onsc (Ontario Superior Court), onca (Ontario Court of Appeal), oncj (Ontario Court of Justice), " + "onscdc (Divisional Court), csc-scc (Supreme Court of Canada), bcsc (BC Supreme Court), abkb (Alberta King's Bench). " + "Use this to discover valid databaseId values for browse and citator tools.", { language: z.enum(["en", "fr"]).default("en") .describe("Language: 'en' for English (default), 'fr' for French"), ...dateParametersSchema, }, async (params) => { try { const { language, ...dateParams } = params; const urlParams = new URLSearchParams({ api_key: apiKey }); buildDateParams(urlParams, dateParams); const response = await apiFetch( `https://api.canlii.org/v1/caseBrowse/${language}/?${urlParams.toString()}` ); if (!response.ok) { return errorResponse(`Error: Failed to fetch databases (${response.status})`); } const data = await response.json(); const parsed = CaseDatabasesResponseSchema.parse(data); return jsonResponse(parsed); } catch (error) { return errorResponse( `Error: ${error instanceof Error ? error.message : "Unknown error"}` ); } } ); - src/index.ts:69-87 (helper)The buildDateParams helper function is used by the handler to append 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); } - src/index.ts:93-95 (helper)The jsonResponse helper function formats the parsed response data as a JSON text response for the tool output.
function jsonResponse(data: unknown) { return textResponse(JSON.stringify(data, null, 2)); }