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

# CrewAI

> Save an explicit project note and recall its confirmed ID with a native CrewAI Flow and the existing local MCP server.

The [CrewAI example](https://github.com/thedotmack/claude-mem/tree/main/examples/crewai)
uses CrewAI's native `Flow`, `MCPClient`, and `StdioTransport`. One flow step
saves the caller's handoff; the next retrieves that known observation through
project-scoped search, timeline, and detail tools. It runs without a model key.

## Capabilities and verified versions

| Capability | This example |
| - | - |
| Explicit save | Stores only the handoff text supplied by the caller |
| Recall | Displays a recent project index, then fetches the confirmed saved ID's timeline and details |
| Flow identity | Records CrewAI's actual flow UUID and the caller's logical run ID as note metadata |
| Claude-Mem attribution | Existing manual session for the project and `crewai` platform |
| Automatic capture or injection | Not provided; no transcript hooks or model calls are installed |
| Account | No CrewAI cloud, model-provider, or CMEM Pro account is needed for this local example |

Verified on Linux with Python **3.12.14**, CrewAI **1.15.39**, MCP Python SDK
**1.30.0**, and Claude-Mem **15.17.0**. macOS, Windows, AMP/cloud deployment,
remote authenticated MCP, and a model choosing tools were not verified. This is
a deterministic Flow, without CrewAI's separate memory or embedding subsystem.

## Connect to the local worker

You need Node.js, Python 3.11 or later, an installed Claude-Mem MCP script, and
a running local worker. From a Claude-Mem checkout:

```bash theme={null}
python -m venv .venv-crewai-memory
. .venv-crewai-memory/bin/activate
python -m pip install -r examples/crewai/requirements.txt
export CLAUDE_MEM_MCP_SERVER="/absolute/path/to/claude-mem/plugin/scripts/mcp-server.cjs"
npm run worker:status
```

Start the worker with `npm run worker:start` if it is stopped. Select your trusted
installed MCP script, or the shipped script in this checkout. If you use a custom
`CLAUDE_MEM_DATA_DIR` or `CLAUDE_MEM_WORKER_PORT`, set the same values for the
example. Paths are passed as individual process arguments, including paths with
spaces.

The MCP child uses local worker mode with autostart disabled. The example adds no
hooks or MCP configuration and does not alter worker settings. Repeating setup
creates no duplicate installation entries.

## Save and recall a handoff

```bash theme={null}
python examples/crewai/memory_workflow.py \
  --project shop-api \
  --run-id scheduler-handoff-1 \
  --note "Keep the quokkaharbor scheduler export in UTC."
```

The `@start()` method saves the supplied note and requires a confirmed observation
ID. The `@listen(remember)` method then shows a recent project index and recalls
that ID's timeline and details. Every tool call receives the fixed project chosen
by the caller. Returned text cannot choose a different project or tool, or
authorize another save.

Successful output includes `saved_id`, `recalled`, and the native `flow_id`.
Repeating the command with the same project, run ID, and note returns the same
saved ID. The receipt remains the recall target even if newer notes have pushed
it outside the recent 20-result index.

## Native client and flow

The example keeps one native MCP client connected while the Flow runs:

```python theme={null}
async with MCPClient(
    StdioTransport(command="node", args=[script], env=worker_env),
    connect_timeout=10,
    execution_timeout=10,
    discovery_timeout=10,
    max_retries=1,
) as client:
    flow = MemoryFlow(
        initial_state=MemoryState(project=project, note=note, run_id=run_id),
        client=client,
        tracing=False,
        suppress_flow_events=True,
        memory=None,
    )
    result = await flow.kickoff_async()
```

For this pinned CrewAI version, `max_retries=1` means one attempt, without a retry.
The client discovers the worker's tools and the Flow calls only `save_memory`,
`search`, `timeline`, and `get_observations`. It uses `call_tool_result()` because
`call_tool()` returns text without the MCP error flag. A failed MCP result is
rejected before its content is used.

Claude-Mem stores the note through its existing manual-memory contract with
`platformSource: "crewai"`, `runId`, and `crewaiFlowId` metadata. The flow UUID is
generated by CrewAI. A new invocation creates a new Flow; a deliberate duplicate
save returns the original observation and retains its original provenance.
The logical run ID and note content determine the receipt fingerprint. Neither
identity resumes inference or replays a conversation.

## Worktree project boundaries

Reads send both the selected `project` and an explicit `projects=json.dumps([project])`
list. This prevents the MCP server from automatically widening a worktree's
read scope to its parent checkout. `save_memory` receives only the selected
`project`.

The native tests create a real Git repository and linked worktree, seed a
parent-project observation, and run the SDK from that worktree. The chosen
project's index and timeline exclude the parent record; an explicit detail read
of its known ID also returns no parent content.

The project list is encoded as a JSON string so the GET query path preserves
literal commas and JSON-looking keys. Nonempty project names retain their exact
outer whitespace. Native checks seed separate split/trimmed-key projects and
confirm they stay out of search, timeline, and recalled details.

## Repeated runs and failures

The source fingerprint includes the integration, project, run ID, and note text.
The worker's existing receipt prevents duplicate storage on deliberate repeats.
Changing the note represents a new explicit save. There are no automatic write
retries. If a timeout makes the outcome uncertain, inspect the viewer or repeat
with the same run ID and text after checking the worker.

Connection, discovery, and tool calls each have a 10-second deadline. An
80-second outer deadline covers the client, Flow, and cleanup. A missing script,
blank project, stopped worker, rejected tool call, or deadline gives a nonzero
CLI exit and a short diagnostic. A failed recall after a confirmed save does not
undo that save; the example reports overall failure without claiming completion.

## Real-client verification

With Bun and Node.js available, run:

```bash theme={null}
(
  unset CLAUDE_MEM_CLOUD_SYNC_TOKEN CLAUDE_MEM_CLOUD_SYNC_USER_ID CLAUDE_MEM_CLOUD_SYNC_HUB_URL
  export CLAUDE_MEM_MEDIA_CAPTURE_ENABLED=false
  python examples/crewai/test_workflow.py
)
```

This verification uses fresh worker settings and a restricted child-process
environment. It imports the shipped `WorkerService` and calls `start()` directly,
so the CLI startup path does not run host hook-configuration repairs. The
subshell also clears inherited cloud-sync credentials; it does not change your
normal worker's settings or saved memory.

The nine checks use the actual CrewAI Flow and MCP client, the shipped worker,
and a fresh SQLite database. They cover save and recall, a repeated receipt after
25 newer notes, project isolation, platform/manual-session/native-flow identity,
an actual rejected MCP save, blank input, a stopped worker, telemetry settings,
and a bounded slow save with exactly one request. The slow HTTP endpoint is a
fault fixture; successful writes and recall use the real worker.

The verified run saved observation `3`, recalled its supplied text, and returned
`3` again after 25 newer notes. Its disposable data path contained spaces. No
model request or model key was used.

## Data and disconnect

Before importing CrewAI, this standalone script sets `OTEL_SDK_DISABLED=true`
and `CREWAI_TRACING_ENABLED=false`. These are separate controls: disabling
telemetry alone does not disable CrewAI tracing. The Flow also sets
`tracing=False`. The native console formatter is quiet so MCP argument panels
do not print the supplied note; the final requested recall remains CLI output.
When embedding this example, apply those choices before your application's
CrewAI imports and choose deliberately where final output is retained.

Only the explicit note, project, selected IDs, and provenance metadata enter the
local memory path. No model or additional memory service receives them from this
script. Existing worker sync and export settings still apply to saved notes.
Use a trusted local worker: project filtering is not multiuser authentication.
Save only text intended for retention. No excluded transcripts or prior
conversations are collected and no privacy settings are changed in the worker.

Stop running the example or remove it from your application to disconnect. The
client's async context closes its MCP child after the run. You may remove the
dedicated virtual environment; no worker configuration or memory is deleted.

## Official references

* [CrewAI 1.15.39 Flows](https://docs.crewai.com/v1.15.39/en/concepts/flows)
* [CrewAI 1.15.39 stdio MCP guidance](https://docs.crewai.com/v1.15.39/en/mcp/stdio)
* [Native MCP client implementation](https://github.com/crewAIInc/crewAI/blob/main/lib/crewai/src/crewai/mcp/client.py)
* [Claude-Mem search workflow](https://docs.claude-mem.ai/usage/search-tools.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.