Tenant reporting

Checked against FrontMCP 1.12.2 on

Intermediate

This FrontMCP reporting server serves made-up revenue records for two tenants. Its get_report tool takes the tenant from the trusted caller context, not from the arguments. The server then picks that tenant's API credential. The backing API decides which records that credential can read. The tests try an anonymous caller, another tenant's record ID, a forged tenant argument and a record that doesn't exist. The local download also checks calls that run at the same time. Nothing here uses a live identity provider, real financial data or an external API.

Follow one request

  1. In production, the server verifies the caller's token. The in-process tests pass trusted context in directly. That is a fixture, not a test of token verification.
  2. get_report reads the tenant from verified claims. A tenant argument cannot grant access.
  3. The server picks a synthetic credential for the backing API. The credential is not in the input schema or the result.
  4. The backing API checks the credential's tenant against the record's owner.
  5. Only the permitted record reaches the client and the model. Another tenant's record and a missing record get the same error.

The server and its access checks

In the browser, the caller is anonymous. dataset_info is public. Calling get_report from the Call tab is meant to fail. Open Tests to see the permitted and refused calls.

Open
import { Provider, PublicMcpError, Tool, ToolContext, z } from "@frontmcp/sdk";

const credentials = { north: "fixture-north", south: "fixture-south" } as const;
const records = [
  { id: "R-1", tenant: "north", revenue: 1200 },
  { id: "R-2", tenant: "south", revenue: 900 },
];

@Provider({ name: "ReportApi" })
export class ReportApi {
  read(id: string, credential: string) {
    const tenant = Object.entries(credentials).find(([, value]) => value === credential)?.[0];
    const record = records.find((item) => item.id === id && item.tenant === tenant);
    if (!record) throw new PublicMcpError("Report not found", "NOT_FOUND");
    return { id: record.id, revenue: record.revenue };
  }
}

@Tool({ name: "dataset_info", description: "Describe the synthetic reporting dataset", inputSchema: {}, annotations: { readOnlyHint: true } })
export class DatasetInfo extends ToolContext {
  async execute() { return { fixture: true, tenants: 2, records: 2 }; }
}

@Tool({
  name: "get_report",
  description: "Read one report owned by the authenticated tenant",
  inputSchema: { id: z.string(), tenant: z.string().optional().describe("Untrusted hint; cannot grant access") },
  annotations: { readOnlyHint: true },
})
export class GetReport extends ToolContext {
  async execute({ id, tenant: hint }: { id: string; tenant?: string }) {
    const tenant = this.auth.claims.tenant;
    if (this.auth.isAnonymous || (tenant !== "north" && tenant !== "south")) {
      this.fail(new PublicMcpError("A verified tenant is required", "AUTH_REQUIRED"));
    }
    if (hint && hint !== tenant) this.fail(new PublicMcpError("Report not found", "NOT_FOUND"));
    return this.get(ReportApi).read(id, credentials[tenant as keyof typeof credentials]);
  }
}

Starting FrontMCP in your browser…

FrontMCP starts when this example comes into view.

The browser runtime uses a simplified request context, so these browser checks make one call at a time. The local project adds a Node check for concurrent calls, using real AsyncLocalStorage. Don't treat the browser fixture as proof that concurrent callers stay isolated.

Run locally

Download the version-pinned reporting project. The archive has the same files, plus the app and server registration, a dependency lockfile, local tests and instructions. It doesn't include your browser edits or any credentials. Use Node.js 24+:

tar -xzf tenant-reporting.tgz
cd tenant-reporting
npm ci
npm test
npm run dev

The tests are the Playground checks, adapted to e2e/*.e2e.spec.ts with an explicit server entry. The local endpoint is /mcp by default. dataset_info is public, and get_report refuses callers without a verified tenant. The archive's README has a protocol request and the build commands.

Connect real identity and data

Replace the in-memory API and credential map with your own service and secret store. Configure transparent auth with the issuer, audience and keys you trust, then map the provider's verified tenant claim. Remote auth doesn't copy every upstream claim. Read what remote tools see before you rely on custom claims.

Add HTTP tests for missing, expired and wrong-audience tokens, two real tenant identities, the backing API's authorization and log redaction. Background jobs need their own explicit principal and credential lifecycle. This fixture shows application checks. It doesn't certify tenant isolation for a deployment.

For production, choose a deployment target and configure secrets and persistence. Then send permitted and refused requests to the deployed endpoint. Record the target, the configuration and the date. A local build doesn't prove that a hosted deployment works.

Report a docs issue · Report a security concern privately