Skip to content

MCP

An app can serve an MCP endpoint: a person adds its address to an AI client that speaks MCP, such as a chat assistant or a code editor, signs in on the app and allows the client. The client then works with that person’s access: it lists the resources and fields they may read, finds records with the API’s filters, sorting and pages, and reads one record.

auth.mcp in protobase.config.ts turns it on:

export default defineConfig({ auth: { mcp: true } })

Every auth store has the OAuth tables, so turning it on needs no migration. The endpoint verifies its tokens with the app’s own sign-in, so an app whose authenticator is its own, auth/authenticate.ts, does not start with MCP on. The endpoint is https://<app>/api/mcp, or the path auth.mcp.path names. How clients register, how people sign in and allow them, and how they disconnect them is in OAuth for MCP clients.

Signed-in people find the endpoint’s address in the app: “Account” in the user menu, then Connected apps (/-/account/apps), shows it with a button that copies it and an “Add to Claude” link that opens Claude’s dialog for a custom connector with the app’s name and the address filled in. The tab shows only when MCP is on, and only on an account page that keeps the ConnectedApps block.

Give the client the endpoint’s address. It finds the app’s sign-in from there, opens it in the browser, and the person signs in and allows it on the app’s connect page.

  • A chat assistant usually takes a remote MCP server, or custom connector, in its settings: add one with the address.

  • A code editor or agent usually reads its MCP servers from a JSON file, in this shape or close to it:

    { "mcpServers": { "my-app": { "url": "https://my-app.example.com/api/mcp" } } }

    Some take the address on the command line instead, as a server with the HTTP transport, and sign in when you first use it.

The endpoint names the app’s icon to the client when it connects (serverInfo.icons), at absolute addresses on the app’s origin: the project’s 192 pixel, touch and 512 pixel PNGs it has, then its protobase.favicon.svg, or Protobase’s without one. A client that draws server icons shows it beside the app’s name. An app without PNGs of its own cannot offer clients that draw no SVG an icon because PNG versions of Protobase’s icon are not implemented.

Each tool reads as the signed-in person: their role’s access rules, row filters, tenant and hidden fields apply as in the REST API.

Tool What it does
list_resources The resources the person may read, kept small for a client’s first call: each one’s name, label, the first line of its help, key and whether it soft deletes (soft_delete), without its fields.
describe_resource One resource the person may read, with its fields: each field’s type, label, help, enum values, the resource a relation links to, and whether it is optional, read-only and taken by filters and sorts. linked_from names the relations of the other resources the person reads that point at this one. It also names the resource’s list_fields, what list_records returns when not told which.
list_records A page of a resource’s records: fields, filter in the API’s filter syntax, order_by, page_size (20 by default, at most 100) and page_token, with next_page_token for the next page and total_size_estimate, an estimate rather than an exact count. show_deleted: true also returns soft-deleted records.
count_records How many records a filter finds, without returning them: { count } as the API’s count=exact counts, or { more_than: 10000, estimate } when more match. With group_by, a filterable field, the count per value instead, as :aggregate gives it: { group_by, groups: [{ value, count }] }, largest first, adding up to what the filter finds, the first limit (100 by default, at most 1,000), with label naming a relation’s values by a field of the records they link to. A date or timestamp group_by counts per day over the last 30 days. show_deleted: true also counts soft-deleted records.
get_record One record by its key, with its ETag, holding the fields asked for or, without them, every field. A composite key is passed as the values of its fields, in order. show_deleted: true also finds a soft-deleted record.

show_deleted works as the REST API’s: it applies only to a resource with a soft delete, and is refused on any other. count_records cannot count soft-deleted records per value because :aggregate does not implement show_deleted. Soft-deleted records come under the same access rules, tenant and hidden fields as the rest, and carry the field their deletion set.

Records can hold long texts, such as a description or notes, and a page of them can run past what a client can take in. So list_records and get_record take fields, the field names to return, as an AIP-157 read mask does, with ["*"] for every field.

