salesascode
← All feature docs
Feature docs · /settings/api-keys

Advanced: API Keys & MCP

The power-user path. The default path needs no key: connect your tools and it runs on a schedule. If you want to drive your account from your own scripts or an MCP-compatible agent, issue a Bearer token and your brain becomes scriptable. Six tools cover the verbs that matter: log a capture, update a prospect, append to a plan, mark a meeting outcome, read an account, pull a brief.

Overview

This is an advanced option under Settings, Advanced, not the main flow. Most people never need it: connect your CRM, inbox, and calendar on Connect and the work runs on a schedule. If you want to script your account, the API keys surface turns it into a tenant-scoped MCP server. Issue a key at /settings/api-keys, point any MCP client at your account, and tools/list returns 51 tools. Every write hits the same panel_data store the in-app surfaces use, so scripted and in-product activity stay in sync. The cards below cover the ones you reach for first; ask your client for the full list rather than trusting this page to stay current.

Different from Connect your tools, that page links your CRM, inbox, and calendar for the scheduled runs. API keys are the credential for the advanced, self-driven path.

How it helps you

How to use it

  1. Open /settings/api-keys, click + New key.
  2. Name it (e.g. "nightly brief"), pick the scopes the agent needs.
  3. Copy the key, it's shown once. Paste it into the agent's credential field.
  4. Point the agent at https://<your-domain>/api/v1/mcp as the MCP server URL.
  5. The agent calls tools/list to introspect, then tools/call to invoke. Every call lands in your audit log.

The six tools

// capture.write

log_capture

Drop a free-form note or transcript into the brain. Optionally attach to an account or prospect.

// prospect.write

update_prospect

Create or update a prospect (name, title, email, notes, arbitrary fields).

// plan.write

add_to_plan

Append content to a named section of an account plan ("next_steps", "risks", "champion_notes").

// meeting.write

mark_meeting_outcome

Record the outcome of a meeting ("advance" / "stall" / "lost" or free-form) with notes + next step.

// account.read

read_account

Read an account record. Optionally pull in the plan, recent meetings, or recent captures.

// brief.read

pull_brief

Structured "today / week" summary, accounts active, recent captures, recent meetings, open plan sections.

// usage.write

POST /api/ingest/usage

Push product-usage / consumption data for an account by domain (seats used, active users, contract terms, usage signals). A vendor-neutral REST endpoint, point your warehouse job or ETL at it and the pre-call brief renders consumption-vs-contract, each line cited to the ingested telemetry.

// meddpicc.write

set_meddpicc

Put MEDDPICC evidence on an opportunity by id, any of the eight dimensions as short text. Provided dimensions merge onto the existing record; others are left untouched. This is how a deal earns the evidence the curiosity engine reads to find the gaps worth asking about, without a CRM.

Control-plane tools

Five more tools cover the control plane: check the session, check a licence, report run telemetry, push brain state, pull config. They need no extra scope, a valid key acting on its own account is enough.

Your own client is what calls these. The scheduled runs do not: they run inside our servers and write the same tables directly, so nothing in your rollup depends on an agent remembering to report. The descriptions below say "every skill" because they are written for a skill you drive over MCP.

// session

verify_session

Returns the account, plan, and entitled products. Every skill calls this first and stops if it errors.

// license

check_entitlement

Is this account licensed for a named product? Skills stop and ask the user to connect their account if not.

// telemetry

emit_telemetry

Record a run event, product, skill, counts, outcome, duration. Metadata only. Powers the Activity rollup.

// brain

sync_brain

Push brain state for a scope (signal-weights, icp-registry, decision-log, funnel-brain, ...).

// config

pull_config

Pull the account's plan, entitled products, and feature flags so a skill can adapt at run start.

These back the per-account Activity rollup. The full contract, every tool with its arguments and scopes, is on API & MCP.

Entitlement is enforced per tool. Any tool that reads or writes your data or brain, the six data verbs plus emit_telemetry, sync_brain, start_run, run_heartbeat, connect_integration, and the studio tools, requires the account to hold at least one active paid entitlement (a product, bundle, suite, membership, or team seat). Without one, the server returns not_entitled (MCP error -32003 / HTTP 403) with a pointer to /pricing. The onboarding trio stays open on purpose: verify_session, check_entitlement, and pull_config are always callable so a new user can connect and check status before buying. Entitlement is additive to the scope check, a call must clear both.

Security model

Webhooks

