| Tool | Purpose |
|---|---|
list_templates | Enumerate templates visible to the calling user. |
generate_template | Render a template by key, against optional context. |
get_template) is used by Deal Brain’s own agent runtimes to hydrate a template before rendering. It is not exposed publicly over MCP.
list_templates
Returns all templates the calling user can see, deduplicated by scope precedence (User > Organization > System).
Input
No parameters. The tool always operates against the calling user’s identity.Output
Returns two content blocks: astructuredContent JSON payload and a human-readable text summary.
Behavior
- Returns only
activetemplates. Drafts are invisible. - Returns only templates the calling user can see, with scope precedence applied — the user sees the most-specific version of each key.
- Sort order: System templates first (alphabetical by key), then Organization, then User.
Example agent prompt
Show me all the available templates and pick the one closest to a “deal qualification readout.”The agent calls
list_templates, scans the descriptions, and chooses the best match by key.
generate_template
Renders a template by key, binding optional context (most commonly an opportunity ID), and returns the system prompt + rendered body ready for the LLM.
Input
The template’s stable key. Examples:
daily-brief, user-templates/opportunity-readout-3p.The UUID of the opportunity to bind. If the template uses opportunity variables and this is omitted, those variables render as empty.
Optional key-value pairs that override specific variables at render time. Useful for testing or for binding values not in the data layer.Example:
{ "company tone of voice": "casual and warm" }Output
Returns two text blocks:- System prompt — Deal Brain’s standard model directive plus any instruction variables compiled from the template.
- Rendered body — The template’s content with all
datavariables substituted.
Behavior
- Scope precedence applies. The key resolves to User > Organization > System for the calling user.
- Status gate. If the resolved template is
draft, the tool returns an error. - Missing opportunity. If
opportunityIdrefers to a deal the calling user can’t see, the tool returns an authorization error — not an empty render. - Missing variables. If a
datavariable’s value isn’t present in the bound context, it renders as an empty string. The template should be written to handle this gracefully.
Task-handoff semantics
For date-anchored templates (daily/meeting briefs and debriefs),generate_template supports MCP task handoff:
- The first call kicks off the render asynchronously and returns a task ID.
- Subsequent polling resolves to the final two-block output.
- The result is cached per (template key, opportunity ID or date, calling user) for the cache window.
Draft-message templates (e.g.,
drafts/follow-up) do not support task handoff — they’re synchronous and not cached, because each draft is bespoke.Errors
| Error | Cause |
|---|---|
TEMPLATE_NOT_FOUND | No template with the given key is visible to the calling user. |
TEMPLATE_NOT_ACTIVE | Template resolved but its status is draft. |
OPPORTUNITY_NOT_FOUND | opportunityId was provided but the deal is not visible to the calling user. |
INVALID_CONTEXT_OVERRIDE | contextOverrides contains a key that doesn’t match any known variable. |
Example agent flow
Integration patterns
Customer-authored templates in a custom agent
If you’re building an agent on top of Deal Brain and want customers to author their own templates inside Deal Brain’s Canvas UI, the pattern is:- Customer authors the template in Canvas, sets it to Active, and uses a key prefix you control (e.g.,
your-product/<feature>). - Your agent calls
list_templates, filters to keys starting withyour-product/, and presents them to the customer as choices. - Your agent calls
generate_template({ key, opportunityId })and sends the result to your LLM.
Caching for repeated reads
For date-anchored templates that the agent calls repeatedly within the same window (e.g., adaily-brief checked multiple times in a morning), rely on the built-in task-handoff cache documented above — Deal Brain caches by (template key, opportunity ID or date, calling user) for the cache window, so repeated calls within the window hit the same render.
See also
- Publishing — status, scope, and how a template becomes visible to
list_templates. - Variables — the data and instruction tokens that templates resolve at render time.