Without fields, list_records returns the record’s key and the columns of the resource’s table in the app: the list’s columns of the person’s view, or its first six fields when the view has no list. describe_resource names them as the resource’s list_fields, and the page names the fields it left out in omitted_fields. get_record returns every field unless told which.

The server tells each client this when it connects, in its instructions, and the tool descriptions repeat it: name the fields needed, filter on the fields marked filterable, which are indexed, rather than paging through records to search them, and keep pages small. For example, the open tasks, newest first, ten at a time, then the brief of one of them:

{ "resource": "tasks", "fields": ["id", "status", "title"], "filter": "status = \"open\"", "order_by": "created_at desc", "page_size": 10 }
{ "resource": "tasks", "key": "42", "fields": ["brief"] }

To find records through related ones, a client filters with related() in one call instead of reading the keys first and sending them back:

{ "resource": "task_claims", "filter": "related(task_id, objective_tasks.task_id, (objective_id = 40))" }

For the records of one record it passes belongs_to, as the list under a record does, with filter beside it:

{ "resource": "tasks", "belongs_to": { "resource": "objectives", "key": 40 }, "filter": "state != \"done\"" }

A refusal, such as a resource the person may not read, a bad filter or a field the person may not read, comes back to the client as text it can act on, { "error": ..., "message": ... }.

When a resource takes comments, the endpoint also offers list_comments, and with writes on, add_comment. They go through the same service as the REST API’s comments, as the person: whoever may read a record may read its comments and add one, and everyone else gets the same refusal as from GET or POST /api/v1/{resource}/{key}:comments. An app without a resource with comments offers neither.

Tool What it does
list_comments A page of a record’s comments, newest first, each as { author, created_at, text }, the author’s name beside their id when the app’s auth knows it. page_size (20 by default, at most 100) and page_token, with next_page_token for the next page.
add_comment Adds text as the person’s comment on one record, and returns it as list_comments gives it.

add_comment is a write: the person approves each comment first, seeing the record’s name and the whole comment, unless they hold one of the roles without approval. With writes limited to some resources, it comments only on those. A comment it adds mentions nobody, so it sends no emails. An empty comment, one over 10,000 characters, a resource without comments, and a record the person may not read, or one that is soft-deleted, are refused before asking.

In an app with workflows, the endpoint also offers tools to find, make, change and test-run them, and its instructions describe the workflow language: the document, the states, reading values by name, errors and retries, with an example. A client can write a working workflow from them and the tools alone, without the docs. Each tool goes through the workflow resources as the person, so their grants and tenant apply: someone without them is answered as for a resource that is not there, and nothing changes.

