Skip to main content

Using Claude Agent SDK with Marrow MCP

This tutorial shows how to build a small TypeScript app with @anthropic-ai/claude-agent-sdk and connect it to Marrow MCP. The sample app asks Marrow for sales data, lets Claude analyse it, and writes a structured JSON report to ./response/.

What you will build

By the end, you will have a simple agent that:
  • connects to Marrow MCP from Claude Agent SDK
  • uses a local MCP server for the app’s helper tools
  • asks Marrow for export data, then analyses it in the agent
  • writes the final result as JSON on disk

Prerequisites

  • Completion of the Marrow MCP Overview setup with an MCP key
  • Node.js 24 or later
  • A Marrow organization with an MCP key
  • An Anthropic API key
  • yarn (bundled via Corepack - run corepack enable if needed)

Step 1: Clone and install

Start by installing the project:

Step 2: Configure your keys

Copy the example environment file and add your keys:
Set these values in .env:
  • MARROW_MCP_KEY: your Marrow MCP key
  • ANTHROPIC_API_KEY: your Anthropic API key
The app reads the Marrow key from the environment and sends it to the hosted MCP server.

Step 3: Understand the Claude entry point

The app logic lives in src/index.ts. Claude Agent SDK handles the agent loop, while Marrow MCP provides the Amazon data. Here is the core shape:
There are 3 parts to notice:
  • query(...) starts the Claude run.
  • mcpServers.marrow connects Claude to the hosted Marrow MCP endpoint.
  • createSdkMcpServer(...) exposes local helper tools in the same agent session.
The allowedTools list keeps the agent focused, and maxTurns stops the run from continuing forever.

Step 4: Why the system prompt matters

The system prompt in src/prompts/system.prompt.ts tells Claude how to use the tools:
This turns a generic agent into a focused workflow:
  • Marrow MCP is the source of truth for the Amazon data
  • Claude reasons over the returned data in the conversation
  • the output tool writes one final JSON artefact to disk

Step 5: Keep the output step explicit

The app uses one local tool for the final handoff: output_top_asins in src/tools/output.tools.ts.
The prompt tells Claude to call this tool once, which keeps the final output structured and predictable.

Step 6: Run the app

Start the sample with:
The app will:
  1. ask Marrow MCP for the required sales export
  2. let Claude identify the top 3 ASINs by units sold
  3. call output_top_asins once
  4. write the result to ./response/top-asins-<timestamp>.json

A simple mental model

To reuse this pattern in another app, keep the split the same:
  • Marrow MCP for Amazon data access
  • Claude Agent SDK for the agent loop and tool orchestration
  • local tools for file output and any small app-specific helpers
This separation keeps the tutorial simple while still showing a real integration.

Marrow MCP resources

Check the following resources for more information: