The open protocol for governed memory in AI systems.
English ยท ็ฎไฝไธญๆ ยท Documentation ยท Getting Started
MGP standardizes how AI runtimes write, recall, govern, and audit persistent memory across heterogeneous backends. Think of it as a unified contract layer โ your agent talks to one protocol, and any compliant memory backend just works.
Current protocol version: v0.1.1
MCP standardizes tools and resources. MGP standardizes governed memory. They are peer protocols โ complementary, not competing.
flowchart LR
subgraph runtime ["๐ค Agent Runtime"]
sdk[Python SDK]
sidecar[Sidecar Bridge]
end
subgraph gateway ["๐ MGP Gateway"]
api[API Layer]
policy[Policy Hook]
audit[Audit Sink]
router[Adapter Router]
end
subgraph adapters ["๐งฉ Adapters"]
mem[In-Memory]
file[File]
graphAdapter[Graph]
pg[PostgreSQL]
ob[OceanBase]
lance[LanceDB]
ext["Mem0 / Zep"]
end
sdk --> api
sidecar --> api
api --> policy
api --> audit
api --> router
router --> mem
router --> file
router --> graphAdapter
router --> pg
router --> ob
router --> lance
router --> ext
| ๐ One Protocol, Any Backend | Write once, connect to in-memory, file, graph, relational, vector, or managed memory services |
| ๐ Governance Built-In | Every request carries policy context โ who acts, for whom, under what constraints |
| ๐ Full Lifecycle | Write โ Search โ Get โ Update โ Expire โ Revoke โ Delete โ Purge โ each with distinct semantics |
| ๐ Audit Trail | Every state transition is recorded. Query the audit log through the protocol itself |
| ๐งฉ Pluggable Adapters | Ship your own adapter or pick from 8 reference implementations |
| ๐ค Peer to MCP | Complements MCP โ use MCP for tools, MGP for memory, both in the same runtime |
| โ Compliance Suite | Machine-verifiable conformance profiles: Core, Lifecycle, Interop, ExternalService |
| ๐ Schema-Driven | 60+ JSON Schemas + OpenAPI spec โ validate everything, guess nothing |
Get a governed memory gateway running in under 2 minutes:
git clone https://github.com/hkuds/MGP.git
cd MGP
make install # creates .venv/ and installs everything
make serve # starts the gateway at http://127.0.0.1:8080Verify it's running:
curl http://127.0.0.1:8080/mgp/capabilitiesWrite your first memory:
curl -X POST http://127.0.0.1:8080/mgp/write \
-H "Content-Type: application/json" \
-d '{
"request_id": "req_001",
"policy_context": {
"actor_agent": "my-agent/v1",
"acting_for_subject": {"kind": "user", "id": "user_alice"},
"requested_action": "write",
"tenant_id": "my_tenant"
},
"payload": {
"memory": {
"memory_id": "mem_001",
"subject": {"kind": "user", "id": "user_alice"},
"scope": "user",
"type": "preference",
"content": {
"statement": "User prefers dark mode.",
"preference_key": "theme",
"preference_value": "dark"
},
"source": {"kind": "human", "ref": "chat:1"},
"sensitivity": "internal",
"created_at": "2026-01-01T00:00:00Z",
"backend_ref": {"tenant_id": "my_tenant"},
"extensions": {}
}
}
}'Search it back:
curl -X POST http://127.0.0.1:8080/mgp/search \
-H "Content-Type: application/json" \
-d '{
"request_id": "req_002",
"policy_context": {
"actor_agent": "my-agent/v1",
"acting_for_subject": {"kind": "user", "id": "user_alice"},
"requested_action": "search",
"tenant_id": "my_tenant"
},
"payload": {
"query": "dark mode",
"limit": 10
}
}'Or use the Python SDK:
from mgp_client import MGPClient, PolicyContextBuilder, SearchQuery
ctx = PolicyContextBuilder(
actor_agent="my-agent/v1",
subject_id="user_alice",
tenant_id="my_tenant",
)
with MGPClient("http://127.0.0.1:8080") as client:
client.write_memory(
ctx.build("write"),
{
"memory_id": "mem_001",
"subject": {"kind": "user", "id": "user_alice"},
"scope": "user",
"type": "preference",
"content": {"statement": "User prefers dark mode."},
"source": {"kind": "human", "ref": "chat:1"},
"created_at": "2026-01-01T00:00:00Z",
"backend_ref": {"tenant_id": "my_tenant"},
"extensions": {},
},
)
results = client.search_memory(
ctx.build("search"),
SearchQuery(query="dark mode", limit=10),
)
for item in results.data.get("results", []):
print(item["consumable_text"])๐ For the complete walkthrough โ including update, expire, and audit โ see the Getting Started Guide.
MGP/
โโโ spec/ # ๐ Protocol semantics โ the source of truth
โโโ schemas/ # ๐ 60+ JSON Schemas for all protocol objects
โโโ openapi/ # ๐ OpenAPI definition (HTTP binding)
โโโ reference/ # โ๏ธ Python reference gateway (FastAPI)
โโโ adapters/ # ๐งฉ Backend adapter implementations
โโโ sdk/python/ # ๐ฆ MGPClient + AsyncMGPClient + helpers
โโโ compliance/ # โ
Executable conformance test suite
โโโ integrations/ # ๐ Runtime bridges (Nanobot, LangGraph, minimal)
โโโ examples/ # ๐ก Runnable end-to-end demos
โโโ docs/ # ๐ MkDocs documentation site (EN + ZH)
| Adapter | Backend | Profile | Use Case |
|---|---|---|---|
| In-Memory | Process memory | Reference | Testing & development |
| File | JSON files | Reference | File-native workflows |
| Graph | SQLite | Reference | Relationship semantics |
| PostgreSQL | PostgreSQL | Production | Relational backends |
| OceanBase | OceanBase / oceanbase/seekdb |
Production | MySQL-compatible relational backend |
| LanceDB | LanceDB | Production | Vector / hybrid search |
| Mem0 | Mem0 service | External | Managed memory |
| Zep | Zep service | External | Graph-native memory |
Reference adapters are for protocol verification and learning. For production, use the PostgreSQL / OceanBase / LanceDB baselines or build your own.
| Dimension | MCP | MGP |
|---|---|---|
| Focus | Tools & resource connectivity | Governed persistent memory |
| Protocol surface | Tool invocation, resource discovery | Memory CRUD, policy, audit, lifecycle |
| Data model | Tools, prompts, resources | Memory objects, candidates, recall intents |
| Governance | Not in scope | Policy context, access control, retention |
| Audit | Not in scope | Built-in audit trail & lineage |
| Relationship | Peer protocol | Peer protocol |
One-line heuristic: Use MCP for action, use MGP for memory.
Both can coexist in the same runtime โ call a calendar tool via MCP, remember the user's scheduling preferences via MGP.
๐ Deep dive: MGP vs MCP
Choose your path:
| You are... | Start here |
|---|---|
| ๐ ๏ธ Runtime developer | Getting Started โ Python SDK โ Sidecar Integration |
| ๐ข Platform engineer | Reference Implementation โ Deployment Guide โ Security Baseline |
| ๐ Protocol implementer | Protocol Reference โ Schema Reference โ Spec Index |
| ๐งฉ Adapter author | Adapter Guide โ Adapters Overview โ Compliance Suite |
Core operations:
WriteMemory ยท SearchMemory ยท GetMemory ยท UpdateMemory
ExpireMemory ยท RevokeMemory ยท DeleteMemory ยท PurgeMemory
BatchWrite ยท AuditQuery
Discovery & lifecycle:
GET /mgp/capabilities ยท POST /mgp/initialize
Export ยท Import ยท Sync ยท Task polling & cancellation
Operational:
GET /healthz ยท GET /readyz ยท GET /version
We welcome contributions! See CONTRIBUTING.md for the development workflow.
make install # set up the dev environment
make lint # contract validation + code quality
make test-all # compliance suite on all reference adapters
make docs-build # verify documentation buildsMGP is released under the MIT License.