Tool What it does
list_workflow_types The step types a Task names as its Resource and the triggers a definition holds, built-in and plugin ones alike, with the custom steps of the person’s tenant, each by id with its label, description, input as JSON Schema and, when the type declares one, its output, the errors a step fails with, and whether the app can run it. Each custom step version also says how its image’s build stands on the app’s runners, build: ready once one built it, building, or failed on each that tried; none before a build began.
list_workflows A page of the workflows the person may read, newest change first, without their definitions: filter on name, page_size (20 by default, at most 100) and page_token.
get_workflow One workflow with its whole definition, its layout, the nodes moved by hand in each view, and its ETag.
validate_workflow Checks a state_machine, with its trigger and execution_order, or a workflow’s id with an edit of its saved definition, as a save checks it, and saves nothing: { valid: true }, or { valid: false, problems }. A valid one may come with warnings in the same shape, which a save goes through with, such as a Wait after a Block; create_workflow and update_workflow return them with what they saved. A record trigger is checked against the resources and fields the person may read, so a resource they cannot read is not a resource of the app.
get_workflow_run A run’s status, input, output, error and cause, with its steps in the order they ran, each with its state, scope, try, status, input, output, assigned variables, logs, error and cause; state reads one state’s steps, a page of 20 by default.
list_connections The person’s own connected accounts, by each connection the app’s plugins declare: its key and label, and each account’s id, scopes and needs_sign_in. A definition’s connections binds an account by its id. It returns no token, and no one else’s accounts.
create_workflow Creates a workflow from its name, description and state_machine, with its trigger, execution_order and layout, none by default, and returns its id, version and ETag. With publish: true it publishes version 1 in the same save and answers enabled_version, and for a webhook trigger also issues its URL, keeping a webhook_secret the sender makes, and answers webhook: { url, secret }, shown this once. A state machine from Step Functions imports its HTTP tasks as app:http steps, with connection_headers naming each connection’s header; update_workflow and validate_workflow import one the same way.
update_workflow Changes a workflow’s definition by an edit or whole, as state_machine, trigger and execution_order, and its name, description or layout, written whole, and returns its id, new version and ETag; a change of the layout alone keeps the version. With the etag that get_workflow gave, it fails when someone changed the workflow since; an edit without one is saved against the version it was applied to.
run_workflow Starts a run of a workflow’s version saved last, or of the version it names, with an input, and returns its run_id and status. With rerun_of, a failed run’s id, it re-runs that run from its last checkpoint instead, on its input, and with rerun_from any ended run that kept its trace from that state; with replay: true too, it replays any ended run of the workflow on its current version, with that run’s input, sending none of its outside writes.
enable_workflow Publishes the saved version it names (enabled: true), which puts the workflow’s trigger on it, or turns the workflow off, and returns its enabled_version. A save never goes live by itself. One that uses a connected account is turned on only by the account’s owner in the admin app: the tool answers own-sign-in-only and says so.
new_webhook_url Issues a new URL and secret for a workflow that starts from a webhook trigger, keeping a secret the sender makes when given one, and returns { url, secret }, shown this once; the old URL stops.
send_task_success, send_task_failure, send_task_heartbeat Answer a Task that waits for an outside result with the task_token it handed off: its result, output, a string of JSON; its failure, error and cause; or a heartbeat. Each returns { run }, or { error, message } with the error Step Functions gives, such as TaskTimedOut. Only a caller who may read the run can answer it; to anyone else the token is unknown.

With custom steps on, the endpoint also offers the tools that make, build, test and run them, and its instructions describe a step’s manifest and what its container gets and gives:

Tool What it does
get_custom_step A custom step by its name: its manifest as saved last, the version that is, its ETag, and its latest 20 versions, or only version, newest first, each with its step type (custom:<name>:<version>), who saved it and when, and its builds, one per runner: the runner’s id, status, the image’s digest, how long it took in seconds and the last 30 lines of its log, log_tail.
list_runners The runners the person may read, each with its id, name, whether it is online (holding a claim for work now, or running a job), revoked and registered, its labels, platform, the kinds of work it does, its free_slots and the custom step versions whose images it holds, as it said with its last claim, and when that was, polled_at.
save_custom_step Creates a custom step from its name and manifest, label, description, container, input, output, error_prefix and errors; or, with the id of one, changes the fields given, which saves its next version when the manifest changed. With the etag that get_custom_step gave, it fails when someone changed the step since. It returns { id, name, version, build }, build the image’s first build of that version: { status, runner, digest, seconds, log_tail }, status building, ready, failed, or no_runner when no runner that builds images is online. With wait_seconds, at most 120, it waits that long for the build to end. A manifest the save check refuses comes back as { "error": "invalid-custom-step", "message", "problems" }, each problem { field, message }, such as container.dockerfile; nothing is saved.
test_custom_step Runs one job of a custom step version, name and version, on an input, its arguments, with a store for the files it gives, without a workflow: a custom step test. It returns { run_id, job_id, status, output, error, cause, log_tail, seconds }: status queued, running, succeeded with its output, or failed or timed_out with its error and cause, the last 30 lines its container wrote and how long the job took from queued to done. With wait_seconds, at most 120, it waits that long for the job to end; get_workflow_run reads its run after.
create_runner_token Makes a runner from its name and labels, and returns { id, name, labels, command, expires_at, endpoint }: the one command that installs the runner on a Linux machine with a one-time token, shown this once, valid an hour. The client gives it to the person to run on the machine. It needs both workflow_runners.create and workflow_runners.update, as issuing a runner’s token is a change to it; without update nothing is made.

