Use OpenAI Agents SDK with Marrow MCP
This tutorial shows how to build a small TypeScript agent with the OpenAI Agents JS SDK and connect it to Marrow MCP. The sample app does one practical job: it uses Marrow advertising data, downloads the export file, loads it into DuckDB and writes a JSON file with improved Amazon listing copy.What you will build
By the end, you will have a simple agent that:- connects to Marrow MCP with
hostedMcpTool - downloads an export file before the URL expires
- loads the data into DuckDB and runs SQL over it
- produces one final JSON file in
response/
Prerequisites
- Completion of the Marrow MCP Overview setup, with an MCP key
- An OpenAI API key with access to
gpt-5.4-mini - Node.js 24 or later (required for native TypeScript support)
- yarn (bundled through Corepack; run
corepack enableif needed)
Step 1: Clone and install the repository
Install the project:Step 2: Configure your keys
Copy the environment file and add both API keys:.env and set:
MARROW_MCP_KEY: your MCP key from the Marrow integrations pageOPENAI_API_KEY: your OpenAI API key
src/index.ts, it uses this configuration:
Step 3: Create the agent
The main agent lives insrc/index.ts. It imports the OpenAI Agents SDK and combines Marrow MCP with a few local tools:
hostedMcpTool(...)exposes Marrow tools to the agentfetchTools,duckdbToolsandoutputToolshandle the local workflowsystemPrompttells the model what to do and what not to dorun(...)executes the agent and streams its output
Step 4: Understand the helper tools
The local tools make the sample app work like a real workflow, rather than a single prompt.Download tool
src/tools/fetch.tools.ts adds download_file_from_url. Marrow export URLs are temporary, so the agent should fetch them right away and save them locally.
DuckDB tools
src/tools/duckdb.tools.ts is where the downloaded data becomes queryable:
load_jsonfor JSON or newline-delimited JSON fileslist_tablesto inspect what is loadedrun_sql_queryto run standard SQL against DuckDB
Final output tool
src/tools/output.tools.ts defines output_improved_listings. This tool is the app’s final step:
response/improved-listings-<timestamp>.json.
Step 5: Use the system prompt to guide the agent
The prompt insrc/prompts/system.prompt.ts keeps the agent focused. It tells the model to:
- use Marrow MCP tools when it needs export data
- prefer SQL-based analysis through DuckDB
- keep marketplace-specific content in the right language
- never write JSON output directly in the chat
Step 6: Run the app
Start the sample with:src/index.ts, streams the agent’s reasoning to the terminal and finishes by writing a JSON file to ./response/.
Typical flow:
- The agent asks Marrow MCP for the needed export.
- The export URL is downloaded immediately.
- DuckDB loads the file and the agent runs SQL to find weak ASINs.
- The model rewrites the listing copy.
output_improved_listingssaves the final result.
Use a simple mental model
If you want to adapt this pattern for another Marrow-powered agent, keep the same split:- Marrow MCP for source data
- local tools for downloading, transforming, and validating
- one dedicated output tool for the final artifact
Related resources
Marrow MCP resources
Check the following resources for more information:- MCP server URL:
https://mcp.marrow.com/mcp/v1 - Interactive Data Scheme
- Data Scheme JSON: https://api.marrow.com/api/v1/spec/data-scheme
- Need help? Use the contact form

