HAM

HAM

Provides persistent, scoped shared memory for collaborating AI agents, with tools for storing observations, semantic recall, and handoff workflows. Backed by PostgreSQL and exposed through MCP.

Category
访问服务器

README

HAM - Shared Memory for Collaborating Agents

HAM is a PostgreSQL-backed memory service for agents working across sessions, repositories, projects, and tools. Text is encoded locally with deterministic Clifford/geometric encoders, so the core service does not require an embedding API or GPU.

The production model is deliberately simple:

Codex / Claude / Cursor / other MCP clients
  -> local stdio MCP bridge
  -> authenticated HAM HTTP API
  -> PostgreSQL + pgvector (canonical memory and provenance)

Each deployment can contain many tenants. Within a tenant, agents share memory through explicit scopes while preserving the originating agent, project, repo, task, thread, state, and version of every item.

Agent Workflows

The MCP bridge exposes:

  • ham_remember - store a scoped observation, fact, decision, preference, or note.
  • ham_recall - semantic and lexical search in the active collaboration context.
  • ham_recent - see recent work without having to invent a search query.
  • ham_changes - catch up from an ISO-8601 cursor.
  • ham_handoff - publish completed work, next steps, blockers, and touched files.
  • ham_get - fetch a complete memory with provenance and version.
  • ham_supersede - replace stale knowledge with optimistic concurrency.
  • ham_retract - mark incorrect knowledge inactive without deleting its history.
  • ham_reflect and ham_context - close and reopen working sessions.

Scopes are arbitrary lower-case labels such as shared, project:ham, repo:monumentalsystems/ham, or task:deploy. MCP clients should use the same tenant ID and distinct agent IDs.

Quick Start

Create .env from .env.example, generate strong values for HAM_DB_PASS and HAM_API_KEY, then run:

docker compose up --build -d
curl http://127.0.0.1:8042/health/ready

The Compose stack starts a private pgvector/pgvector:pg16 database and binds the API to 127.0.0.1:8042. The entrypoint creates the required vector, pg_trgm, and intarray extensions and applies all idempotent migrations in a serialized transaction.

To test an authenticated request:

curl -H "Authorization: Bearer $HAM_API_KEY" \
  -H "X-GB-User-ID: shared-team" \
  http://127.0.0.1:8042/stats

MCP Configuration

The stdio process is a thin bridge to the shared API. In normal shared-service mode it requires HAM_API_URL and does not need database credentials.

{
  "mcpServers": {
    "ham": {
      "command": "python",
      "args": ["-m", "pg_ham.mcp_server"],
      "cwd": "/path/to/ham",
      "env": {
        "HAM_API_URL": "http://127.0.0.1:8042",
        "HAM_API_KEY": "replace-me",
        "HAM_MCP_USER_ID": "shared-team",
        "HAM_AGENT_ID": "codex",
        "HAM_SCOPES": "shared,project:ham,repo:monumentalsystems/ham",
        "HAM_PROJECT": "ham",
        "HAM_REPO": "MonumentalSystems/ham"
      }
    }
  }
}

Give each agent a distinct key in HAM_AGENT_KEYS_JSON, and configure that key as its HAM_API_KEY. The server binds the key to its tenant and agent identity; client-supplied identity headers cannot override it. Set HAM_TASK and HAM_THREAD when the host can provide them. Local clients can reach a private remote deployment through an SSH tunnel without exposing HAM or PostgreSQL.

Legacy direct-PostgreSQL MCP mode is disabled by default. Local research setups can opt in with HAM_MCP_DIRECT_DB_ENABLED=true and the HAM_DB_* variables, but this grants the MCP process database credentials and is not recommended for shared or multi-user deployments.

Collaboration Contract

Per-agent keys are the normal tenant boundary. HAM_API_KEY is the separate administrator key and may select a tenant with X-GB-User-ID; it is required for hard delete, reset, graph rebuild, enrichment, and research endpoints. Unsigned identity headers are accepted only when HAM_TRUST_IDENTITY_HEADER=true behind an authenticated proxy. HAM_SINGLE_USER_ID is for local development.

Every collaborative memory stores standardized JSON metadata:

Field Purpose
agent_id Agent that produced the memory.
scopes Shared contexts in which the memory is discoverable.
project, repo, task, thread Work provenance and filtering.
type observation, fact, decision, handoff, and similar kinds.
status, importance Agent-facing workflow state and priority.
visibility shared or organizationally private to the originating agent.
idempotency_key Stable retry key that prevents duplicate writes.

Rows also carry state, version, updated_at, and supersedes_id. Search returns active memories; the change feed includes superseded and retracted items so agents can update their local understanding.

API Surface

Endpoint Method Purpose
/health/live, /health/ready GET Container and dependency health.
/ingest, /ingest/batch POST Consistent complete ingestion.
/search POST Scoped semantic, spectral, and lexical search.
/memories/recent POST Recent active context.
/changes POST Cursor-based catch-up feed.
/memories/{id} GET Full memory and provenance.
/memories/{id}/supersede POST Immutable replacement.
/memories/{id}/retract POST Auditable retraction.
/stats, /consolidate GET / POST Tenant memory lifecycle.

Legacy and research retrieval endpoints remain available. PostgreSQL is the production authority. QKPS and legacy pickle-backed fields are disabled by default (HAM_QKPS_ENABLED=false, HAM_LEGACY_FIELD_ENABLED=false) because they are process-local accelerators and should not define shared consistency.

Security

  • Keep PostgreSQL private and give agents only HAM_API_URL and HAM_API_KEY.
  • Prefer a private network or SSH tunnel; do not publish HAM directly to browsers.
  • Leave CORS empty unless a trusted browser application genuinely needs it.
  • Use per-agent credentials for every MCP client. Keep the administrator key out of agent environments; it can hard-delete or reset tenant data.
  • Application authorization is enforced before queries. PostgreSQL row-level security remains useful future defense in depth for mutually untrusted operators.
  • Back up PostgreSQL off-host and test restoration.

Development

pip install -r requirements.txt -r requirements-dev.txt
python -m py_compile pg_ham/server.py pg_ham/mcp_server.py scripts/e2e_collaboration.py
pytest -q
ruff check pg_ham/server.py pg_ham/mcp_server.py scripts tests

Training and benchmark scripts remain research tooling. Generated datasets, checkpoints, embeddings, field snapshots, and logs must stay out of git.

License

HAM is available under the Apache License 2.0.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选