Skip to content
James Ross
articlePublished Updated 7 min read

One tool registry behind chat and MCP: 36 tools, one set of guardrails

By James Ross

A shared tool registry defines each tool once — name, schema, scope, credit cost, dry-run behaviour and handler — then serves that same definition to both the in-app assistant and external MCP clients. An AI email platform runs 36 tools this way, so an MCP caller gets the same scopes, credit holds, dry runs and approval rule as the chat box.

One registry of tool blocks serving a chat console and a protocol port through the same guardrail gate, showing a shared MCP tool registry.

This sits on top of the authorization layer described in building a remote MCP server with OAuth 2.1. The registry decides what a caller may do; OAuth decides who the caller is.

Why two tool layers drift

Two tool lists always drift. The chat assistant needs a handler and a schema; the MCP server needs a name, a description and a JSON Schema. If those are written in different files by different people, the names diverge first, then the arguments, then the behaviour.

The drift is not cosmetic. A chat tool can rely on the session, the selected account and a server-side user object. An MCP caller arrives with a bearer token, an account ID and a scope set. If the two paths have separate implementations, one of them will eventually skip a credit hold, a plan check or the approval rule. The one that skips it will be the one nobody tests.

The registry removes the second implementation. There is one entry per tool, and both surfaces are adapters over it. The chat calls the handler with a user session. The hosted MCP server calls the same handler with a token context. The stdio package calls the same tool through the public API, which is the only path that can work from a user’s laptop.

What a registry entry carries

A registry entry is a tool’s whole contract. If a field is not in the entry, the wrapper cannot enforce it, so the fields are chosen to match the guardrails rather than the handler’s convenience.

Field Why it exists
name The identifier the model calls. Snake case, verb first, stable across releases.
description What the tool does and, more importantly, what it will not do.
schema A Zod schema that becomes the JSON Schema in tools/list.
scope The permission the caller must hold. Read-only is the default.
credits The cost, so the dry run can report it before anything is spent.
effect read, draft or commit. Draft tools create pending objects; commit tools need a human.
handler The one implementation both surfaces call.
export const createSegment = defineTool({
  name: "create_segment",
  description:
    "Create a draft segment from a validated definition. " +
    "Does not activate the segment; a human publishes it.",
  schema: z.object({
    name: z.string().min(1).max(120),
    definition: segmentDefinition,
  }),
  scope: "segments:write",
  credits: 0,
  effect: "draft",
  handler: async (ctx, input) => {
    const segment = await ctx.db.segment.create({
      data: { accountId: ctx.accountId, ...input, status: "DRAFT" },
    });
    return { segment_id: segment.id, status: "draft" };
  },
});

The wrapper around the handler is where the guardrails live: scope check, plan limit, credit hold, ToolCall log, error mapping. A handler that forgets one of them cannot ship, because the handler never sees the request until the wrapper has passed it.

One set of guardrails on both surfaces

The rule that makes the shared registry worth the work is that a tool behaves identically no matter who calls it. Four guardrails carry most of that weight.

Credits. A tool that spends credits holds them before the work and charges on completion. The dry run is not a separate code path; it is the same handler with a flag that stops before the hold. That is why the dry-run response can name the exact cost: the cost is a field on the entry, not a paragraph in a description.

Scopes. Scopes are deny-by-default, and the read-only set is what a new client gets. A registered client scope can only be narrowed at consent time. The MCP caller’s scopes are checked by the same wrapper that checks the chat session’s membership role.

Drafts. Every tool that changes live behaviour creates a draft or a pending approval. No tool sends an email, takes a flow live or approves anything. request_approval creates a pending Approval with a snapshot, and a human approves it in the app or through the emailed link.

Audit. The wrapper writes a ToolCall row for every invocation, including the dry runs. When an assistant does something surprising, the row is the only reliable account of what it sent.

The two surfaces are not equivalent

The registry is shared; the surfaces are not interchangeable. The hosted server has the account context, storage and queue access to run every tool. The stdio package runs on a user’s machine and talks to the public API, so it can only offer what the API can actually perform.

In-app chat Hosted MCP stdio MCP
Identity Session cookie and membership OAuth access token or API key API key from the environment
Tools All 36 All 36 12 that dispatch
Credit holds Yes Yes Yes, through the API
Image and file tools Yes Yes No; needs server-side storage
Network position Inside the app Public endpoint User’s machine, outbound only
Best for Guided work in the product Connectors and remote agents Local editors and scripts