save_custom_step, test_custom_step and create_runner_token come with writes, on workflow_custom_steps, workflow_runs and workflow_runners when writes name their resources, and the person approves each first: the save as any create or update of a record, the test showing its arguments, the runner saying the command it gives registers a machine. Each tool reads and writes the records as the person, so the grants of custom steps, their versions, builds and jobs, runs and runners apply: a test needs the right to start runs and to read jobs, a runner the right to make and change runners.

An edit is a JSON Merge Patch of the saved definition: only what changes, at its place in the document. An object merges into the object there, null removes a member, and any other value, a list included, replaces it. Changing one argument of one state:

{ "id": "...", "edit": { "stateMachine": { "States": { "Notify": { "Arguments": { "url": "https://hooks.example.com/v2" } } } } } }

A definition the save check refuses comes back as { "error": "invalid-workflow", "message": ..., "problems": [...] }, each problem { state, field, message } naming the state, the field and what was expected, as validate_workflow gives them; nothing is saved. A run goes on in the background on the app’s jobs, so run_workflow returns while it is queued: the client reads it with get_workflow_run until it has succeeded or failed, fixes the step that failed and re-runs the run from that step.

create_workflow, update_workflow, run_workflow, enable_workflow, new_webhook_url and the send_task_* answers come with writes, and the person approves each first, as any write, unless they hold one of the roles without approval; with writes limited to some resources, they save, turn on and issue URLs on workflows and run on workflow_runs only when the list names them. A run does what its steps do, such as requests, mail and record writes, as the workflow’s last editor.

mcpEndpoint.sql also offers run_read_only_query, as in the assistant, to people with the admin or ai role:

export default defineConfig({ auth: { mcp: true }, mcpEndpoint: { sql: true } })

It runs one SELECT in a read-only transaction, as the app’s database role, outside the access rules and tenant scoping: whoever has one of those roles reads the whole database through it. Give those roles only to people who may see all of the data.

mcpEndpoint.writes also offers four tools that change records, to everyone signed in:

export default defineConfig({ auth: { mcp: true }, mcpEndpoint: { writes: true } })
Tool What it does
create_record Creates a record of a resource from data, field names to values, and returns its key and ETag with the fields it wrote, see What a write returns.
update_record Changes the fields in data of one record by its key, and returns its key and new ETag with the fields it set. With the etag that get_record gave, it fails when someone changed the record since. It does not set the field a soft delete sets: a delete goes through delete_record.
delete_record Deletes one record by its key. With the etag that get_record gave, it fails when someone changed the record since; without one, or with *, it deletes the record whatever its version. A resource with a soft delete keeps the record, deleted; any other loses it for good.
batch_write Creates, updates and deletes records across resources in one transaction, see Batch writes.

Each write goes through the REST API as the person: their role’s access rules, validate, write hooks, events and webhooks apply, so the client can do only what the person may do in the app.

Before each write the client asks the person to approve it, through MCP’s form elicitation. The approval names the record by the resource’s label, its key and its title, such as Update Task #42 "Fix the sign-in lockout"?. An update lists each field it changes by its label, with its value before and after (Status: In flight -> Done); a create lists the new record’s fields by their labels; a delete says whether the record can be restored, and for a resource without a soft delete says plainly that it cannot be undone. Enum values show by their labels, a sensitive field’s value is hidden, and a value is cut at 200 characters. A record or field the person may not read is named by its key or its name in words, and an update or delete of a record changed since its etag is refused before asking. The approval, its button and the refusal for a client that cannot ask are in the person’s language: the app’s locale, or else the one the client’s request accepts (Accept-Language). Nothing is written until they approve, and declining writes nothing. A client’s own setting that always allows a tool is not this approval. An approval holds only for the call it was asked for, with the same arguments, by the same person in the same app, organization and client, and only once, within 10 minutes; any other call is asked again. A client that cannot ask, one without form elicitation or one on the 2025 protocol, gets each write refused with a message saying so.

An approval cannot be answered on another server instance or after a restart because a shared approval store is not implemented. Behind a load balancer, send an MCP client’s calls to the same instance.

To offer the writes on some resources only, list them:

mcpEndpoint: { writes: { resources: ['tasks'] } }