Keys let your systems call us. Webhooks let us call them. On the same page, under Webhooks, click + New webhook, paste an HTTPS URL, and pick the events: draft.ready, reply.received (with the reply's intent), account.tier_changed, send.approved and deal_terms.proposed (a discount or a customer commitment waiting for a person). We POST a signed JSON event to that URL each time one happens.

Signature format, retry timing and the URLs we refuse: API & MCP, Webhooks.

Use cases

// your agent

Wire your own client

Have your agent log captures and update prospects as you work, your brain stays current without context-switching.

// scripts

Cron-driven workflows

A nightly script pulls your brief, summarizes it, posts to Slack. Or a meeting bot logs the outcome into your account plan automatically.

// custom agents

Build your own agent

Wire any agent loop to the MCP server. Tools/list discovers everything; you don't ship custom integrations.

// team automation

Team-wide workflows

An ops team can issue per-process keys ("post-call writer", "weekly forecaster") with the minimum scopes each needs.

Transports: HTTP, REST, and stdio

HTTP is the canonical MCP transport, point any HTTP MCP client at /api/v1/mcp. Every tool is also a plain REST endpoint (below). For clients that only speak stdio, the repo ships a thin local bridge that forwards stdio JSON-RPC to that same HTTP endpoint:

  1. Issue a key here and set it as SALES_AS_CODE_API_KEY.
  2. Run npm run mcp:stdio, or point your stdio client's config at node scripts/mcp-stdio.mjs with the key in the server's env block.
  3. The bridge relays each message to /api/v1/mcp, same tools, same scopes, same audit log. It holds no logic of its own.

Full config example: /docs/api, stdio.

Team keys

By default a key is per-user, it authorizes against your own plan. A team owner can toggle Issue as a team key in the New key dialog to mint a team key instead. A team key still writes into the owner's workspace, but the control-plane tools (verify_session, check_entitlement, pull_config) resolve entitlements against the team's plan: the union of the owner's grants and every product the team's seat packs license. Per-user keys are unchanged and keep working exactly as before.

OAuth-provider mode (optional)

Pasting a key is the default for this advanced path. When a deployment enables it (MCP_OAUTH_ENABLED=true), a client can instead obtain access through a standard OAuth 2.0 authorization-code + PKCE flow, you approve it on a consent screen using your existing login, and the client never sees a key you had to copy. The clever part: the OAuth access token is a managed key. It's minted as a scoped api_keys row, shows up in this list as OAuth (<client>), and you revoke it here like any other.

PromptReports ID agent tokens (switching on)

An agent registered at PromptReports ID can call this API and MCP without a key you copy. It gets a short-lived agent token from the ID that names you as the person it acts for, the agent and its version, and your PromptReports org, and it proves each call with a DPoP proof signed by its own key. Send the token as Authorization: DPoP <token> (or Bearer) with the proof in the DPoP header.

This is switching on: it starts working once PromptReports ID issues agent tokens for this site and we turn them on. Until then an agent token is refused as an unknown key, and your own keys work as above.

Outside apps you signed in to with PromptReports (switching on)

An outside app, such as a notes or document tool, can read your Sales as Code data after you sign in to it with PromptReports. The app asks PromptReports ID for a one-minute grant naming you, your PromptReports org and the app, then trades it at POST /api/v1/oauth/token (grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer, the grant in assertion, and a DPoP proof by the app's own key) for a key from this site.

This is switching on: it starts working once PromptReports ID issues these grants for this site and we turn them on. Until then the token endpoint answers unsupported_grant_type.

How each call is decided

Every call to a tool, over MCP or REST, gets one decision before the tool runs, in three checks. If any check says no, the answer is no: nothing later can turn it round.

  1. Scope. The key, or the agent token's scopes, must hold the tool's scope. Otherwise 403 scope_required (MCP -32001).
  2. Licence or seat. Data and brain tools need an active entitlement. Otherwise 403 not_entitled (MCP -32003). For an agent token, the person and the org were already checked when the call signed in.
  3. Your organization's policy, for high-risk actions. Two tools count: studio_review_draft when it approves or schedules a draft (publishing, the external share class) and propose_action (a CRM write, the system of record class). If your organization set that class to Never, the call gets 403 policy_denied (MCP -32004), for keys and agents alike.

An agent acting for you with a PromptReports ID agent token never publishes on its own. Approving or scheduling a draft answers 403 approval_required (MCP -32005) with an RFC 9396 authorization_details object naming the action, this site and the draft, and nothing runs: you approve the draft in Studio. propose_action still runs for an agent, because all it does is put a proposal in your review queue, and nothing reaches the CRM until a person approves it there. A key you issued yourself keeps acting on your own drafts as before.

Every decided call is also accounted for. It leaves one audit event (your PromptReports org and person when an ID agent token named them, the agent and its version, or the key, the tool, the decision, how it ended, and the policy version) and one usage event (one unit for this product, and how long it ran). When the call put a proposal in your review queue, the audit event links to it, and to its signed receipt once a person applies it. Both are kept here, beside the call log above. Sending them to PromptCompute's audit and usage records, with the key your org made when it connected PromptCompute, is switching on: we turn it on for this site once it is checked end to end. An org that has not connected PromptCompute keeps them here only.

A refusal or a wait for a high-risk action names the policy version it used. Asking PromptReports' policy service as well is switching on: it waits on that service being published, and until then only the checks above decide.

The HTTP REST surface

The same tools are also available as plain REST endpoints if you prefer not to speak MCP. POST JSON to /api/v1/tools/<name> with a Bearer auth header. Same Bearer key, same scopes, same audit log.

curl -X POST https://salesascode.com/api/v1/tools/log_capture \
  -H 'authorization: Bearer sak_…' \
  -H 'content-type: application/json' \
  -d '{"source":"script","text":"Acme champion confirmed budget for Q3"}'

Related

// deep walkthrough · 2 min