Which should you choose? Use the hosted server for anything that needs storage, image generation or account-wide reads. Use stdio when the caller is a local editor and the work maps cleanly onto public API endpoints. Do not pretend the two are the same; the honest split is more useful than a tool list that looks complete and fails at call time.

The most useful line in the audit was a ratio: 36/36 by name, 5/36 functional on stdio. Registration was never the problem. The stdio package looped the whole registry into tools/list, then its dispatch handled five names and sent everything else to a default branch that returned an “unavailable” result.

That is worse than a missing tool. A model reads tools/list as a promise. When it calls a promised tool and gets a refusal, it retries, rephrases and eventually tells the user the product cannot do something it can do. The failure is not the missing handler; it is the false advertisement.

The fix was to shrink the list, not to fake the handlers. The stdio package now advertises 12 tools: get_account_overview, get_results, preview_segment, preview_segment_count, create_segment, update_segment, create_list, add_to_list, remove_from_list, create_flow, create_campaign and request_approval. Every one dispatches through the public API. The rest are documented as hosted-only.

The limits that remain are stated in the README rather than hidden:

  • add_to_list accepts profile IDs or a segment snapshot on stdio. Looking contacts up by email or import ID needs the hosted server.
  • create_campaign creates a draft and rejects scheduledAt, because the public API creates drafts only and a human schedules in the app.
  • create_flow does not accept a gallery template ID.
  • request_approval supports flow_live and campaign_send. A flow_change has no public endpoint, so the tool refuses with an explanation instead of writing an approval nothing can apply.

What broke and what we changed

The stdio gap was the main failure, and the interesting part is how quiet it was. Each piece looked correct on its own: the registry had 36 tools, the stdio server registered all of them, and the dispatch function had a default branch that returned a structured error. Nothing crashed, and a tools/list response with 36 entries looks complete.

Three changes came out of it:

  • A check that calls every advertised tool. Counting entries in tools/list proves nothing; the count is the same whether the handlers exist or not. Walking the list and asserting that each name reaches a handler is the same class of check as a link checker: it fails when the surface and the implementation disagree.
  • An explicit hosted-only list. The README names the hosted-only tools, so the split is documented where a client author will read it rather than inferred from a failed call.
  • Refusals that explain themselves. Where a tool exists but a parameter cannot be honoured, the response says why and what to use instead. A refusal with a reason lets a model recover; a generic error makes it retry the same call.

The other correction was smaller. The confirm argument is added by the wrapper rather than written into each schema, so a new tool cannot forget it. Because the wrapper owns the argument, the dry run is available on every credit-spending tool by construction, including tools added after the rule was written.

Frequently asked questions

What is a shared MCP tool registry?

It is one definition per tool — name, schema, scope, cost, effect and handler — that both the product's chat assistant and the MCP server read. The registry is the contract; each surface is an adapter over it. The alternative is two lists that drift until one surface behaves differently from the other, usually in the guardrail nobody tests.

Should the chat assistant and MCP server share tool code?

Yes, if they act on the same account data. Shared code is the only way to guarantee the same scope checks, credit holds and approval rule on both. The surfaces can differ in transport and in which tools they expose; they should not differ in what a tool does.

Why expose fewer tools on stdio?

Because a stdio process talks to the public API and cannot reach server-side storage, queues or internal handlers. Advertising tools it cannot run makes a model retry a call that will never work. Twelve working tools are more useful than thirty-six names with five implementations.

How do you stop a tool spending credits by accident?

Make the dry run the default. A tool that can spend credits requires confirm: true; without it the call returns the cost and does nothing. The wrapper adds the argument to every credit-spending tool, so no tool can opt out and the dry run cannot be forgotten.

Do MCP tools need JSON Schema?

The protocol requires an inputSchema that is a valid JSON Schema object, defaulting to 2020-12 when no $schema is present. In practice a typed schema library generates it from the same definition the handler validates against, which keeps the runtime validation and the advertised schema from drifting apart.

How many tools should one MCP server expose?

As many as it can dispatch correctly, and no more. Tool count is not a quality signal; a caller that gets a correct refusal learns more than one that gets a plausible but empty result. Group related operations and keep the names predictable.

How do you audit a tool surface?

Call every tool in tools/list and assert that it reaches a handler. Then check that the effect matches the description: a tool described as creating a draft must not be able to publish, and a read-only tool must not hold credits.