The write tools then name those resources in their descriptions, and refuse a write to any other before asking, with { "error": "forbidden", "message": ... } saying which resources they write; nothing is written. A name the app has no resource for stops the server at startup. The list only narrows the writes: the person’s access rules still apply on the listed resources.

A write returns its record small, so changing one field of a large record does not send the whole record back:

{ "key": 42, "etag": "\"7\"", "record": { "status": "done", "updated_at": "2026-10-27T09:00:00Z" } }

key is the record’s key as the tools take it, the values of its key fields in order when it has several; etag is its new ETag, for a later write. record holds the fields the write set, as stored, and the read-only fields that changed with it, such as a formula, a rollup or an update time; a create counts every read-only field that has a value. A fields argument, a list of field names, adds those fields, and ["*"] returns the whole record. A field the person may not read stays out, and for a resource they may not read at all the key and the read-only fields stay out too.

An app that runs service accounts over MCP, such as a backend job or an agent with no person present, names their roles in mcpEndpoint.writes:

mcpEndpoint: { writes: { resources: ['tasks'], rolesWithoutApproval: ['service'] } }

A user with one of those roles creates, updates and deletes records over MCP without the approval step: the client is never asked, so a client that cannot ask writes too. Their role’s access rules and the listed resources still limit every write as before, so a job with no person present can keep the app’s data over MCP and do nothing there it could not do through the REST API. Everyone else is still asked before each write. Taking the role away, banning or deleting the account stops its tokens at their next request, not when they expire.

No role is exempt unless named. The roles are checked against the signed-in user, not against the client, and a user holding several is exempt when any of them is named. A name that is not one of the app’s roles, or is anonymous, stops the server at startup. Naming a role a person signs in with lets any client that person allows write as them unasked.

A deleted record cannot be restored over MCP. There is no SQL that writes.

batch_write takes a list of creates, updates and deletes, each naming its resource, with the key and ETag for an update or delete, and runs them in order in one transaction, as the REST API’s batch writes do: either all of them are written or none, and a record changed since its ETag fails the whole batch.

{ "operations": [
{ "op": "create", "resource": "tasks", "data": { "title": "Plan the release" }, "ref": "task" },
{ "op": "create", "resource": "task_links", "data": { "task_id": { "$ref": "task" }, "url": "https://example.com" } },
{ "op": "update", "resource": "tasks", "key": 12, "etag": "\"3\"", "data": { "status": "done" } },
{ "op": "delete", "resource": "task_links", "key": 40, "etag": "\"1\"" }
] }

An update needs the etag the record was read with, or "*" for any version; a delete’s etag is optional, and without one it deletes any version. A create may name itself with ref, and a later operation’s key or data value { "$ref": "<name>" } is that record’s key. The result is { "results": [...] }, one per operation in order: a create or an update gives its op, resource, a create’s ref, and its record as a write returns it, with an operation’s own fields for more, and a delete { "op": "delete", "resource": ..., "deleted": true }. The read-only fields an update changed are told against the record as read just before the batch runs; an update of a record created in the same batch, by $ref, counts every read-only field that has a value.

The person approves the batch once, in their language, seeing each write in it named and listed as the approval of a single write names and lists it: 2. Update Task #42 "Fix the sign-in lockout" with each field it changes, a create with the new record’s fields, and a delete saying whether it can be restored. A key or value pointing at a create in the batch is named by that write’s number, such as the Task from write 1. The first 50 writes are listed and the rest counted. The approval says plainly how many deletes in it cannot be undone, which is every delete on a resource that does not soft delete, and an update or delete among the listed writes of a record changed since its etag is refused before asking.

A batch is checked before the person is asked: an operation other than a create, update or delete, a field an operation does not take, an update without an ETag or more than 500 operations come back as { "error": "invalid-argument", "message": ... } naming the operation, and with writes limited to some resources an operation on any other refuses the whole batch. An update does not set the field a soft delete sets, as update_record does not: a delete goes through a delete operation. A refusal while it runs, such as an operation the person may not do or a stale ETag, comes back with the REST batch’s operation (its index), op and resource. Either way nothing is written.

mcpEndpoint.instructions adds the app’s own text to what the endpoint tells each client when it connects, its instructions, such as how the app’s records fit together or what to ask the person before changing something:

export default defineConfig({
auth: { mcp: true },
mcpEndpoint: { instructions: 'A big ask becomes a research task first: ask the person its open questions, and build only once they approve its plan.' },
})

The client reads the framework’s text on reading records first, then the app’s, then, in an app with workflows, the workflow guide. Some MCP clients keep only the first 4,096 characters of a server’s instructions, so the framework’s text and the app’s together stay within 4,096: the app has 2,691 characters, and a longer text stops startup with an error naming mcpEndpoint.instructions. The workflow guide that follows is longer than that alone, so such a client cuts it. A client that keeps only 4,096 characters cannot read the whole workflow guide because a shorter guide is not implemented. The text is the same for every client and every connection, which lets clients cache it: what changes, such as the records themselves, reaches the client through the tools.

mcp/tools.ts adds tools of the app’s own, offered after the built-in ones to everyone signed in, whatever mcpEndpoint.writes says. Its default export is an array of defineTool(...) from @protobase/server, the same shape as the assistant’s own tools: a name of 1 to 64 letters, digits, _ or -, a description the client’s model reads, parameters, the JSON Schema of its arguments, which the endpoint checks each call against, annotations, MCP’s tool hints such as readOnlyHint, optionally a title and _meta, which tools/list gives clients as they are, and run(args, context), which returns the text the client reads. The file is found when the app starts, under protobase dev and protobase serve alike, and only with auth.mcp on; with mcpEndpoint: false it offers nothing.

context holds the caller’s session, the locale they read, approve(request), resources(), the resources they may read, and records, the app’s records as that person: their role’s access rules, tenant, hidden fields, validate and write hooks apply, as in the REST API and the built-in tools. Its methods are the assistant’s, listed there; a refusal rejects with an HttpProblem. show does nothing over MCP, and there is no conversation.

A tool refuses by throwing an HttpProblem with a status below 500, such as notFound(detail) or forbidden(slug, detail), or by letting through the one records rejects with: the client gets { "error": <slug>, "message": <detail> } as an error result, as from the built-in tools, and nothing is reported. A write the database refuses as read-only while the app is being updated reaches the client as “The server failed to answer.” and is not reported. Anything else a tool throws is reported to the app’s error handler and reaches the client as “The server failed to answer.”, or, for a query the database stopped at its statement timeout, as { "error": "statement-timeout", "message": <a sentence naming the tool> }. refusalOf(error) from @protobase/server gives that { error, message } text for a refusal and undefined otherwise, and refused(error) gives it or throws the error again, for a tool that returns a refusal as its result rather than as an error.

Nothing cuts a tool’s result, as nothing cuts the built-in tools’: a tool that can return a lot takes a limit or the fields to return, as list_records takes page_size and fields. A tool result larger than an AI client takes cannot be refused with a message naming what to leave out because a size guard is not implemented.

A tool that reads:

mcp/tools.ts
import { defineTool } from '@protobase/server'
const openTasks = defineTool({
name: 'open_tasks',
description: "The person's open tasks, newest first: id, title and due date.",
parameters: { type: 'object', properties: { limit: { type: 'integer', minimum: 1, maximum: 50 } } },
annotations: { readOnlyHint: true },
run: async (args, { records }) => {
const page = await records.list('tasks', { filter: 'status = "open"', order_by: 'created_at desc', page_size: Number(args.limit ?? 10), fields: ['id', 'title', 'due_on'] })
return JSON.stringify(page)
},
})

A tool that changes data asks first, through approve, before it changes anything:

const closeTask = defineTool({
name: 'close_task',
description: 'Marks one task done.',
parameters: { type: 'object', properties: { id: { type: 'integer' } }, required: ['id'] },
annotations: { readOnlyHint: false },
run: async (args, { approve, records }) => {
const { record, etag } = await records.get('tasks', Number(args.id))
const answer = await approve({ title: `Close task #${args.id} "${record.title}"?`, fields: [{ label: 'Status', value: 'Done' }], approveLabel: 'Close' })
if (answer !== 'approved') return JSON.stringify({ closed: false })
await records.update('tasks', Number(args.id), { status: 'done' }, { etag })
return JSON.stringify({ closed: true })
},
})
export default [openTasks, closeTask]

