Cookbooks

Govern: Protect a Tool from the CLI

Protect an MCP server tool with consent, watch an agent get refused, approve it and see the call go through, all from the kya-os CLI

Goal

Protect one tool on an MCP server you made with kya-os mcp create, and prove the protection works end to end without opening the dashboard. By the end you'll have:

  • a tool that refuses an agent until its user approves
  • a refused call and an approved call, both recorded by KYA
  • kya-os mcp status showing all 11 steps done

Best for: developers who built a server with kya-os mcp create and want to govern its tools from the terminal.

Prerequisites

  • The kya-os CLI, signed in (kya-os login)
  • A server from kya-os mcp create, with a key in its .dev.vars
  • A Cloudflare account, and npx wrangler login done once
  • To connect the server to consent, you must be the project's creator

Time Estimate

10 minutes, once the server is deployed


How protection works

Protection belongs to the project and goes by tool name. Protecting search protects every tool called search on every server in the project, and the CLI says so when another server has one. Use a project of its own for a server whose tools you protect differently.

A protected tool refuses an agent that has no consent, and the refusal names where the agent's user can approve. Where that is depends on how the project is set up: KYA's consent page, the project's verified authorization host domain, or the MCP server itself. The CLI follows the address the refusal names, so the steps below are the same in each case.

Step 1: Deploy the server and check it

In the server's folder:

npx wrangler secret bulk .dev.vars
npm run deploy
kya-os mcp status

mcp status lights each step only from evidence. Before you protect anything, these must be done: key valid, deployed, tools known and listed on Servers. If one isn't, the status line says why and what to run.

Step 2: Call a tool while it's open

kya-os mcp probe search --args '{"query":"test"}'

The probe calls the tool as a throwaway agent, with a new did:key each run. It prints the result, then waits up to 30 seconds and prints Checkpoint recorded the call.

Step 3: Protect it

kya-os mcp protect search

The first time, the CLI connects the server to the project's authorization host:

  1. KYA checks that the server controls its host, from the DID document it serves at https://<host>/.well-known/did.json.
  2. KYA issues the server's authorization values, once.
  3. The CLI writes them to .dev.vars and uploads them with npx wrangler secret bulk, the values on stdin.
  4. It calls the server so it registers with its new key, and waits for KYA to confirm.
  5. It revokes the key mcp create minted, which the new values replace.

Then it sets the protection and makes sure the server sees it before it finishes. After the first time, protect only sets the protection.

Step 4: See the refusal

kya-os mcp probe search --args '{"query":"test"}'

The call is refused, and the probe prints where an agent would send its user:

Refused, as it should be: search needs consent. An agent would send its user to <host>.
Checkpoint recorded the refusal.

If the call goes through instead, the probe exits 1 with Not protected: the call went through without consent.

kya-os mcp probe search --args '{"query":"test"}' --delegated

The probe opens the consent page the refusal names. Approve the request there. The probe picks up the credential, makes the call again with it, and prints Checkpoint recorded the delegated call.

On a machine without a browser, add --no-open and open the printed address yourself. The probe waits 600 seconds for the approval; --timeout changes that.

Step 6: Check every step

kya-os mcp status

When the refusal and the delegated call are recorded, the last line reads:

All 11 steps done: <name> is listed, protected, refuses calls without consent and serves calls with it.

The server's page under Servers in the dashboard shows the same steps.

Undo

kya-os mcp unprotect search

The tool is open again. The server stays connected to consent, so protecting a tool later is one command.

When something goes wrong

The CLI saysWhat to do
No tool named <x> on this server. Its tools: ...Use a name from the list. A tool is listed once the server has registered with it
Only the project's owner can connect this server to consentAsk the project's creator to run kya-os mcp protect once. After that, protecting tools doesn't need them
Checkpoint could not confirm this server controls <host>Deploy the server, check that https://<host>/.well-known/did.json serves its DID, then run kya-os mcp status
Checkpoint does not list this server yetDeploy it, send it any request, then run kya-os mcp status
Checkpoint has not seen the server use its new key yetSend the server a request, then run kya-os mcp status
Another project already holds <host>The host is registered to another project, and KYA does not move a host between projects. Use that project for this server
Checkpoint has no registered host for this server yetDeploy the server, then run kya-os mcp status
Checkpoint is already connecting this serverSomeone else is connecting it, from the CLI or the dashboard. Wait a few seconds and run the command again
Checkpoint asks for a pause between connections to consentConnecting again is allowed once a minute. Run the command again after a minute
Checkpoint's connection for this server changed while this ranRun the command again
This server is archived or suspendedOnly an active server can be connected. Check its state on the Servers page
Checkpoint has no verified record of this server's WorkerA deploy does not create this record; KYA writes it after checking the Worker with Cloudflare. Ask KYA support
This server is not connected to consent yetRun kya-os mcp protect <tool> first
Checkpoint has not recorded it yetThe call worked. Run kya-os mcp status again in a minute

See the CLI reference for every flag.