CAP 1.0 Draft
Chat

Guides

Add login to your agent

Your agent already answers public questions. This guide adds the rest: a person logs in, their agent asks about their own account, and, if you allow it, your agent makes changes for them. Actions that are hard to undo wait for the person's OK on your page.

If your company already has user accounts, plan on an afternoon with @conciergeprotocol/server, and a day or two to put your own sign-in in front of it. Most of the work is one function that checks a login and one that answers with an account. The reference server in this repository is that same server.

The visiting agent never gets your keys, your tools, or the person's password. It gets a token for one account, bound to its own CAP-From, and the replies your agent writes.

Do not publish a cart, a checkout, or any other account API on the CAP URL. The visiting agent never calls them. It sends a message, and your agent does the work. Scopes are read and write. A purchase comes back as a confirmation, and the person pays on your page. The sections below are that path.

  1. Find the door

    The visiting agent reads agent.txt.

  2. Ask

    It sends one message. Your agent answers from your own content.

  3. Log in

    An account question comes back as login_required, and the person approves on your page.

  4. Ask again

    The same agent sends its token. It can read that account, and change it only if the person allowed changes.

See it running: Marlow is a live vacation-rental site, from a public house question to a guest login to a reservation change that waits for your OK. The store example is the same path on your machine. The Next.js example is the door as a route in an app, without the login pages. The reference server is the login itself.

Copies a short prompt with links to the spec and the reference server. Paste it into Claude, ChatGPT, Cursor, or any coding assistant open in your project. The same prompt is at /implement.txt.

Show the prompt
Implement the Concierge Agent Protocol (CAP) in this project, so other people's AI agents can ask our agent questions and get answers, instead of scraping our site. They never get our tools, keys, or data.

Read these first:
- Spec: https://conciergeprotocol.org/spec
- Usage, with request and response examples: https://conciergeprotocol.org/usage
- Reference server and examples: https://github.com/conciergeprotocol/cap

