> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hologrow.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Using Claude Agent SDK with Marrow MCP

# 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](/hologrow-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:

```bash theme={null}
git clone https://github.com/Deltologic/marrow-mcp-claude-agent-sdk.git
cd marrow-mcp-claude-agent-sdk
yarn install
```

## Step 2: Configure your keys

Copy the example environment file and add your keys:

```bash theme={null}
cp .env.example .env
```

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:

```ts theme={null}
import { createSdkMcpServer, query } from '@anthropic-ai/claude-agent-sdk';

import { systemPrompt } from './prompts/system.prompt.ts';
import { outputTools } from './tools/output.tools.ts';
import { sleepTools } from './tools/sleep.tools.ts';

const localServer = createSdkMcpServer({
    name: 'local-tools',
    tools: [...sleepTools, ...outputTools]
});

const messages = query({
    prompt: 'Analyze the Delto UK account for the last 7 days. Find the top 3 ASINs by total units sold.',
    options: {
        model: 'sonnet',
        systemPrompt,
        mcpServers: {
            marrow: {
                type: 'http',
                url: 'https://mcp.marrow.com/mcp/v1',
                headers: {
                    'marrow-mcp-key': process.env.MARROW_MCP_KEY ?? ''
                }
            },
            'local-tools': localServer
        },
        allowedTools: ['mcp__marrow__*', 'mcp__local-tools__*'],
        maxTurns: 10
    }
});
```

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:

```ts theme={null}
export const systemPrompt = `You are an expert Amazon marketplace data analyst. You have access to Marrow MCP, which provides live Amazon Seller/Vendor data.

Current time: ${new Date().toISOString()}

## Data access pattern

Use \`mcp__marrow__exports_raw_download\` to fetch sales data directly. Analyse the returned data inline - no file download or SQL engine is needed.

## Output rule

After completing your analysis you MUST call \`mcp__local-tools__output_top_asins\` exactly once with all results. Never write the final JSON directly in your response text - always route it through that tool.
`;
```

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`.

```ts theme={null}
tool(
    'output_top_asins',
    'Log the top-ASINs sales report to console and save it to ./response/<timestamp>.json. Call this exactly once with all results.',
    { asins: z.array(asinSalesSchema) },
    async ({ asins }) => {
        const json = JSON.stringify(asins, null, 2);
        mkdirSync('./response', { recursive: true });
        const filePath = `./response/top-asins-${Date.now()}.json`;
        writeFileSync(filePath, json);
        return { content: [{ type: 'text', text: json }] };
    }
);
```

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:

```bash theme={null}
yarn start
```

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.

## Related resources

* [Marrow introduction](https://www.marrow.com/hub/docs/basics/introduction-to-marrow)
* [Marrow MCP Overview](/hologrow-marrow-mcp/overview)
* [Claude Agent SDK](https://www.anthropic.com/claude)

## Marrow MCP resources

Check the following resources for more information:

* MCP server URL: `https://mcp.marrow.com/mcp/v1`
* [Interactive Data Scheme](/hub/data-scheme)
* Data Scheme JSON: [https://api.marrow.com/api/v1/spec/data-scheme](https://api.marrow.com/api/v1/spec/data-scheme)
* Need help? Use the [contact form](https://forms.clickup.com/9015200219/f/8cnj2ev-38615/AOYF9I35QFOXWJQXIG?type=Form\&source=hub-mcp-claude-agent-sdk-docs)
