# Set up Teaflask in this product

The user copied this prompt from teaflask.com and gave it to you. They want Teaflask in the product whose code you have open, and they already have a Teaflask organization.

Your goal is a minimal setup that provably works on their local dev server: the assistant mounted in the app, answering as a published agent, with their API reachable through actions. Everything beyond that is a next step you offer at the end, not something you build now.

Teaflask's docs are the source of truth. Fetch each docs page as Markdown by adding `.md` to its URL, and follow what it says over anything you already believe about Teaflask. The full list of pages is at https://docs.teaflask.com/llms.txt.

If you already have Teaflask's MCP tools, such as `get_onboarding`, steps 1 to 3 happened in an earlier session. Check that the code changes from step 2 are in place, finish them if not, and continue from step 4.

## 1. Understand Teaflask

Before you change anything, read these:

- https://teaflask.com/llms.txt: what Teaflask is and who it's for. If it disagrees with the docs, the docs win.
- https://docs.teaflask.com/fundamentals.md: what Teaflask runs and what the user owns.
- https://docs.teaflask.com/architecture.md: where each part runs, and the boundary between the assistant in the page, the Teaflask runtime and the user's backend.
- https://docs.teaflask.com/getting-started.md: the whole path to a live agent.

## 2. Add the assistant to this codebase

Skip anything already in place.

1. Read https://docs.teaflask.com/assistant-ui.md, then follow https://docs.teaflask.com/install.md in this repository, steps 1 to 6. Read the publishable key from a public environment variable, named the way this project names its public variables, and add it to the example env file if there is one. Leave its value empty for now.
2. Wire the actions adapter: https://docs.teaflask.com/adapters.md. Choose the kind that matches how this app's frontend already calls its own API, so actions run in the user's existing session.
3. Wire identity: https://docs.teaflask.com/identity.md. Add the token endpoint and give the assistant the `userId` and `getEndUserToken` pair for signed-in users. The signing secret goes in a server environment variable that the user fills in; add it to the example env file with an empty value. Never ask for the secret in the chat, and never commit it. While the variable is empty, have the endpoint answer that no token is available and `getEndUserToken` return `null`, so the assistant runs anonymously instead of showing a setup error.

Don't guess at props, attributes or properties. Every public export and field is described in the package itself: in its TypeScript types for the npm package, and in `custom-elements.json` at the package root for the script tag. If the package isn't installed locally, read them on unpkg: https://unpkg.com/@teaflask/assistant/

## 3. Connect to Teaflask's MCP server

The rest of setup happens in the user's Teaflask organization, through Teaflask's MCP server at `https://api.teaflask.com/mcp`. It is a remote HTTP server that the user signs in to with OAuth. Add it to your own client, named `teaflask`:

- Claude Code: run `claude mcp add --transport http teaflask https://api.teaflask.com/mcp`.
- Cursor: it can't sign in to Teaflask's MCP server yet, so go straight to "Without the MCP server".
- Any other client: add it the way your client's documentation says to add a remote HTTP MCP server with OAuth sign-in.

If you couldn't add it, because your client can't add one itself or doesn't support OAuth for remote servers, go to "Without the MCP server". Go there too if it was already added in an earlier session but you still have no Teaflask tools because signing in failed, instead of asking the user to paste this prompt again.

If it worked, stop and tell the user what you changed so far, then ask them to:

1. Copy the identity signing secret from **Settings → Keys → Identity verification** at https://app.teaflask.com into the server environment variable you added. This is optional for the local check; without it the assistant runs anonymously. Only an owner can see the secret.
2. Start a fresh session in this project. A server added mid-session isn't available until then.
3. Sign in to Teaflask when the client asks. In Claude Code, run `/mcp`, select teaflask and follow the prompt. In the browser, choose the organization and leave every tool on; they can narrow it later in **Settings → MCP**.
4. Paste this same prompt again.

## 4. See where the organization stands

Find out, without changing anything:

| Question                                                               | How                                                   |
| ---------------------------------------------------------------------- | ----------------------------------------------------- |
| Is there an agent, and is it published?                                | `list_agent_definitions`, then `get_agent_definition` |
| Is a GitHub repository connected, and have actions been scanned?       | `get_onboarding` and `get_latest_org_action_scan`     |
| Are there actions in the catalog?                                      | `list_org_actions`                                    |
| Are there any docs?                                                    | `list_docs`                                           |
| Can the organization pay for the work this setup starts?               | `get_model_settings`                                  |
| Is there a publishable key whose origins include the local dev server? | `list_publishable_keys`                               |

Tell the user what you found in a few lines, and what you propose to fill in.

## 5. Fill the gaps

Do only what the minimal local run needs. Ask before each change in Teaflask: say what you're about to create, change or publish, and wait for a yes. If a tool is missing or refused, tell the user its name and that they can turn it on in **Settings → MCP**. Some tools are owners only; if the user isn't an owner, that step goes in your report as one for an owner.