approve asks the person through MCP’s form elicitation, as the built-in writes do: the client calls the tool again from the start with their answer, so everything before approve runs twice and must change nothing. It resolves with 'approved' only when they approve; declining resolves otherwise, and a client that cannot ask gets the call refused with a message saying so, before anything after approve runs. An approval holds once, for the same call with the same arguments, by the same person in the same app, organization and client. A user holding one of rolesWithoutApproval is approved at once, for these tools too. A tool that never calls approve writes unasked: whatever it does through records, the person’s access rules still limit, but nobody is asked first.

With extensions, each folder’s mcp/tools.ts adds its tools, the extensions’ first, in order, then the app’s. A name two of them use, or one of the built-in tools’ names, such as get_record or create_record, even one the config leaves off, stops the server at startup, naming it.

assistant/tools.ts stays the dock’s: it offers nothing over MCP, since the dock serves only the admin and ai roles while MCP serves everyone signed in. To offer the dock’s tools over MCP too, on purpose, export them from mcp/tools.ts as well:

mcp/tools.ts
import assistantTools from '../assistant/tools'
export default [...assistantTools]

A host calling createAdmin itself passes the tools as options.mcp.tools; the JSON config’s mcpEndpoint takes none.

A client in a browser may call the endpoint from any origin: it sends its token, never cookies. A request addressed to another host than that of the app’s url is refused, against DNS rebinding.

The endpoint serves each request on its own, without an MCP session: a GET or DELETE answers 405.

@protobase/server exports the pieces the endpoint is made of, for an MCP server of your own with tools of your own:

  • mcpHandler({ authenticate, resource, scope, server }): the endpoint as a fetch handler. It checks the host, admits a valid token (mcpGate) and serves the request with the server that server(session, request) builds for its caller; request is the HTTP request, such as for the language the person reads.
  • mcpServer({ info, instructions, tools, context, report, rolesWithoutApproval, approvals }): an MCP server named by info, its name, version and icons, such as mcpIcons(origin, icons), the app’s icons on origin, and offering assistant tools, each with its JSON Schema, its annotations, MCP’s tool hints, and its title and _meta, and each refusing as the app’s own tools do. context is the tools’ context without approve, with the locale its approvals are asked in (English when absent): each call gets its own, which asks the client’s user, or approves at once when the session’s user holds one of rolesWithoutApproval. It is a ToolContext, with the app’s records, resources() and show, unless every tool is declared with a smaller one, such as defineTool<BaseToolContext>(...), whose context is only session, locale and approve: a host without app records then passes { session }. report gets what a tool throws other than a refusal or a read-only database’s error. approvals is mcpApprovals(), built once and passed to every server the endpoint builds: it keeps the approvals asked for until they are answered or expire. instructions is what it tells clients when they connect, by default mcpInstructions, the advice on reading records above.
  • mcpTools({ db, sql, writes, commented, workflows, own }): the endpoint’s tools for a session; writes is true, false or { resources, rolesWithoutApproval }, commented names the resources with comments, workflows offers the workflow tools with the app’s types, and own are the app’s own tools, offered after the rest.
  • workflowTypes(plugins, models): the app’s workflow types, a WorkflowCatalog, which workflows and workflowReadTools take. plugins are the app’s own workflow plugins, each { plugin, source }, beside the built-in ones, and models(name) gives the model of the app’s resource of that name, which a record trigger is checked against. An app with workflows needs none of this: its endpoint offers the tools with the app’s types; these are for an MCP server of your own.
  • workflowReadTools(catalog) and workflowWriteTools({ resources }): the workflow tools alone, and workflowInstructions, what the endpoint tells clients about the language, to append to mcpInstructions.
  • readRecordTools(), or listResourcesTool(), describeResourceTool(), listRecordsTool() and getRecordTool(): the read tools alone; readOnlyQueryTool(db) is run_read_only_query, and readWriteQueryTool(db) proposes one write statement that the user approves before it runs.
  • commentTools({ commented }, writes), or listCommentsTool({ commented }) and addCommentTool({ commented, resources }): the comment tools on the resources named in commented, which call the context’s comments, and add_comment only when writes is not false.
  • writeRecordTools({ resources }), or createRecordTool(...), updateRecordTool(...) and deleteRecordTool(...): the single write tools alone, on the listed resources or, without resources, on any; batchWriteTool({ resources }) is batch_write alone.
  • mcpGate({ authenticate, resource, scope }): the token check alone, answering 401 or 403 with a challenge that names the resource’s metadata.
  • mcpToolContext(...), with the records’ comments as comments, mcpRoutes(app, { path, handler }) and sessionOf(authInfo): the tools’ context as the app builds it, the routes with open CORS, and the session a request was admitted with.

