Recipes

Wire an MCP-aware AI agent

Add the brandRNA MCP server to your custom agent so it can call analyze_brand and get_brand_pack.

The brandRNA MCP server exposes two tools to any compliant MCP client: get_brand_pack(domain) for cache-first lookups and analyze_brand(url) to trigger a fresh extraction. Out of the box, five clients (Claude Desktop, Cursor, Lovable, v0, Bolt) work with a single copy-paste from the dashboard. This recipe is for the sixth one — your own custom agent.

When this is useful

  • You're building a custom AI agent (Anthropic / OpenAI / vendor-specific MCP client) that needs branded outputs.
  • You're integrating brandRNA into a multi-tool agent (alongside other MCP servers) and want unified OAuth.
  • You want per-user usage attribution — every tool call rolls up to the user's brandRNA account, not a shared service token.

Prerequisites

  • An MCP client library. Anthropic's official SDKs are easiest:
    • Node/TS: @modelcontextprotocol/sdk
    • Python: mcp (PyPI)
  • A brandRNA account at brandrna.com/signup. No API key needed — MCP authenticates via OAuth.

Step-by-step

Discover the MCP server

The brandRNA MCP server lives at https://mcp.brandrna.com. Point your client there and let it negotiate the protocol:

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";

const transport = new SSEClientTransport(
  new URL("https://mcp.brandrna.com"),
);
const client = new Client(
  { name: "my-agent", version: "1.0.0" },
  { capabilities: {} },
);
await client.connect(transport);
from mcp.client.sse import sse_client
from mcp import ClientSession

async with sse_client("https://mcp.brandrna.com") as (read, write):
    async with ClientSession(read, write) as session:
        await session.initialize()
        # ... tool calls

Negotiate OAuth via Dynamic Client Registration

The brandRNA MCP server is an OAuth 2.1 provider. Most MCP SDKs handle DCR automatically — your client registers itself, kicks off the authorization code flow with PKCE, and receives an access token bound to the user's brandRNA account.

For the full handshake (registration, redirect, token exchange, revocation), see the OAuth dance explainer.

List the available tools

Once connected, your client can discover what tools the server exposes:

const tools = await client.listTools();
console.log(tools.tools.map((t) => t.name));
// ["get_brand_pack", "analyze_brand"]

get_brand_pack is your cache-first read. analyze_brand is the extraction trigger; it's slower (5–15s) and counts toward the user's monthly quota.

Call get_brand_pack first

Most domains worth fetching are already in our cache. Try the cheap read before the expensive extraction:

async function fetchOrAnalyze(domain: string) {
  try {
    const result = await client.callTool({
      name: "get_brand_pack",
      arguments: { domain },
    });
    return result;
  } catch (err: any) {
    // 404: not in cache yet
    if (err.code === -32000 && err.data?.reason === "not_found") {
      return null; // signal to caller to trigger analyze_brand
    }
    throw err;
  }
}

Fall back to analyze_brand on 404

If the cache miss returned null, kick off a fresh extraction. The MCP tool is async — it returns a job_id; poll until ready or wait on the SSE stream:

async function analyzeAndWait(url: string) {
  const job = await client.callTool({
    name: "analyze_brand",
    arguments: { url },
  });
  // Implementation depends on your client's polling model;
  // typical pattern: poll get_brand_pack(domain) every 2s up to 60s.
  return await pollUntilReady(job.content[0].text);
}

Handle billing attribution

The OAuth token your client holds maps to a managed key behind the scenes. Every get_brand_pack and analyze_brand call rolls up to the user's brandRNA account — /api/v1/usage on the REST surface reflects the same numbers.

If the user's quota is exhausted, the tool call returns the JSON-RPC error code -32001 (QuotaExceeded) with data.upgrade_url populated. Surface that link so the user can upgrade in-flow.

The two MCP tools are guaranteed to match the REST endpoints (GET /api/v1/pack/{domain} and POST /api/v1/analyze) byte-for-byte on the response shape. You can prototype with curl and migrate to MCP without changing your data model.

What's next

  • Read the OAuth dance explainer for production hardening (refresh tokens, revocation, multi-account flows).
  • Check the per-client guides under /docs/mcp — the snippets there are the same ones the dashboard surfaces.
  • Cross-link to errors for the JSON-RPC error code matrix.

On this page