Skip to content
API explorerProductOpen console

Your own MCP server

The agent can call tools that run in your service: look up an order, move a delivery, book a table. You expose them as an MCP server, Omazy connects to it, and the agent calls a tool when a conversation needs it. Your data stays in your database. Omazy sees the tool’s answer, not your tables.

@omazyai/sdk/server has a small MCP server for that: stateless, one JSON answer per request, so it runs on a Worker with no session to keep.

import { READ, WRITE, serveMcp, verifiedEmail, type Registry } from '@omazyai/sdk/server'
interface Env {
/** The bearer token Omazy sends. You choose it and give it to Omazy when you connect the server. */
MCP_TOKEN: string
}
type Ctx = { env: Env; email: string | null }
// Your own data. Replace with your database or API.
declare function findOrder(id: string): Promise<{ id: string; status: string; delivery: string; email: string } | null>
declare function moveDelivery(id: string, date: string): Promise<void>
const registry: Registry<Ctx> = {
info: { name: 'orders', title: 'Orders', version: '1.0.0' },
instructions: () => 'Look up an order by its number, and move its delivery date when the customer asks.',
tools: [
{
name: 'order_status',
title: 'Order status',
description: 'Where an order is and when it arrives.',
inputSchema: {
type: 'object',
properties: { order_id: { type: 'string', description: 'The order number, such as 48213' } },
required: ['order_id'],
},
annotations: READ,
},
{
name: 'change_delivery',
title: 'Change delivery date',
description: 'Move the delivery of an order to another date.',
inputSchema: {
type: 'object',
properties: {
order_id: { type: 'string' },
date: { type: 'string', description: 'YYYY-MM-DD' },
},
required: ['order_id', 'date'],
},
annotations: WRITE,
},
],
async call(name, args, ctx) {
const order = await findOrder(String(args.order_id ?? ''))
if (!order) return { text: 'No order with that number.', isError: true }
if (name === 'order_status') {
return {
text: `Order ${order.id} is ${order.status}. Delivery on ${order.delivery}.`,
structured: { id: order.id, status: order.status, delivery: order.delivery },
}
}
// A change only for the person the order belongs to.
if (!ctx.email || ctx.email !== order.email) {
return { text: 'Ask the customer to verify their email first.', isError: true }
}
await moveDelivery(order.id, String(args.date))
return { text: `Delivery moved to ${String(args.date)}.` }
},
}
export default {
fetch: (request: Request, env: Env) =>
serveMcp(request, env.MCP_TOKEN, registry, (req) => ({ env, email: verifiedEmail(req) })),
} satisfies ExportedHandler<Env>

What the pieces are for:

  • annotations. READ marks a tool that only reads. WRITE marks one that changes data, and DESTRUCTIVE one that removes it. Omazy reads these to decide whether a call needs the visitor to confirm on a card first. A tool with no annotations is treated as one that cannot be undone, so always set them.
  • structured. The same answer as an object, for a caller that reads fields rather than text.
  • isError: true. A refusal the model can read and explain. A tool that throws is turned into one of these too, never into a protocol error.
  • The bearer token. serveMcp answers /mcp only to a request carrying MCP_TOKEN, compared in constant time. /health is public. You choose the token and give it to Omazy when you connect the server.
  • verifiedEmail. When the server is connected with the identity policy below, Omazy sends the visitor’s email on calls from a conversation where the visitor proved it with an emailed code, and nothing otherwise. Trust it only because the request also carried your bearer token.

Deploy it like any Worker, with the token as a secret:

Terminal window
npx wrangler secret put MCP_TOKEN
npx wrangler deploy

A workspace owner can connect it in the console. From your backend, a token with the agent:tools scope connects it through the Core API:

import { Omazy } from '@omazyai/sdk'
const omazy = new Omazy({ token: process.env.OMAZY_CORE_TOKEN! })
// Needs the agent:tools scope.
const server = await omazy.agent.mcpServers.create(
{
name: 'orders',
endpoint_url: 'https://orders-mcp.example.workers.dev/mcp',
auth_type: 'bearer',
credentials: process.env.ORDERS_MCP_TOKEN!,
// A tool marked as a write asks the customer to confirm on a card first.
write_mode: 'confirm',
// Send the customer's verified email with each call from a session that passed the email code.
action_policy: { identity: 'verified_email' },
},
{ idempotencyKey: 'connect-orders-mcp' },
)
console.log(server.id, server.has_credentials)
// Later: only some tools, or a new token.
await omazy.agent.mcpServers.update(server.id, { allowed_tools: ['order_status'] })
await omazy.agent.mcpServers.update(server.id, { credentials: process.env.ORDERS_MCP_TOKEN_NEW! })
  • The endpoint must be https on a public host.
  • The credential is stored encrypted and never returned. has_credentials says one is stored. Sending a new one replaces it.
  • The name is unique in the app. The agent sees each tool as mcp_<name>__<tool>, from its next turn.
  • write_mode is confirm unless you say otherwise: a tool marked as a write runs only after the visitor agrees on a card. read_only allows only tools that read, trusted runs writes without a card, and open runs every allowed tool when the model calls it, as servers did before write modes existed.
  • Connecting takes an idempotency key, so a retry connects once.

For one workspace per customer, connect the same server to each customer’s agent with that customer’s token, and give each customer’s connection its own credential, so your server knows which customer is calling.

The agent:tools scope is not in a customer’s default install. See Many customers.

The SDK’s first product kits shipped in 0.5.0 as a preview:

Kit What it does
capabilities One definition of each action your product offers, from which the MCP tool, the model’s tool schema and your own API are made
guard Who may run an action, confirmations and approvals, kill switches, rate limits and a request log
mcp An MCP server per door built from the registry and the guard, on spec 2026-07-28 and the official MCP SDK
oauth The authorization server for your doors: consent, sign-in through your product, keys and connected apps. Six independent security reviews done; open a door only on its setup rules

serveMcp stays in @omazyai/sdk/server as it is, with no dependency, so a server written as on this page keeps working. New servers should start on the mcp kit, and the MCP kit reference has the steps to move one. What to do now:

  • Keep each tool’s definition in one place, as the registry object above does. Moving it into a capability later is then a move, not a rewrite.
  • Keep the decision about who may run a write in one function your tools call, not spread across them. It becomes the guard’s permission hook.

The capabilities kit and MCP kit references are up ahead of their release, marked experimental. The other kits come onto these pages as they are released. Watch the SDK releases for them.

Omazy CX documentation. One voice. Every channel. Always on.

Founded by Mosthofa Imran · imran@omazy.ai