Branded PDF inventory report with charts and MCP
What you get: A two-page A4 PDF in a website's colors and logo, with three charts of records counted from an MCP tool's answer.
Needs: A model key, an MCP server, Chromium and a Python sandbox · Time: 30 minutes · Nodes: 14
One Manual Trigger starts two branches. The brand branch loads a URL with Web Browse in headless Chromium, and a Prompt Template, an LLM Call and an Output Parser turn the page's title, meta tags, image URLs and text into a brand kit: name, logo URL, two colors, a font and a tagline. The data branch calls a list_keys tool with an MCP Tool node, and a Python Code Node counts the records by cloud, by algorithm and by age. Three Chart nodes draw the counts as SVG, the two bar charts in the brand colors, a second Prompt Template builds one HTML page, and PDF Output prints it. The sample counts encryption keys, but any MCP tool that returns a JSON list works. It combines two smaller recipes: brand extraction and PDF report with charts.
Steps
- Download key-inventory-report-flow.json, or take it from the samples folder on GitHub.
- In the studio's workflow editor, import the file (see import and export).
- Install Chromium for Playwright on the API host once:
pnpm exec playwright install chromiumfrom the repo root, or pointPDF_CHROMIUM_EXECUTABLE_PATHat a Chromium you have. Web Browse and PDF Output both need it. - Let Python code run. With the default
CODE_SANDBOX_MODE=auto, Aggregate Keys runs in a throwaway container when docker or podman is installed and both sandbox images are present locally. Without a container, Python code nodes are off by default and the node fails. See code execution. - Point Key manager list_keys at your MCP server: set
connection.endpointto its streamable HTTP URL (http://key-manager-mcp.internal/mcpis a placeholder). For a token, setconnection.authTypetobearerand asecretRefto a stored secret, or register the server in the MCP server registry and setregistryServerId. - Give Distill Branding a model: pick a stored secret with your OpenAI API key under API Key Secret (or set
OPENAI_API_KEYon the API server), or switch the provider. To try it without a key, set itsproviderIdtoechoin the JSON file and import it again: the Provider list has no echo entry. - Set Brand URL to your site, or send a
user_promptwith the run: it replaces the Text Input's URL. Run it, open the run and click Render PDF:pdf.downloadUrlholds the file as adata:application/pdf;base64,...URL, and the PDF Report output returns it asresult.
How it works
| Node | Type | Role |
|---|---|---|
| Run report | manual_trigger | Step in the run |
| Brand URL | text_input | Step in the run |
| Key manager list_keys | mcp_tool | Step in the run |
| Fetch Brand Site | web_browse | Step in the run |
| Aggregate Keys | code_node | Step in the run |
| Extract Branding Prompt | prompt_template | Step in the run |
| Distill Branding | llm_call | Step in the run |
| Parse Brand JSON | output_parser | Step in the run |
| Keys by Cloud | chart | Step in the run |
| Keys by Algorithm | chart | Step in the run |
| Key Aging | chart | Step in the run |
| Compose Branded HTML | prompt_template | Step in the run |
| Render PDF | pdf_output | Step in the run |
| PDF Report | output | Step in the run |
11 node types. Each type links to its config fields in the node reference.
What a run does
We ran it on a local install with three stand-ins, so nothing left the machine: a brand page served on localhost (a title, an og:image logo, a theme-color tag and text naming two colors and a font), a local MCP server whose list_keys returned 12 keys, and a scripted OpenAI-compatible model that answered the brand prompt with one JSON object. Python ran in a container (we set CODE_SANDBOX_PYTHON_IMAGE to a stock python:3-alpine image).
- With the stand-ins, the run took about 1.7 seconds: about 0.65 s each for Web Browse and the PDF, 0.3 s for the Python step (mostly starting the container) and 6 to 12 ms per chart. The PDF was 55,555 bytes on two A4 pages: the logo, brand name and tagline, a box with the total (12), the cloud bar chart in the page's primary color and the algorithm donut on page 1, and the age chart in the accent color on page 2. The age chart's heading was left at the foot of page 1; add
h2{break-after:avoid}.chart{break-inside:avoid}to the template's CSS to keep headings with their charts. - With the echo provider, the model only repeats the prompt. The parser picked up the image list from the echoed text, so every brand field was empty: the PDF had no brand name, tagline or logo, and the bar charts used default colors. The run still succeeded, so check the brand values.
- With the MCP endpoint as shipped, Key manager list_keys failed with
fetch failedafter about 8 seconds. The nodes that had not run yet, Web Browse included, were skipped, and the run ended with an error.
The file name template is {{results.brand_parse.parsed.brand}}-key-inventory-{{session_id}}.pdf: a run with session_id: "q4-review" gave the stand-in's brand name followed by -key-inventory-q4-review.pdf (spaces in the brand name are kept), and without a session the name ends in -.pdf. The stand-in shows the plumbing; how well a real model fills in the brand kit depends on the model and the page.
How the branches meet
A node sees the outputs of the nodes that point at it. The three Chart nodes have edges from both Aggregate Keys and Parse Brand JSON, so they wait for both branches. Compose Branded HTML has edges from the parser, the Python step, the Text Input and the charts, so its template can use {{parsed.brand}}, {{totalKeys}} and {{cloudChart.svg}}. Render PDF has only the HTML node as a parent, so its file name reads the brand with {{results.brand_parse.parsed.brand}}, which reaches any finished node.
A Chart node fills in placeholders only in specTemplate, a JSON string, not in an inline spec object. The two bar charts use specTemplate with {{ parsed.primaryColor || '#4c78a8' }} as the bar color, so a missing color falls back to a default. The result must still be valid JSON: a color value with a quote in it fails the node. Each chart's dataPath (byCloud, byAlgorithm, ageing) names a list from the Python step. See the Chart node for the other fields.
The Python step
Aggregate Keys gets the MCP Tool node's output as items[0]: the tool's text in tool_output, and its structuredContent in structured when the server sends one. The script prefers structured, parses tool_output as JSON otherwise, and accepts a list or an object with a keys list. It reads each record's algorithm, labels.cloud (or cloud) and createdAt. Missing values count as unknown, and a record without a readable date counts as under 30 days old.
A Python code node returns what the script assigns to result; log() only adds a line to code_logs. Here result is a dictionary (byCloud, byAlgorithm, ageing, totalKeys, generatedAt), and its keys also appear at the top level for the next nodes. generatedAt goes into the report as a raw ISO timestamp; format it in the script if you want a plain date.
Outbound requests and untrusted input
Web Browse loads the page and everything it pulls in, and PDF Output loads whatever the HTML references, here the logo URL. Both go through L2M's outbound URL checks: cloud metadata and link-local addresses are always refused, while private ranges and localhost are allowed by default, which is why our localhost page worked.
The brand values come from a web page through a model and go into the HTML without escaping, and Chromium renders that HTML with scripts on. Treat the brand URL as untrusted input. The counts have no model in their path: the charts come straight from the tool's answer.
Make it yours
- Count something else: change the tool name and
argsTemplateon the MCP Tool node, then the field names in the Python step. Keep thebyCloud,byAlgorithmandageingnames, or change each chart'sdataPath. - Skip the model: delete the four brand nodes and put fixed colors in the chart specs and the HTML template.
- Let a chat follow up on a report: the two-turn report and code helper saves a report per session and writes a script from it on the next turn.
Make it safer
These controls are optional; the recipe runs without them.
- If people you do not control choose the brand URL, turn on
OUTBOUND_DENY_PRIVATE(off by default): see outbound URL checks. - Keep Python in the container sandbox, not on the host: see code execution.
- Give the workflow an MCP token that can only read. An optional MCP tool policy can also refuse tools you did not mean to allow.
- The PDF is stored with the run as base64, so anyone who can read the run can read the report.