- Billing. In `get_model_settings`, the work this setup needs must have a `paid_by.state` of `own_key` or `balance`: the agent's replies (listed under `agents` once it's published) and, with a repository connected, the `scans` and `docs` work. If any can't be paid for, stop and tell the user what, for an owner to fix in the dashboard: https://docs.teaflask.com/models.md and https://docs.teaflask.com/billing.md. Wait until it can be paid before anything that costs money: the action scan, the doc and the local check. You can't fix it from here, but you can propose another model in the agent's configuration. It's the one step only the user or an owner can do, so it comes first.
- GitHub. If no repository is connected, recommend connecting it: https://docs.teaflask.com/github.md. Say what skipping it costs: Teaflask won't suggest actions from the repository's API specs, and won't propose doc updates as the code changes. It's optional and can't be done from here, so carry on either way.
- Actions. If the catalog is empty and a repository is connected, run `start_org_action_scan`, poll `get_latest_org_action_scan`, and approve a few of the suggestions from `list_org_action_proposals` with `approve_org_action_proposal`. With no repository, add a few of this API's endpoints with `register_org_action`. A handful is enough, with at least one read-only action for the check in step 6. Read https://docs.teaflask.com/actions.md first; a good default policy is `allow` for reads and `ask` for writes.
- Docs. If there are none, draft one short doc from the code that says what the product is and what users do in it, with `create_doc`, and publish it with `release_doc` once the user approves.
- The agent. Use the existing agent if there is one, or create one with `create_agent_definition`. Read https://docs.teaflask.com/agents.md. Grant it the actions and docs search, keep its prompt short, and leave `end_users.sign_in_required` off so the local check works without signing in. Edit with `create_agent_definition_revision` and publish with `publish_agent_definition`.
- The key. If none fits, create one for the agent with `create_publishable_key`: https://docs.teaflask.com/publishable-keys.md. Its origins can't be changed later, so include the local dev server's address from this project plus the staging and production origins, which you ask the user for. Put the key's value in the environment variable from step 2, in the env file that holds this project's local values.

## 6. Prove it runs locally

Start the local dev server and work through step 7 of install.md: the launcher appears, and the agent answers a message. Then:

- Ask the assistant something that needs the read-only action, and check the call succeeded through the adapter: find the conversation with `list_conversations` and read it with `get_conversation_transcript`.
- Confirm in `list_publishable_keys` that the key now has a `last_used_at`.
- If the identity secret is set and you can sign in to the app locally, check that the conversation belongs to that user.

If anything fails, find out why and fix it before you go on. Don't report success until each check has passed.

## 7. Report and offer next steps

Finish with a short report: what you changed in the code, file by file; what you set up in Teaflask; what you checked and saw; and anything left for the user, each linked to its docs page.

Then offer next steps, and build none of them unless the user asks:

- More docs, drafted from the code: https://docs.teaflask.com/drafting.md.
- A fuller agent prompt, more actions, and skills: https://docs.teaflask.com/skills.md.
- Letting the agent navigate and work with the page: https://docs.teaflask.com/app-access.md.
- Custom views for action results, such as an order card instead of raw JSON: https://docs.teaflask.com/tool-views.md. Read each granted action's schemas with `get_org_action` and key each view by its exact action name.
- Theming and other surfaces: https://docs.teaflask.com/appearance.md and https://docs.teaflask.com/surfaces.md.
- Tests written from real conversations, such as the one from your check, so a new version of the agent is checked before it's published: https://docs.teaflask.com/tests.md.
- Seeing what users do in the product, one journey at a time, with Steep. It has its own package and its own key, which an owner creates: https://docs.teaflask.com/steep.md and https://docs.teaflask.com/steep-install.md.

## Without the MCP server

The user sets up their organization in the dashboard at https://app.teaflask.com instead, and most of these steps need an owner. Finish with a report of what you changed, then list these steps, each linked to its docs page:

1. Make sure the organization can pay for its work, as **Settings → Models** shows: models.md and billing.md.
2. Optionally, connect this repository, so Teaflask suggests actions from its API specs and keeps docs current: github.md.
3. Register a few actions and set a policy on each: actions.md.
4. Add at least one doc and release it: drafting.md and releasing.md.
5. Configure the agent, grant it the actions, and publish it: agents.md.
6. Create a publishable key: publishable-keys.md. Give them the exact allowed origins, worked out from this project, such as its local dev server address, plus staging and production. A key's origins can't be changed later.
7. Put the key in the environment variable you set up, and the identity signing secret in its server variable.
8. Check it works: step 7 of install.md, against the local dev server.

They can also connect you to the MCP server later and paste this prompt again, and you'll do these steps for them.
