Lewati ke konten utama

MCP Reference

HMG exposes memory tools to agents via MCP (Model Context Protocol). Tool names in the host look like mcp__hmg__memory_memorize (mcp__<server>__<tool>).

Overview

ToolPurposeRequired fields
memory_memorizeWrite one memorycontent
memory_recallSearch memoriesquery
memory_correctCorrect one memorytarget_atom, action, reason
memory_governGovern the lifecycle of one memorytarget_atom, action, reason
memory_handoffSession handoff summarysummary
memory_statsStore overview(none)

Capabilities not exposed as MCP tools: agent_brief (internal to the SessionStart hook), observation_* (not activated in agent integration), history / export (SDK layer only, see SDK Reference).

General conventions

  • The agent never passes scope. For every tool, scope is mechanically inferred from the session directory and injected by the PreToolUse hook (or inferred by the MCP server from its process working directory); scope passed by the agent is overridden.
  • Certainty and polarity are inferred automatically. epistemic (fact/constraint/guess) and polarity (positive/negative/conditional) are inferred from wording — not input parameters.
  • Automatic redaction on write. Structured sensitive information (connection strings, password=xxx, Bearer tokens, private key blocks) is auto-redacted at memorize time; sensitive content in natural language is not auto-detected — avoid writing it.
  • Exact dedup. Writing identical content never creates a second atom (effect: "no_op").

ScopeInput (shared)

All tools share the same optional scope field structure (the agent never passes it):

json
{
"tenant_id": "qiankun",
"workspace": "HMG-AI",
"repository": "HMG-DEV-brach",
"branch": "main"
}
FieldDescription
tenant_idTenant, the OS username, read by HMG from the store config
workspaceWorkspace, usually the git remote owner
repositoryRepository name
branchBranch

memory_memorize

Write one long-term memory.

Input

FieldTypeRequiredDescription
contentstringyesMemory content, one self-contained sentence
sourcestringnoSource attribution: user (said by the user, more authoritative) / agent (concluded by the agent) / custom
scopeScopeInputnoInjected by hooks automatically — the agent doesn't pass it

Output

