Skip to main content
Glama

execute_code

Run custom JavaScript in a stateful sandbox to query Klaviyo and Shopify analytics, preserving data between calls for multi-step workflows.

Instructions

execute_code(code: string) -> { ok, result, stdout, state, durationMs } state: current globalThis stash (auto-populated, summary-form — read this to see what data from prior calls is available without re-fetching)

Sandbox globals: klaviyo, shopify, console, pick, topN, summarize, globalThis (persists across calls)

Discovery: search_docs / read_doc surface SDK paths, parameter shapes, and recipes. The SDK uses JSON:API conventions (sort keys, sparse fieldsets) that differ from typical JS SDKs — search_docs FIRST for unfamiliar methods.

Reference example (real API surface — note JSON:API request shape): const metricId = await klaviyo.getConversionMetricId(); const report = await klaviyo.reporting.campaignValues({ data: { type: 'campaign-values-report', attributes: { timeframe: { key: 'last_30_days' }, conversion_metric_id: metricId, statistics: ['recipients', 'open_rate', 'conversion_value'], }} }); globalThis.report = report; return topN(report.data.attributes.results, 5, r => r.statistics.conversion_value);

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesJavaScript (or TypeScript-like) to execute in the stateful sandbox. Async; return a value via `return ...`. Globals: klaviyo, shopify, console, pick, topN, summarize, globalThis. No fetch/process/require/import. Add `// @timeout 2m` (max 5m) to extend the 30s wall-clock limit.
Install Server

TDQS

A5/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description goes well beyond annotations by disclosing that globalThis persists across calls, that state is auto-populated as a summary-form stash, that execution is async with a default 30s wall-clock limit and configurable timeout, and that network/module access is blocked. No contradiction with the annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is dense but every section earns its place: return shape, persistent state, available globals, discovery direction, and a reference example. The most important operational facts are front-loaded in the signature and state note.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite lacking an output schema, the description fully defines the return object, persistent state behavior, available globals, constraints, and a realistic usage example. An agent can invoke the tool correctly and interpret results without further documentation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Although the schema already covers the code parameter well, the description enriches it with execution semantics: async behavior, return value via `return ...`, available globals, forbidden globals, and timeout syntax. This gives an agent concrete guidance far beyond the raw schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific action — execute JavaScript/TypeScript-like code in a stateful sandbox — and gives the exact return signature. It clearly distinguishes itself from sibling documentation tools by including a discovery note that routes unfamiliar API questions to search_docs/read_doc.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly says to use search_docs/read_doc first for unfamiliar SDK methods and discourages running code before checking API conventions. It also lists sandbox constraints (no fetch/process/require/import) and timeout rules, which effectively tell the agent when not to use this tool or how to adapt usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rafaelsztutman/dtc-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server