agentcore-memory-mcp
# agentcore-memory-mcp
An [MCP](https://modelcontextprotocol.io) server that gives AI agents long-term
memory stored in [Amazon Bedrock AgentCore Memory](https://docs.aws.amazon.com/bedrock-agentcore/).
Every agent or machine that points at the same memory shares what it knows.
It supports two ways to save memory:
- **Exact text** (`memory_store`): your words are stored unchanged, with optional tags.
- **Extracted memory** (`memory_store_session`): you send a conversation, and AgentCore
turns it into facts, user preferences and a session summary in the background.
## Tools
| Tool | What it does |
|---|---|
| `memory_store(content, conversation_id, metadata)` | Saves text exactly as written. Tags go in `metadata.tags`. |
| `memory_store_session(turns, session_id)` | Sends a chat for background extraction. Takes about a minute to appear. |
| `memory_search(query, tags, after, before, limit, memory_type)` | Semantic search, best match first. |
| `memory_list(page, page_size, tags, memory_type)` | Lists memories, newest first. |
| `memory_delete(content_hash, tags, tag_match, before, after, dry_run)` | Deletes by id or by filter. At least one filter is required. |
| `memory_update(content_hash, updates, preserve_timestamps)` | Changes the text and/or tags. |
`content_hash` is the AgentCore record id. `memory_type` is `facts`, `prefs`,
`summaries` or `manual` (the exact-text records). Every tool replies with JSON, and
bad input comes back as `{"error": "..."}` and not as an exception.
## Setup
You need Python 3.12 or newer and AWS credentials that can use AgentCore Memory.
1. Install:
```
pip install -e .
```
2. Create the memory once. `infra/memory.json` defines three strategies (facts,
summaries, preferences) and their namespaces:
```
aws bedrock-agentcore-control create-memory --cli-input-json file://infra/memory.json
```
Wait until `aws bedrock-agentcore-control get-memory --memory-id <id>` shows `ACTIVE`.
Note the memory id and the id of the `facts` strategy from its output.
3. Configure the server with environment variables:
| Variable | Required | Meaning |
|---|---|---|
| `AGENTCORE_MEMORY_ID` | yes | Id from step 2 |
| `AGENTCORE_FACTS_STRATEGY_ID` | yes | Id of the `facts` strategy |
| `AGENTCORE_ACTOR_ID` | yes | Who the memories belong to: letters, digits, `_`, `-` |
| `AWS_REGION` or `AGENTCORE_REGION` | yes | Region of the memory |
| `AGENTCORE_NAMESPACE_ROOT` | no | Default `/memory`. Must match `infra/memory.json`. |
4. Register it with your MCP client. See `examples/mcp_config.json`.
## How it stores things
- An AgentCore record has no tag field and allows only one namespace. Tags on exact-text
records are kept in a `[tags: a, b]` footer in the stored text, and removed when read.
- Exact-text records live under `<root>/facts/<actor>/manual`, so searching `facts`
finds them too.
- Reads are eventually consistent for a few seconds after a write.
- `memory_list` and bulk delete read every record. They raise an error past 20,000
records and do not silently truncate. Use `memory_type` or tags to narrow.
## Permissions
The server needs these actions on the memory resource: `CreateEvent`,
`RetrieveMemoryRecords`, `ListMemoryRecords`, `GetMemoryRecord`,
`BatchCreateMemoryRecords`, `BatchUpdateMemoryRecords` and `DeleteMemoryRecord`
(prefix each with `bedrock-agentcore:`). Check the names against the AWS service
authorization reference before you write a policy. Grant only these on the one memory.
Do not store secrets or regulated data in the memory unless your own policies allow it.
The actor id is part of every namespace path, so use a different actor id for each
person who shares a memory.
## Costs
AgentCore Memory is a paid AWS service, and extraction uses a model. Check current
pricing, and set an AWS Budget before you load data.
## Development
```
pip install -e ".[dev]"
pytest -q # offline, uses a fake AWS API
mypy --strict src
black --check src tests examples
```
`examples/live_smoke.py` runs the whole tool set against a real memory. It writes one
record and deletes it.
## Limits
- No export, import or deduplication tools.
- One memory and one actor per server process.
- Semantic search quality and extraction behavior come from AgentCore, not this code.
## License
MIT. See `LICENSE`.
TDQS
Scored across 6 tools
Each tool maps to a distinct operation (store raw, store from session, search, list, delete, update), and the descriptions explicitly disambiguate the closest pair (memory_store vs memory_store_session). The only residual confusion is memory_list vs memory_search for retrieval and how memory_update identifies its target.
All names follow the same memory_<verb> snake_case convention with a consistent shared prefix. memory_store_session is a natural extension rather than a deviation.
Six tools is well-scoped for a memory service: write paths, read paths, mutation, and deletion. No obviously redundant or missing surface-level tool.
The lifecycle is essentially covered: store, ingest session, search, list, update, delete (with dry_run). Minor gaps: memory_update does not state how the target memory is identified, and there is no dedicated get-by-hash tool, though search/list partially compensate.