Integration

Memory for Claude Agent SDK agents

The Claude Agent SDK can connect MCP servers as tools. This page shows how to connect the Harny MCP server to a Claude Agent SDK agent.

Jump to the code

What the framework does not keep

  • Which value is current. Harny stores a changed value with its timestamp so the newest value is the current one and the earlier value stays answerable by date.
  • When a fact happened. You send a timestamp with each memory, set to when it happened. You can then ask what was true on a date with an as-of recall using queryTimestamp.
  • One person across sources. Harny gives each person one private memory that the app's AI can read.

The pattern: the Harny MCP server

The code block connects the Harny MCP server to the agent. The key in the header is a person's key (fsk_), which names its own user, so calls are scoped to that person.

Keep the key on your server and do not put it in a browser.

import os
from claude_agent_sdk import ClaudeAgentOptions, query

options = ClaudeAgentOptions(
    mcp_servers={
        "harny": {
            "type": "http",
            "url": "https://api.harny.ai/v1/mcp/mcp",
            "headers": {"Authorization": f"Bearer {os.environ['HARNY_USER_KEY']}"},  # the signed-in person's key, set by your application
        }
    },
    allowed_tools=["mcp__harny__assemble_context", "mcp__harny__ingest_text"],
)

async def ask(question: str):
    async for message in query(prompt=question, options=options):
        print(message)

What the tools return

With a bearer key, the server lists the tools that key may call. A person's key (starts with fsk_) reaches the memory tools for that person only.

  • assemble_context is the Recall Memory tool. It returns ranked context from the person's memory, scoped to that person.
  • ingest_text is the Ingest Memory tool. It writes a note or fact into that person's memory.
  • describe is available with any key.

When to use which

  • Use the SDK's own session state for the working context of a single run, such as the current task and the messages in the session.
  • Add Harny when a fact must persist across sessions, change over time, or be answered as of a past date for the same person.

Frequently asked questions

Is a package needed?

The page uses the Harny MCP server over Streamable HTTP, so the agent connects to a URL with a header. The code block shows the exact setup.

Where does the user id come from?

The key in the header is a person's key (fsk_), which names its own user, so you do not pass a user id per call.

Go on. Get Harny.

The first 500 monthly-active end users are free for good. Create an app key and make your first call in minutes.