A host that builds its own server around createAdmin, rather than running the project with protobase dev or protobase serve, can serve its own endpoint at auth.mcp.path instead: mcpEndpoint: false (createAdmin’s options.mcp) turns Protobase’s off, and the host mounts its own in front of createAdmin’s app. The OAuth provider and its discovery stay, and createAdmin answers 404 at the path and under it. protobase dev and protobase serve have no place to mount another endpoint, so in a project served by them mcpEndpoint: false only turns the endpoint off.

A tool of your own goes on the server server returns, with the context its tools get. authenticate is the host’s own Authenticator, such as jwtAuthenticator(...): it verifies the client’s access token for the endpoint’s address, its audience, and returns a session with the client the token was issued to. A host with no app records, such as a console that reads its own database, declares its tools with BaseToolContext and passes { session }; here a tool with a title and _meta, which refuses another person’s project and asks before it archives one:

mcp-endpoint.ts
import { defineTool, mcpApprovals, mcpHandler, mcpServer, notFound, type Authenticator, type BaseToolContext } from '@protobase/server'
// The host's own data: here a map, in a real host its own database or API.
const projects = new Map([[1, { id: 1, name: 'Website', owner: 'ann', archived: false }]])
// Shown to clients that read `securitySchemes`: each tool needs the person's sign-in.
const signedIn = { securitySchemes: [{ type: 'oauth2', scopes: ['mcp'] }] }
const ownProject = (id: unknown, userId: string | number) => {
const project = projects.get(Number(id))
if (!project || project.owner !== userId) throw notFound(`No project ${String(id)}`)
return project
}
export const archiveProject = defineTool<BaseToolContext>({
name: 'archive_project',
title: 'Archive a project',
description: 'Archives one of the person\'s projects.',
parameters: { type: 'object', properties: { id: { type: 'integer' } }, required: ['id'] },
annotations: { readOnlyHint: false, destructiveHint: false },
_meta: signedIn,
run: async (args, { session, approve }) => {
const project = ownProject(args.id, session.user.id)
const answer = await approve({ title: `Archive project "${project.name}"?`, approveLabel: 'Archive' })
if (answer !== 'approved') return JSON.stringify({ archived: false })
project.archived = true
return JSON.stringify({ archived: true })
},
})
const approvals = mcpApprovals()
/** The host's MCP endpoint, admitting the tokens `authenticate`, the host's own `Authenticator`, verifies. */
export const projectsEndpoint = (authenticate: Authenticator) =>
mcpHandler({
authenticate,
resource: 'https://console.example.com/api/mcp',
scope: 'mcp',
server: (session) => mcpServer({ info: { name: 'Console', version: '1.0.0' }, tools: [archiveProject], context: { session }, report: console.error, approvals }),
})

A host that wants the person’s records in the app instead serves the app’s endpoint and passes its tools as options.mcp.tools on createAdmin, as in the app’s own tools.

A tool that changes something calls context.approve(...) before it changes anything, and only once: over MCP the client asks the person, then calls the tool again from the start with their answer, and approve then resolves with it.

mcpServer returns the SDK’s McpServer, so registerTool on it adds a tool written against the SDK directly.