Skip to main content
Glama
Riku-KANO

mem9-guard-mcp

by Riku-KANO

mem9-guard-mcp

An MCP server that exposes mem9 (the TiDB team's persistent memory backend for AI agents) behind OWASP agent-memory-guard.

Agents never touch the raw mem9 API — every read and write goes through the guard:

MCP client (agent)
        │  memory_read / memory_write / ...
        ▼
  mem9-guard-mcp (this server)
        │  MemoryGuard + Policy.strict()   ← inspect, then block / quarantine / redact
        ▼
  Mem9Store adapter (MemoryStore Protocol)
        │  REST (X-API-Key)
        ▼
      mem9 (api.mem9.ai or self-hosted)

This protects agent memory against prompt injection, secret leakage, and memory poisoning: malicious or sensitive content is blocked, quarantined, or redacted according to policy before it ever reaches — or returns from — the store.

Tools

Tool

Description

memory_write(key, value, source_class, memory_class)

Guarded write. Result is allow / redact / quarantine / blocked

memory_read(key, default)

Read with integrity verification and outbound screening

memory_delete(key)

Delete a key (protected keys are blocked)

memory_list()

List stored keys

security_events(limit)

Recent security events emitted by the guard (for auditing)

quarantine_list()

Writes currently held in quarantine

rollback / snapshot restore is intentionally not exposed. Recovery is an operator action; giving it to agents would let them discard legitimate writes or cover up poisoned data.

Related MCP server: ContextHub

Configuration (environment variables)

Variable

Description

MEM9_API_KEY

mem9 API key. Falls back to a local JSON store when unset

MEM9_API_URL

Defaults to https://api.mem9.ai. Override for self-hosted mem9

MEM9_AGENT_ID

X-Mnemo-Agent-Id header (optional)

MEM9_GUARD_POLICY

Path to a policy YAML. Defaults to Policy.strict()

MEM9_GUARD_LOCAL_PATH

Path of the fallback JSON store (default mem9_local_store.json)

Installing into Claude Code

Straight from GitHub (no clone needed — uvx fetches and builds on first run):

claude mcp add mem9-guard \
  --env MEM9_API_KEY=<your-key> \
  -- uvx --from git+https://github.com/Riku-KANO/mem9-guard-mcp mem9-guard-mcp

Or from a local clone (recommended while developing):

claude mcp add mem9-guard \
  --env MEM9_API_KEY=<your-key> \
  -- uv run --project <path-to-this-repo> mem9-guard-mcp

Notes:

  • MEM9_API_KEY is optional — omit the --env line to use the local JSON store fallback.

  • The server is registered for the current project by default; add --scope user to make it available in every project.

  • For self-hosted mem9, add --env MEM9_API_URL=<url>.

  • Verify with claude mcp list, or run /mcp in a new session to see the memory_write / memory_read / ... tools.

Other MCP clients

Any MCP client that supports stdio servers works, e.g.:

{
  "mcpServers": {
    "mem9-guard": {
      "command": "uvx",
      "args": ["--from", "git+https://github.com/Riku-KANO/mem9-guard-mcp", "mem9-guard-mcp"],
      "env": { "MEM9_API_KEY": "<your-key>" }
    }
  }
}

Development

uv sync
uv run pytest

# End-to-end smoke test over stdio (no LLM involved)
uv run python scripts/smoke_stdio.py

Notes

The mem9 v1alpha2 JSON field names (content / metadata / id) are not yet covered by a published official schema, so they are centralized as assumptions in src/mem9_guard_mcp/client.py. If the real API differs, that is the only file that needs to change.

License

MIT

Available Tools

6 tools
memory_deleteC

Delete a key from guarded mem9 memory. Protected keys cannot be deleted.

ParametersJSON Schema
NameRequiredDescriptionDefault
keyYes

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

C2.7/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full transparency burden. It mentions the protected keys constraint but omits side effects, error cases (e.g., key not found), authorization needs, and the meaning of 'guarded' memory.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences are concise, but the structure lacks organization. The content is front-loaded with the action, but the brevity sacrifices necessary details.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Even with an output schema, the description fails to explain successful deletion behavior, error conditions, or the 'guarded' concept. For a delete operation with one parameter, more completeness is expected.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The single parameter 'key' has 0% schema description coverage and the description adds no information about its format, source, or allowed values. The agent must infer meaning from the tool name alone.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description clearly states the action (delete a key) and the resource (guarded mem9 memory), distinguishing it from sibling tools like memory_list and memory_write.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance on when to use this tool vs. alternatives (e.g., memory_write or quarantine_list). The only usage hint is the constraint 'Protected keys cannot be deleted,' but this is a behavioral limitation, not a decision guide.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

memory_listA

List all keys currently stored in guarded mem9 memory.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A4.3/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Without annotations, the description carries the full burden. It states it lists keys from 'guarded mem9 memory', hinting at security context. The operation is simple and read-only, so transparency is adequate.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single clear sentence with no wasted words. It is front-loaded and efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no parameters and the existence of an output schema, the description sufficiently explains the tool's purpose. It does not need to detail return values as those are covered by the output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

There are no parameters, and schema coverage is 100%. With zero parameters, the baseline is 4, and the description adds no parameter info but doesn't need to.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly specifies the verb 'list' and the resource 'keys in guarded mem9 memory'. It distinguishes from sibling tools like memory_delete, memory_read, and memory_write, which perform different operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for listing stored keys but does not explicitly state when to use this tool versus alternatives. No guidance on when not to use it is provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

memory_readB

Read a value from guarded mem9 memory.

Reads run integrity verification and outbound screening; sensitive content may come back redacted, and tampered or policy-violating entries are blocked.

ParametersJSON Schema
NameRequiredDescriptionDefault
keyYes
defaultNo

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

B3.2/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description effectively discloses key behaviors: integrity verification, outbound screening, potential redaction of sensitive content, and blocking of tampered/policy-violating entries. This helps the agent understand side effects and constraints beyond a simple read.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise at two sentences, with the primary action in the first sentence. Every sentence adds value, and there is no redundant or irrelevant information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description adequately covers behavioral aspects, but given the low schema coverage and zero parameter explanations, it feels incomplete. The existence of an output schema partially compensates for missing return value details, but parameter semantics are lacking, which reduces overall completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, and the description provides no explanation for the 'key' and 'default' parameters. The purpose of 'default' (return value when key is missing) is not mentioned, leaving the agent to infer from the schema alone.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Read a value') and the target resource ('guarded mem9 memory'). It is specific enough to understand the primary function, but does not differentiate from sibling tools like memory_list, which also reads memory in a different way.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

There is no guidance on when to use this tool versus alternatives. The description explains behavior during reads (integrity verification, redaction, blocking) but does not explicitly state when to choose memory_read over memory_list or other sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

memory_writeA

Write a value to guarded mem9 memory.

The value is screened by agent-memory-guard before persisting; the result may be
allow / redact / quarantine / block. Declare provenance honestly via source_class
(user_input | external_tool | agent_authored | system) — it drives self-poisoning
detection. Optionally classify with memory_class (e.g. "ephemeral").
ParametersJSON Schema
NameRequiredDescriptionDefault
keyYes
valueYes
source_classNoagent_authored
memory_classNo

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A3.9/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Provides good behavioral context: explains that values are screened by agent-memory-guard with possible outcomes (allow/redact/quarantine/block), mentions self-poisoning detection driven by source_class, and describes optional memory_class. Since annotations are absent, the description carries the full burden and does so effectively.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise—three sentences—with the main action front-loaded. Every sentence earns its place, providing key details without fluff.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Covers behavioral traits like screening and provenance, but does not address return values, error handling, or constraints on key/value (e.g., length, format). An output schema exists but is not shown; given no annotations, some gaps in completeness remain.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It lists possible values for source_class and gives an example for memory_class, adding meaning beyond schema titles. However, key and value parameters are not described; their roles must be inferred. The description adds value but leaves important gaps.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states 'Write a value to guarded mem9 memory', which is a specific verb and resource. It distinguishes itself from sibling tools like memory_delete, memory_list, memory_read, which are obviously different operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance on when to use this tool versus alternatives. The description implies it is for storing values, but does not mention when not to use or compare with other memory tools. Usage context is left to inference.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

quarantine_listA

List writes currently held in quarantine (detected anomalies pending review).

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It states the tool lists quarantined writes pending review but fails to disclose any behavioral traits such as pagination, ordering, or whether the list is ordered by time. It does not contradict any annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, concise sentence that front-loades the main purpose with no extraneous words. Every word earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has zero parameters and an output schema exists (per context signals), the description is reasonably complete for a simple list operation. However, it could mention ordering or whether pagination is supported.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has zero parameters, so per the guidelines baseline is 4. Schema coverage is trivially 100%. The description adds no parameter info, but none is needed.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'List' and the resource 'writes currently held in quarantine', specifying the scope (detected anomalies pending review). This effectively distinguishes it from sibling tools like memory_list or security_events.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for reviewing quarantined writes but provides no explicit guidance on when to use versus alternatives, nor any exclusion criteria. Context from sibling tools (e.g., security_events) is not referenced.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

security_eventsA

Return recent security events emitted by the guard (newest first).

Useful for auditing why a write was blocked, redacted, or quarantined.

ParametersJSON Schema
NameRequiredDescriptionDefault
limitNo

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A4/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden. It indicates a read-only operation ('return recent...') and implies no side effects. The ordering and use case are clear, but there is no explicit mention of safety (e.g., non-destructive), though the verb 'return' suggests safe behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise: two sentences with no wasted words. It front-loads the core action and provides a concrete use case, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has a simple schema (one optional param) and an output schema, the description is mostly complete for understanding the tool's purpose and basic behavior. However, it omits details about the limit parameter and does not explain the output format, relying on the output schema to fill gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has one optional parameter 'limit' with no schema description (0% coverage). The description does not mention this parameter or its effect on results. It fails to add meaning beyond the schema, which is insufficient given the low coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool returns recent security events from the guard, ordered newest first. It specifies the resource ('security events') and the action ('return'), and distinguishes from siblings like memory tools and quarantine_list by focusing on auditing logs for actions like blocking, redaction, or quarantine.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explains when to use the tool ('useful for auditing why a write was blocked...'), providing context. However, it does not explicitly state when not to use it or name alternative tools, though the sibling tools are distinct in purpose.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 6 tool updatesv0.1.0
    • First observedmemory_delete
    • First observedmemory_list
    • First observedmemory_read
    • First observedmemory_write
    • First observedquarantine_list
    • First observedsecurity_events

TDQS

A3.7/5.0

Scored across 6 tools

Disambiguation5/5

Each tool has a clear, distinct purpose: core memory operations (delete, list, read, write) plus quarantine and security events. No overlap ambiguity.

Naming Consistency4/5

Main tools follow a consistent 'memory_' prefix pattern. 'quarantine_list' and 'security_events' deviate slightly but are still descriptive and follow a sensible scheme.

Tool Count5/5

Six tools is an appropriate number for a guarded memory system, covering essential operations without being overwhelming.

Completeness4/5

Covers CRUD (memory_write as create/update, memory_read, memory_delete, memory_list) plus quarantine and security auditing. Missing an explicit update operation, but write can serve that role.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    C
    maintenance
    An MCP-native, local-first memory server that gives AI agents persistent, structured memory across sessions and tools, enabling them to maintain identity and context without reconfiguration.
    3
    MIT
  • A
    license
    A
    quality
    D
    maintenance
    An MCP server that provides persistent memory capabilities for AI agents using Mem0, enabling storage, search, and management of contextual information across conversations with support for multiple backends and LLM providers.
    18
    18 PyPI
    MIT