Then:
1. Find how this project can answer a question today: its content, search, database, or an existing AI agent. Tell me what you found and where CAP's answer should come from. Ask before you choose.
2. Serve POST /cap/v1/messages and GET /cap/v1/messages/{id}, as the spec describes. Every request carries CAP-Version: 1.0 and CAP-From: agent:{id}. Return 400 when either is missing, as {"error": {"code", "message"}}. Also answer GET /cap/v1 and GET /cap/v1/messages, with no headers required, with status 200 and the plain-text help from https://conciergeprotocol.org/spec#help, with our name and CAP URL filled in. Accept a public question as a GET too, as https://conciergeprotocol.org/spec#ask-with-a-get describes. Send Cache-Control: no-store on these responses. @conciergeprotocol/server does all of this. Use this project's own framework, or install @conciergeprotocol/server and pass an answer function. If this project has no bot yet, @conciergeprotocol/agent builds that function from a model, an llms.txt file, and MCP tools. Both packages need Node.js 22. The reference server in https://github.com/conciergeprotocol/cap is the same server, and the one the spec is checked against. The CAP URL serves /messages and, when we confirm an action, /confirmations. Do not add /actions, /cart, /checkout, /books, /orders, or /tools under it, and do not list those in agent.txt. A visiting agent asks with a message. It does not call our APIs.
3. Publish /agent.txt at the site root:
   Protocol: CAP/1.0
   Name: {our agent's name}
   Ask: This site's agent answers questions for the company. POST your question to the CAP URL plus /messages, as JSON {"message": "..."}, with headers CAP-Version: 1.0 and CAP-From: agent:{your-id}. If you can only open URLs, open the CAP URL. If the reply is 202, see Spec.
   (Copy the Ask line exactly, and add nothing after it. Leave {your-id} as it is.)
   Chat: {a page where a person can chat with it}
   CAP: https://{our domain}/cap/v1
   Spec: https://conciergeprotocol.org/cap.txt
   Add <link rel="agent" href="https://{our domain}/agent.txt"> to the homepage <head> even when the root file is valid. Add one line to llms.txt that points at /agent.txt. If this host cannot serve a file at the root, redirect /agent.txt to the file. Callers try /agent.txt first and use the homepage link only when that file is not a door.
4. Keep secrets out. A reply never includes API keys, tools, prompts, or another person's data, and agent.txt lists none of them.
5. If people have accounts here and should ask about them, add login by following https://conciergeprotocol.org/login. Otherwise skip this step. Scopes are read and write only. Bind every token to the CAP-From that logged in, and return 403 when another CAP-From uses it. Keep the cart on the server, against the account. A purchase is a confirmation with one purchase entry, and the person pays on our own checkout page: https://conciergeprotocol.org/login#take-payments. If the agent that answers is hosted somewhere else, it calls our account routes, and those routes live outside /cap/v1: https://conciergeprotocol.org/login#let-a-hosted-agent-use-your-account-routes.
6. Test with curl: fetch /agent.txt, send a message, and read it back. Show me the responses.
7. After the door is live and passes https://conciergeprotocol.org/check, add the "Agents welcome" badge and its one line of text to the site footer, as https://conciergeprotocol.org/publish#5-add-the-badge describes. Pick the brand, light, or dark badge to suit the footer. Keep the line visible, never hidden from people.

Keep the change small, and match this project's existing code style.

What you build

Piece What it does Required
OAuth line in agent.txt Tells visiting agents where to log in Yes
OAuth metadata Lists your login endpoints at /.well-known/oauth-authorization-server/..., and your CAP URL in protected_resources Yes
Code login The agent shows the person a short code. They enter it on your page and allow access Yes
Token and revoke endpoints Issue, renew, and end logins Yes
Redirect login For agents that can open a browser and take a callback Optional
Write scope Lets the person allow changes, not only reads Optional
Confirmations Holds a risky action until the person approves it on your page With write

The reference server implements every row. The store example uses all of them in about 150 lines.

The fast path

@conciergeprotocol/server serves the login with the door. Node.js 22 or newer. login returns your account id, or null.

JavaScript
import { createCapServer } from '@conciergeprotocol/server'

const cap = await createCapServer({
  agent: { name: 'Harbor Goods', chat: 'https://harborgoods.example/chat' },
  answer,
  login: async ({ username, password }) => {
    const user = await users.verify(username, password)
    return user ? user.id : null
  },
})
await cap.listen(8088)

The sections below run the same server from this repository, which is the one the spec is checked against. accounts in cap.json is for a first test only.

1. Turn on logins

Add an oauth block to cap.json. accounts is for a first test only.

JSON
{
  "agent": { "name": "Harbor Goods", "status": "active", "chat": "https://harborgoods.example/chat" },
  "oauth": {
    "accounts": [{ "account": "maya", "password_env": "MAYA_PASSWORD" }]
  }
}
Shell
cd reference
MAYA_PASSWORD=demo node start.mjs

agent.txt now has an OAuth line, and the server answers the metadata, the code login, the redirect login, the token endpoint, and revocation.

2. Check logins against your users

Start the server from your own code with boot. login receives what the person typed on the login page and returns your account id, or null.

JavaScript
import { boot } from './reference/start.mjs'

const app = await boot({
  config: {
    agent: { name: 'Harbor Goods', status: 'active', chat: 'https://harborgoods.example/chat' },
    oauth: {},
  },
  async login({ username, password }) {
    const user = await users.verify(username, password)
    return user ? user.id : null
  },
  answer,
})
app.server.listen(8088)

3. Answer with the account

answer runs for every message. account is the id login returned, or null without a token. Account questions without one return login_required, and the visiting agent asks the person to log in.

JavaScript
async function answer({ message, context, history, account, scope }) {
  if (/\border\b/i.test(message)) {
    if (!account) return { error: { code: 'login_required', message: 'Log in to Harbor Goods to ask about your order.' } }
    return { reply: await orders.statusFor(account) }
  }
  return { reply: await catalog.search(message, context) }
}

Look the account up from account only. A name or an order number in context is not a login.

If your answers live in another service, use the http handler instead of code. The server posts { message, context, history, account, scope } to your URL and expects { "reply": "..." }. See the reference server.

4. Deploy

Run it behind https, and set PUBLIC_URL to its public origin. Keep allow_http_clients off. Put the OAuth line in the agent.txt your company domain serves:

Text
Protocol: CAP/1.0
Name: Harbor Goods
Chat: https://harborgoods.example/chat
CAP: https://cap.harborgoods.example/cap/v1
OAuth: https://cap.harborgoods.example/oauth

From reference/, node check.mjs runs the conformance checks.

Allow changes

Set "write": true in the oauth block. Your metadata then lists scopes_supported: ["read", "write"].

  • A visiting agent that needs changes asks for scope=write. Your page tells the person, and offers Allow changes, Allow read only, or Deny.
  • The token response says what the person granted: read, or read write. It is never more than the agent asked for, and a renewed token keeps it.
  • Write tokens last 15 minutes. Set write_access_token_seconds to change that.

answer receives scope. Check it in code before any change. A rule in a prompt is not enough.

JavaScript
if (/\bgift ?wrap\b/i.test(message)) {
  if (!account) return loginRequired
  if (scope !== 'write') return { error: { code: 'write_required', message: 'This login can read your order but not change it. Log in again and allow changes.' } }
  await orders.addGiftWrap(account)
  return { reply: 'Gift wrap added, at no charge.' }
}

Write access covers what the person could do themselves, and no more. Run each change as that person, with their own permissions.

Confirm actions that are hard to undo

A cancel, a delete, a payment, or anything else that is hard to take back should not run on a token alone. Return confirm instead of doing it:

JavaScript
if (/\bcancel\b/i.test(message)) {
  if (!account) return loginRequired
  const order = await orders.openOrderFor(account)
  return {
    confirm: {
      summary: `Cancel order ${order.id} (${order.item}, $${order.price}).`,
      authorization_details: [{ type: 'cancel_order', order: order.id }],
    },
  }
}

Then pass act to boot. It runs only after the person approves, once, with the account that approved:

JavaScript
async act({ account, authorization_details }) {
  const [action] = authorization_details
  if (action.type !== 'cancel_order') return { error: { message: 'Unknown action.' } }
  await orders.cancel(account, action.order)
  return { message: `Order ${action.order} is cancelled. The refund goes back to your card in 3 to 5 days.` }
}

What happens:

  1. The message is done. Its reply and confirmation give the person the summary and a link to your confirm page. The action has not run.
  2. The person opens the link, logs in, and approves or denies. Only the account the request is for can approve it.
  3. On approval, act runs once. The visiting agent reads GET /cap/v1/confirmations/{id} and tells the person the result.
  4. A request no one decides expires after 10 minutes.

Write summary from your own records, not from the visiting agent's words, so the person approves what will actually happen. authorization_details is your own description of the action, in the style of RFC 9396. It is stored as data, so an approval survives a restart.

A read login cannot ask for a confirmed action at all. The server answers write_required.

With the http handler, your hook returns { "reply": "...", "confirm": { ... } }, and after approval it receives { "confirmed": { "account", "authorization_details", "caller" } } and returns { "message": "..." }.

Take payments

A purchase is a confirmed action, and the person pays on your page with your own checkout. The visiting agent never sees a card.

  1. Keep the cart on your side. A cart in localStorage or a browser session is out of reach of your agent. Store it against the account, so the person's browser and their agent change the same cart.
  2. Hold the order. When the person asks to check out, price the order from your own records, freeze the items and total, and return confirm with one purchase entry. See Purchases for the fields.
  3. Charge on approval. Your confirm page shows the order and a pay button that goes to your checkout, for the frozen items and amount only. The status is working while the person pays.
  4. Finish from your payment provider. When the payment succeeds, mark the confirmation done with result.message and result.reference set to the order number. Do this from the provider's webhook, not only from the return page, because the person may close the tab after paying.
JavaScript
return {
  confirm: {
    summary: `Buy Stride Runner (black, size 12) from Harbor Goods for $120.00.`,
    authorization_details: [{
      type: 'purchase',
      merchant: 'Harbor Goods',
      items: [{ name: 'Stride Runner', options: { color: 'Black', size: '12' }, quantity: 1, unit_price: '120.00' }],
      total: '120.00',
      currency: 'USD',
    }],
  },
}

The SWSH demo store does this with a server-side cart, a confirm page, and Stripe Checkout.

Use your own sign-in

The reference login pages ask for a username and password. If your users sign in with SSO, a social login, passkeys, or two-factor, put your own pages in front instead. Visiting agents never see the difference, as long as the endpoints behave the same.

Keep exactly as the spec says:

  • The metadata, with protected_resources listing your CAP URL exactly as your CAP line gives it. Visiting agents will not log in without it.
  • device_authorization_endpoint, token_endpoint, and revocation_endpoint, with OAuth's own errors (authorization_pending, slow_down, access_denied, expired_token, invalid_grant, invalid_scope).
  • Each token bound to the CAP-From that started the login. Another agent using it gets 403.
  • Refresh tokens that rotate, and revocation that ends the whole login.
  • The scope rules above, and the confirmation statuses.

Replace with your own pages:

  • The code page. The person opens your verification_uri, signs in your usual way, sees the agent's name and what it asked for, and allows or denies. Record the decision against that code: the account, and the scope they granted.
  • The confirm page. The person signs in your usual way, sees the summary, and approves or denies. Check that they are the account the request is for. Claim the request from pending in one atomic update, so it can only run once.
  • The redirect login's consent page, if you offer it.

If your site already has a signed-in session, these pages can be ordinary pages in your app. The person is usually signed in already, so approving takes one click.

The reference oauth.mjs is a working map of every state: pending and decided codes, one-time code exchange, token rotation, and the confirm claim. Copy its data model even if you replace its pages.

Let a hosted agent use your account routes

Your door's answer can be the whole agent. Some owners run their support agent somewhere else instead, for example a chat widget from a hosted platform, and want that agent to answer public questions itself and fetch account data from you only when the person is logged in.

The login stays yours. The hosted agent logs the person in through your door like any visiting agent, with its own CAP-From, and sends that token to a few JSON routes you choose. Each route asks the door who the token belongs to:

JavaScript
import { createCapHandler } from '@conciergeprotocol/server'

const door = await createCapHandler({ agent, answer, login, write: true, act })

// GET /api/account/orders
export async function GET(request) {
  const access = await door.accountFor(request)
  if (!access) return Response.json({ error: { code: 'login_required' } }, { status: 401 })
  const user = await users.get(access.account)
  const list = await orders.listFor(access.account)
  return Response.json({ orders: list }, { headers: { 'CAP-Account': user.email } })
}

accountFor(request) returns { account, scope, caller }, or null when the token is missing, expired, revoked, or was issued to a different agent than the one in CAP-From. Filter every query by account. Never take an account, customer id, or email from the request body or the URL.

A change still waits for the person. requestApproval holds it and returns a link to your confirm page. act runs it once, after they approve:

JavaScript
// POST /api/account/orders/:number/cancel
const access = await door.accountFor(request)
const order = await orders.find(access.account, number)
const held = await door.requestApproval(request, {
  summary: `Cancel order ${order.number}, $${order.total}.`,
  authorization_details: [{ type: 'cancel_order', order: order.id }],
})
return Response.json(held)

A read login gets write_required from requestApproval, and no login gets login_required. Pass those back with a 401 or 403, so the hosted agent can tell the person to log in again.

The optional CAP-Account response header gives the hosted agent a label for the conversation, such as the person's email, so the owner can tell conversations apart. Send only what you would show the person.

Before you launch

  • Serve every endpoint over https. Accept client documents only on https URLs at public hosts.
  • Fetch client documents behind egress rules, so a client id URL cannot reach your private network.
  • Store tokens as hashes. The reference server does.
  • Check scope and account in code, on every change.
  • Filter every account route by the account behind the token, never by an id in the request.
  • Confirm every action that is hard to undo. Show a summary from your own records.
  • Keep write logins short. Consider ending them days after approval, not weeks.
  • Let people see the agents they have logged in, and end any of them.
  • Rate limit the login, token, and confirm endpoints.
  • Run one process for the redirect login, or pin each login to one process. Its pending requests live in memory.

Try it

The store example runs every step on your machine: a public product search, an order lookup after login, gift wrap with a write login, and a cancel that waits for your OK.

Shell
cd examples/store
node start.mjs

Open http://127.0.0.1:8810, click Log in to make changes, and try Cancel my order.