Skip to main content
Glama

Search Legislation

search_legislation

Search Australian legislation to find relevant laws and regulations with structured results. Focuses on Commonwealth and Victorian jurisdictions, returning matches with citation metadata.

Instructions

Search Australian legislation (Commonwealth and Victorian focus) and return structured matches.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNojson
jurisdictionNo
limitNo
queryYes

Implementation Reference

  • Inline handler function that parses the tool input using Zod, calls the searchAustLii helper with legislation type, and formats the search results.
    async (rawInput) => {
      const { query, jurisdiction, limit, format, sortBy } =
        searchLegislationParser.parse(rawInput);
      const results = await searchAustLii(query, {
        type: "legislation",
        jurisdiction,
        limit,
        sortBy,
      });
      return formatSearchResults(results, format ?? "json");
    },
  • Zod schema definition and parser for validating input parameters to the search_legislation tool (query, jurisdiction, limit, format, sortBy).
    const searchLegislationShape = {
      query: z.string().min(1, "Query cannot be empty."),
      jurisdiction: jurisdictionEnum.optional(),
      limit: z.number().int().min(1).max(50).optional(),
      format: formatEnum.optional(),
      sortBy: sortByEnum.optional(),
    };
    const searchLegislationParser = z.object(searchLegislationShape);
  • src/index.ts:33-52 (registration)
    MCP tool registration for 'search_legislation', including title, description, input schema, and handler function.
    server.registerTool(
      "search_legislation",
      {
        title: "Search Legislation",
        description:
          "Search Australian legislation (Commonwealth and Victorian focus) and return structured matches.",
        inputSchema: searchLegislationShape,
      },
      async (rawInput) => {
        const { query, jurisdiction, limit, format, sortBy } =
          searchLegislationParser.parse(rawInput);
        const results = await searchAustLii(query, {
          type: "legislation",
          jurisdiction,
          limit,
          sortBy,
        });
        return formatSearchResults(results, format ?? "json");
      },
    );
  • Core implementation of the search logic for legislation (and cases), handling URL construction for AustLII search, HTTP request, HTML parsing with Cheerio, filtering by type 'legislation', extraction of metadata, sorting/boosting, and error handling.
    export async function searchAustLii(
      query: string,
      options: SearchOptions,
    ): Promise<SearchResult[]> {
      try {
        const searchParams = buildSearchParams(query, options);
        const limit = options.limit ?? 10;
    
        // Determine sort mode (auto-detect or use explicit setting)
        const sortMode = determineSortMode(query, options);
    
        const searchUrl = new URL(AUSTLII_SEARCH_BASE);
        searchUrl.searchParams.set("method", "boolean");
        searchUrl.searchParams.set("query", searchParams.query);
        searchUrl.searchParams.set("meta", searchParams.meta);
        searchUrl.searchParams.set("results", String(limit));
    
        // Set sort order based on mode
        if (sortMode === "relevance") {
          searchUrl.searchParams.set("view", "relevance");
        } else {
          searchUrl.searchParams.set("view", "date");
        }
    
        const response = await axios.get(searchUrl.toString(), {
          headers: {
            "User-Agent": "auslaw-mcp/0.1.0 (legal research tool)",
          },
          timeout: 15000,
        });
    
        const html = response.data;
        const $ = cheerio.load(html);
        const results: SearchResult[] = [];
    
        // Parse search results - AustLII returns results in an <OL> ordered list
        $("ol li").each((_, element) => {
          const $li = $(element);
          const $link = $li.find("a").first();
          const title = $link.text().trim();
          let url = $link.attr("href") || "";
    
          // Make URL absolute if relative
          if (url && !url.startsWith("http")) {
            url = `http://classic.austlii.edu.au${url}`;
          }
    
          if (title && url) {
            // Always skip journal articles - we only want primary sources
            if (url.includes("/journals/")) {
              return; // Skip journal articles
            }
    
            // For cases, only include actual case databases
            if (options.type === "case" && !url.includes("/cases/")) {
              return; // Skip non-case results
            }
    
            // For legislation, only include legislation databases
            if (options.type === "legislation" && !url.includes("/legis/")) {
              return; // Skip non-legislation results
            }
    
            // Try to extract citation from title
            const citationMatch = title.match(/\[(\d{4})\]\s*([A-Z]+)\s*(\d+)/);
            const neutralCitation = citationMatch ? citationMatch[0] : undefined;
            const year = citationMatch ? citationMatch[1] : undefined;
    
            // Extract jurisdiction from URL
            const jurisdictionMatch = url.match(/\/au\/cases\/(cth|vic|nsw|qld|sa|wa|tas|nt|act)\//i);
            const jurisdiction = jurisdictionMatch?.[1]?.toLowerCase();
    
            // Extract summary from <small> tag if present
            const $small = $li.find("small");
            const summary = $small.length > 0 ? $small.text().trim() : undefined;
    
            results.push({
              title,
              citation: undefined,
              neutralCitation,
              url,
              source: "austlii",
              summary,
              jurisdiction,
              year,
              type: options.type,
            });
          }
        });
    
        // Apply title matching boost when using relevance sorting
        let finalResults = results;
        if (sortMode === "relevance" && isCaseNameQuery(query)) {
          finalResults = boostTitleMatches(results, query);
        }
    
        return finalResults.slice(0, limit);
      } catch (error) {
        if (axios.isAxiosError(error)) {
          throw new Error(`AustLII search failed: ${error.message}`);
        }
        throw error;
      }
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions 'returns structured matches' which hints at output format, but doesn't cover critical aspects like whether this is a read-only operation, rate limits, authentication needs, error conditions, or what 'structured matches' actually means in practice.

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?

The description is extremely concise - a single sentence that efficiently communicates the core purpose. It's front-loaded with essential information and contains no unnecessary words or redundant information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a search tool with 4 parameters (2 with enums), 0% schema description coverage, and no output schema, the description is inadequate. It doesn't explain parameter meanings, output format details, or behavioral constraints. The agent would struggle to use this tool effectively without additional context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate but provides no parameter information. It doesn't explain what 'jurisdiction' values mean (cth, vic, federal, other), what 'format' options represent, or how 'query' should be structured. The description adds no meaning beyond what the bare schema provides.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool searches Australian legislation with a focus on Commonwealth and Victorian jurisdictions and returns structured matches. It specifies the verb 'search', resource 'Australian legislation', and scope 'Commonwealth and Victorian focus', but doesn't explicitly differentiate from sibling tools like fetch_document_text or search_cases.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like fetch_document_text or search_cases. There's no mention of prerequisites, appropriate contexts, or exclusions, leaving the agent to infer usage based solely on tool names.

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/russellbrenner/auslaw-mcp'

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