FieldDescription
atom_idULID of the atom (dedup hits return the existing atom's ID)
effectapplied (created) / no_op (dedup hit) / rejected (admission blocked)
reasonReason for dedup/rejection (not returned when applied)
deduped_withExisting atom ID on dedup hit (no_op only)

Example

json
{
"content": "This project uses PostgreSQL 16 as the primary database, not MongoDB, because we need transactions and complex queries",
"source": "user"
}

Notes

  • No need to recall for duplicates first — HMG deduplicates exactly, automatically
  • If a semantically close memory is already visible in the current context, update it with memory_correct (replace) instead of adding a new one
  • Memories are stored in the language of the current conversation

memory_recall

Search memories in natural language.

Input

FieldTypeRequiredDescription
querystringyesSearch query; noun phrases work best
max_resultsnumbernoMaximum results, default 10
include_negatedbooleannoInclude negated memories, default false
scopeScopeInputnoInjected by hooks automatically — the agent doesn't pass it

Output

FieldDescription
atomsResults sorted by relevance, descending
atoms[].atom_idAtom unique identifier for correct / govern
atoms[].contentMemory content (quarantined/sealed return a placeholder)
atoms[].scoreRelevance score, 0.0 ~ 1.0
atoms[].created_atCreation time (RFC 3339)
atoms[].sourceSource attribution

Example

json
{ "query": "PostgreSQL connection pool configuration" }

Notes

  • Use noun phrases with key names (people, projects, technologies, files); avoid conversational questions
  • One recall is usually enough — HMG already retrieves from semantic, keyword, and graph angles internally

memory_correct

Correct one memory. Append-only: old content stays in the audit chain, history is never lost.

Input

FieldTypeRequiredDescription
target_atomstringyesAtom ID to correct (from recall results)
actionstringyesSee action table below
reasonstringyesCorrection reason, written to the audit chain
new_contentstringrequired for replaceNew content
scopeScopeInputnoInherits from the target atom by default — don't pass it

action values

ActionMeaningTypical scenario
negateMark false and disable"This memory is outdated/wrong"
confirm_actualConfirm as fact"Was uncertain, now confirmed"
confirm_necessaryConfirm as hard constraint"Not just a fact — a rule that must be followed"
demoteDemote to possible"Thought it was settled; it isn't"
replaceReplace with new content (new atom created, old kept in the evolution chain)"Content needs updating"

Output

FieldDescription
effectapplied / rejected
target_atomThe corrected atom ID
new_atom_idNew atom ID (replace only)
reasonRejection reason (rejected only)

Example

json
{
"target_atom": "01J9ZK8V3QX7N2M4R6T8W0YB1C",
"action": "replace",
"reason": "migrated to PostgreSQL in v3, old decision outdated",
"new_content": "The primary database is PostgreSQL 16, replacing the old MongoDB plan"
}

Notes

  • negate is not precisely reversible (no un-negate); recover from a wrong negate with replace
  • Wrong replace? Replace again on that same atom — guarantees exactly one active memory at any time

memory_govern

Govern the lifecycle of one memory (isolate, seal, retire, distill a lesson).

Input

FieldTypeRequiredDescription
target_atomstringyesAtom ID to govern
actionstringyesquarantine / seal / tombstone / derive_lesson
reasonstringyesGovernance reason, written to the audit chain
lesson_contentstringrequired for derive_lessonRedacted lesson distilled from the original
scopeScopeInputnoInherits from the target atom by default — don't pass it

action values

ActionMeaning
quarantineQuarantine: hidden from recall, content kept, recoverable
sealSeal: audit-only
tombstoneTombstone: logical deletion, content destroyed by default
derive_lessonDistill a redacted lesson (new atom), retire the original

Output

FieldDescription
effectapplied / rejected
target_atomThe governed atom ID
lesson_atom_idLesson atom ID (derive_lesson only)
reasonRejection reason (rejected only)

Example

json
{
"target_atom": "01J9ZK8V3QX7N2M4R6T8W0YB1C",
"action": "derive_lesson",
"reason": "original contains a leaked API key",
"lesson_content": "Never hardcode API keys in code or memory; use environment variables"
}

Notes

  • Sensitive info written by mistake: derive_lesson when a lesson is worth keeping, otherwise seal or tombstone
  • tombstone destroys content by default — no extra flag needed

memory_handoff

Write a session handoff summary. A handoff is a special memory: the startup brief of the next session recalls it with priority.

Input

FieldTypeRequiredDescription
summarystringyesHandoff summary; recommended coverage: what changed / why / validation / risks / next steps (format free)
sourcestringnoSource attribution
scopeScopeInputnoInjected by hooks automatically — the agent doesn't pass it

Output

FieldDescription
atom_idULID of the handoff atom
effectapplied / rejected
reasonRejection reason (rejected only)

Example

json
{
"summary": "Fixed the null pointer in login.py. Root cause: get_session() returns None when the session expires; added a validity check at line 38, pytest passes. Risk: possible race on session refresh under concurrency. Next: add integration tests for the session module.",
"source": "agent"
}

Notes

  • When to call: task end, milestone reached, session about to end
  • Division of labor with memorize: memorize stores single incremental facts; handoff stores the whole-task handoff

memory_stats

Store overview. Mostly used internally by the SessionStart hook (empty store → onboarding flow); agents rarely need it in normal workflows.

Input: none.

Output

FieldDescription
atomsTotal memory atoms
edgesTotal graph edges
indexesCoverage per index (semantic / keyword / temporal / categorical)
snapshot_versionCurrent snapshot version, increments on every write

Previous: CLI Reference · Next: SDK Reference