Code samples
Copy-paste clients for both transports of Tarno's read contract. Replace the <API_KEY> placeholder with
your operator-issued key at runtime — never commit a real key.
REST
curl
export TARNO_API_KEY="<API_KEY>"
# Search/list trademark summaries (keyset page)
curl -sS "https://api.tarno.cl/trademarks?q=cafe&limit=5" \
-H "X-API-Key: $TARNO_API_KEY"
# Full detail for one application, with expanded sections (`norms` also requires `legal:read`)
curl -sS "https://api.tarno.cl/trademarks/123456?expand=parties,annotations,encumbrances,classes,norms" \
-H "X-API-Key: $TARNO_API_KEY"
# Batch: several known applications at once (up to 100)
curl -sS "https://api.tarno.cl/trademarks?applicationNumber=1286842,823470,9999999" \
-H "X-API-Key: $TARNO_API_KEY"
TypeScript (fetch)
const baseUrl = "https://api.tarno.cl";
const apiKey = process.env.TARNO_API_KEY!; // "<API_KEY>"
async function listTrademarks(q: string, limit = 20) {
const url = new URL(`${baseUrl}/trademarks`);
url.searchParams.set("q", q);
url.searchParams.set("limit", String(limit));
const res = await fetch(url, { headers: { "X-API-Key": apiKey } });
if (!res.ok) {
const problem = await res.json(); // application/problem+json (RFC 9457)
throw new Error(`${problem.status} ${problem.code}: ${problem.detail}`);
}
// { results: Trademark[], limit, next, hasMore, total, meta }
return res.json() as Promise<{ results: unknown[]; next: string | null }>;
}
const page = await listTrademarks("cafe", 5);
console.log(page.results.length, "results; next =", page.next);
MCP
A minimal @modelcontextprotocol/sdk client that connects to the Streamable HTTP endpoint with the
X-API-Key header and calls the tools.
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
const url = process.env.MCP_URL ?? "https://mcp.tarno.cl";
const apiKey = process.env.TARNO_API_KEY!; // "<API_KEY>"
const transport = new StreamableHTTPClientTransport(new URL(url), {
requestInit: { headers: { "X-API-Key": apiKey } },
});
const client = new Client({ name: "tarno-mcp-example", version: "1.0.0" });
await client.connect(transport); // JSON-RPC initialize handshake
try {
// search_trademarks — same input/output as GET /trademarks
const search = await client.callTool({
name: "search_trademarks",
arguments: { q: "cafe", limit: 5 },
});
const firstText = (r: typeof search) =>
(r.content as Array<{ type: string; text?: string }>).find((c) => c.type === "text")?.text;
const page = JSON.parse(firstText(search) ?? "{}");
console.log(page.results.length, "results; next =", page.next);
// get_trademark — same input/output as GET /trademarks/{applicationNumber}
const detail = await client.callTool({
name: "get_trademark",
arguments: { applicationNumber: "123456", expand: ["parties", "annotations"] },
});
console.log(firstText(detail)); // detail JSON
} finally {
await client.close();
}
Both tools require the
brands:readscope (or an unrestricted key). A missing or invalid key returns an error result — never corpus data. See the MCP guide and the authentication guide.
See also
- Getting started — REST onboarding, envelope and pagination.
- Connect your AI agent (MCP) — endpoint, tools, client config.
- The live OpenAPI reference at
https://api.tarno.cl/docs— the authoritative REST schema.