Skip to content

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 ​

  1. Download key-inventory-report-flow.json, or take it from the samples folder on GitHub.
  2. In the studio's workflow editor, import the file (see import and export).
  3. Install Chromium for Playwright on the API host once: pnpm exec playwright install chromium from the repo root, or point PDF_CHROMIUM_EXECUTABLE_PATH at a Chromium you have. Web Browse and PDF Output both need it.
  4. 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.
  5. Point Key manager list_keys at your MCP server: set connection.endpoint to its streamable HTTP URL (http://key-manager-mcp.internal/mcp is a placeholder). For a token, set connection.authType to bearer and a secretRef to a stored secret, or register the server in the MCP server registry and set registryServerId.
  6. Give Distill Branding a model: pick a stored secret with your OpenAI API key under API Key Secret (or set OPENAI_API_KEY on the API server), or switch the provider. To try it without a key, set its providerId to echo in the JSON file and import it again: the Provider list has no echo entry.
  7. Set Brand URL to your site, or send a user_prompt with the run: it replaces the Text Input's URL. Run it, open the run and click Render PDF: pdf.downloadUrl holds the file as a data:application/pdf;base64,... URL, and the PDF Report output returns it as result.

How it works ​

Diagram of the Key manager — Key Inventory Report (PDF, branded) workflowRuns Run report, then Brand URL, then Key manager list_keys, then Fetch Brand Site, then Aggregate Keys, then Extract Branding Prompt, then Distill Branding, then Parse Brand JSON, then Keys by Cloud, then Keys by Algorithm, then Key Aging, then Compose Branded HTML, then Render PDF, then PDF Report.Run report (manual_trigger)Run reportmanual_triggerBrand URL (text_input)Brand URLtext_inputFetch Brand Site (web_browse)Fetch Brand Siteweb_browseExtract Branding Prompt (prompt_template)Extract Branding Promptprompt_templateDistill Branding (llm_call)Distill Brandingllm_callParse Brand JSON (output_parser)Parse Brand JSONoutput_parserKey manager list_keys (mcp_tool)Key manager list_keysmcp_toolAggregate Keys (code_node)Aggregate Keyscode_nodeKeys by Cloud (chart)Keys by CloudchartKeys by Algorithm (chart)Keys by AlgorithmchartKey Aging (chart)Key AgingchartCompose Branded HTML (prompt_template)Compose Branded HTMLprompt_templateRender PDF (pdf_output)Render PDFpdf_outputPDF Report (output)PDF Reportoutput
Solid arrows are the order the steps run in. Dashed lines attach a chat model, memory, tools or workers to an agent; the agent uses them while it runs.
NodeTypeRole
Run reportmanual_triggerStep in the run
Brand URLtext_inputStep in the run
Key manager list_keysmcp_toolStep in the run
Fetch Brand Siteweb_browseStep in the run
Aggregate Keyscode_nodeStep in the run
Extract Branding Promptprompt_templateStep in the run
Distill Brandingllm_callStep in the run
Parse Brand JSONoutput_parserStep in the run
Keys by CloudchartStep in the run
Keys by AlgorithmchartStep in the run
Key AgingchartStep in the run
Compose Branded HTMLprompt_templateStep in the run
Render PDFpdf_outputStep in the run
PDF ReportoutputStep 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 failed after 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 argsTemplate on the MCP Tool node, then the field names in the Python step. Keep the byCloud, byAlgorithm and ageing names, or change each chart's dataPath.
  • 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.

Further reading ​

This website (not the L2M product) uses Google Analytics, only after you accept cookies. Cookie settings