GetLawED
Law library › Developers › Code samples

Code samples

Python (requests)

import os, requests

API = "https://getlawed.co.za/api/law/v1"
headers = {"Authorization": f"Bearer {os.environ['GETLAWED_KEY']}"}

# 1. Search
r = requests.get(f"{API}/search", params={"q": "unfair dismissal reinstatement", "type": "act", "limit": 3}, headers=headers, timeout=30)
if r.status_code == 429:
    print("Allowance used up; retry after", r.headers.get("Retry-After"), "seconds")
r.raise_for_status()
for hit in r.json()["results"]:
    print(hit["title"], "|", hit.get("section"), "|", hit["url"])

# 2. Read the exact section
top = r.json()["results"][0]
s = requests.get(f"{API}/section", params={"doc_id": top["doc_id"], "section": top.get("section", "")}, headers=headers, timeout=30).json()
print(s["text"][:500])

# 3. Check citations in a draft
v = requests.post(f"{API}/verify", json={"text": "S v Makwanyane and Another 1995 (3) SA 391 (CC)"}, headers=headers, timeout=60).json()
for c in v["cases"] + v["acts"]:
    print(c["status"], c["cited"], c.get("url", ""))

JavaScript (fetch, Node 18+ or browser backend)

const API = "https://getlawed.co.za/api/law/v1";
const headers = { Authorization: `Bearer ${process.env.GETLAWED_KEY}` };

const res = await fetch(`${API}/search?` + new URLSearchParams({ q: "unfair dismissal reinstatement", type: "act", limit: "3" }), { headers });
if (res.status === 429) console.log("Retry after", res.headers.get("Retry-After"), "seconds");
const { results, source_note } = await res.json();
for (const r of results) console.log(r.title, "|", r.section, "|", r.url);

const check = await fetch(`${API}/verify`, {
  method: "POST",
  headers: { ...headers, "Content-Type": "application/json" },
  body: JSON.stringify({ text: "S v Makwanyane and Another 1995 (3) SA 391 (CC)" }),
}).then(r => r.json());
console.log(check.cases.map(c => `${c.status}: ${c.cited}`).join("\n"));

TypeScript — official MCP SDK

// npm install @modelcontextprotocol/sdk   (Node 18+, ESM; tested with SDK 1.x, 2026-10-13)
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";

const transport = new StreamableHTTPClientTransport(new URL("https://getlawed.co.za/api/mcp/law"), {
  requestInit: { headers: { Authorization: `Bearer ${process.env.GETLAWED_KEY}` } },
});
const client = new Client({ name: "my-app", version: "1.0.0" });
await client.connect(transport);

const { tools } = await client.listTools();
console.log(tools.map(t => t.name));

const result = await client.callTool({
  name: "legal_library_search",
  arguments: { query: "unfair dismissal reinstatement", doc_type: "act", limit: 3 },
});
console.log(result.content[0].text);
await client.close();

Python — official MCP SDK

# pip install "mcp>=2"   (Python 3.10+)
import asyncio, os
import httpx2
from mcp import ClientSession
from mcp.client.streamable_http import streamable_http_client

async def main():
    headers = {"Authorization": f"Bearer {os.environ['GETLAWED_KEY']}"}
    async with httpx2.AsyncClient(headers=headers, timeout=60) as http:
        async with streamable_http_client("https://getlawed.co.za/api/mcp/law", http_client=http) as (read, write):
            async with ClientSession(read, write) as session:
                await session.initialize()
                tools = await session.list_tools()
                print([t.name for t in tools.tools])
                result = await session.call_tool("legal_verify_citations", {"text": "S v Makwanyane and Another 1995 (3) SA 391 (CC)"})
                print(result.content[0].text)

asyncio.run(main())

Both SDK clients connect over Streamable HTTP; both examples were run against the live server on 2026-10-13 (Python: mcp 2.3). The server answers with JSON (no SSE stream), which the SDKs handle. Python SDK 1.x users: the transport there is streamablehttp_client(url, headers=…) and yields three values.

Using an AI assistant? Connect it to GetLawED's verified South African law library — it can then quote provisions with their official source and check citations before you rely on them. How to connect