Skip to content

HKUDS/MGP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

24 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿง  MGP โ€” Memory Governance Protocol

The open protocol for governed memory in AI systems.

Protocol License: MIT CI Docs Python 3.11+

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.

๐Ÿ—๏ธ Architecture

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
Loading

โœจ Why MGP?

๐Ÿ“ 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

๐Ÿš€ Quick Start

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:8080

Verify it's running:

curl http://127.0.0.1:8080/mgp/capabilities

Write 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.

๐Ÿ“‚ Repository Map

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 Ecosystem

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.

โš–๏ธ MGP vs MCP

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

๐Ÿงญ Where to Start

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

๐Ÿ”ฌ Protocol Surface

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

๐Ÿค Contributing

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 builds

๐Ÿ“„ License

MGP is released under the MIT License.

About

Memory Governance Protocol

Resources

Contributing

Security policy

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages