Cosmos

your ai exocortex

Polarity

cosmos-mcp

One exocortex. Every agent.
MCP server for your Cosmos graph.

npm license site glama


Every AI you use is building its own private graph of you. Claude has one. ChatGPT has one. Cursor has one. None of them talk to each other, and none of them are yours.

Cosmos inverts that. Your knowledge graph lives in one place, and any MCP-capable client (Claude Code, Claude Desktop, Cursor, Codex, Zed, Continue) reads and writes to the same one. When an agent notices something durable about you, it lands in the graph. When you switch tools, the graph follows. The user, not the platform, owns the integration layer.

The thing you carry is a .polarity file. Yours.

Provisioning

There are two ways to get a pmk_… key onto your Mac.

Automatic. Sign in at cosmos.polarity-lab.com/connectors, tap "open in cosmos-mcp." The OS opens a one-shot handler that writes the key into your system keychain. You never see the raw key.

For that deep link to work, register the URL scheme once:

npx -y @polarity-lab/cosmos-mcp install-handler

This drops a tiny .app into ~/Library/Application Support/cosmos-mcp/ and registers cosmos-mcp:// with Launch Services. macOS-only.

Manual. If you already have a pmk_… key, or you do not want to install the handler:

npx -y @polarity-lab/cosmos-mcp provision pmk_xxx

The CLI validates the key against cosmos, then stores it in the macOS system keychain under service cosmos-mcp-key. Subsequent imessage sync, browser sync, calendar sync calls read from the keychain. No env var needed.

Confirm iMessage access.

npx -y @polarity-lab/cosmos-mcp imessage probe

Verifies Full Disk Access is granted and reports how many chats are visible. If you see an EACCES message, open System Settings, Privacy & Security, Full Disk Access, and add Terminal (or whichever app runs the CLI).

CI and self-hosters. Set COSMOS_TOKEN=pmk_… in env. It takes precedence over the keychain, so existing pipelines keep working untouched.

Install

npx -y @polarity-lab/cosmos-mcp init

Opens your browser. Sign in at cosmos.polarity-lab.com, approve a per-user key, and the token lands at ~/.config/cosmos-mcp/token (0600). Then point any MCP client at it:

{
  "mcpServers": {
    "cosmos": {
      "command": "npx",
      "args": ["-y", "@polarity-lab/cosmos-mcp"]
    }
  }
}

That config drops into ~/Library/Application Support/Claude/claude_desktop_config.json for Claude Desktop, your .cursor/mcp.json for Cursor, the equivalent for whichever client.

What you get

Eleven tools, four read, seven write.

Read

ToolCallsWhat it returns
polarity_whoamiGET /api/polarity/whoamiBound user + scopes. Cheap probe.
polarity_exportPOST /api/polarity/exportFull personal graph as polarity/v1 JSON.
polarity_get_graphGET /api/polarityGraph view, scoped by entity (user, cosmos, polarity).
polarity_askPOST /api/polarity/askNL question synthesized over the graph.

Write

ToolCallsWhat it does
polarity_observePOST /api/polarity/observeFreeform observation. Cosmos extracts.
polarity_record_eventPOST /api/polarity/observe (kind=event)Something happened at a point in time.
polarity_record_preferencePOST /api/polarity/observe (kind=preference)A like, dislike, working-style rule.
polarity_capture_turnPOST /api/polarity/capture-turnHand a whole user/assistant exchange to cosmos. Pulls every durable observation in one call. Prefer over multiple polarity_observe calls.
polarity_dumpPOST /api/polarity/dumpLocation-anchored short message.
polarity_checkinPOST /api/polarity/checkinCheck-in at a waypoint. Triggers co-presence detection.
polarity_declarePOST /api/polarity/declareDeclare future presence at a waypoint.

Sources

The MCP server is one way to write to the graph. Cosmos accepts source pages from anywhere you keep notes, and the MCP read tools see all of it through the same view.

SourceHow it connectsWhat lands
iMessageLocal CLI: npx -y @polarity-lab/cosmos-mcp imessage sync. Mac only. Grant Terminal Full Disk Access first.Conversational turns from chat.db, with text content. People appear as person nodes in your graph, sized by conversation weight, named via your local AddressBook, dated by your real message timestamps.
NotionOAuth at cosmos.polarity-lab.com/connectors. Pick the pages and databases you want shared.Each Notion page becomes a source_page node, keyed by Notion id, kept fresh by a daily sync.
ObsidianCommunity plugin: polarity-lab/obsidian-cosmos. Paste your pmk_ key, point at your vault.Each note becomes a source_page node keyed by vault-relative path. Tags and wikilinks resolve into edges.
MCP clientsThis package.Observations, events, preferences, location dumps, check-ins, declarations.
Direct APIPOST /api/polarity/observe with your key.Anything you can express as an observation.

Unchanged pages are skipped server-side, so re-syncing a quiet vault or stable Notion workspace costs almost nothing. The iMessage sync is incremental too, watermarked on the last successful run, so re-running it is a no-op until new messages arrive.

iMessage sync

cosmos-mcp ships an imessage subcommand that reads your local Messages database and lands every conversation in your graph.

# default: incremental sync, 90-day window on first run
npx -y @polarity-lab/cosmos-mcp imessage sync

# re-sync the original 90-day window regardless of watermark
npx -y @polarity-lab/cosmos-mcp imessage sync --backfill

# pull everything since a specific date
npx -y @polarity-lab/cosmos-mcp imessage sync --since 2024-01-01

# check what the last run did
npx -y @polarity-lab/cosmos-mcp imessage status

A three-rule slop filter (no-reply senders, short-code numbers, low-volume contacts) keeps the graph clean. Your AddressBook resolves phone numbers and emails into real contact names. The reading is local to your Mac; only the extracted, normalized turns go into your cosmos graph, which is your account.

Configuration

Env varDefaultWhen you set it
COSMOS_URLhttps://cosmos.polarity-lab.comPointing at your own cosmos.
COSMOS_TOKEN(from keychain)pmk_... per-user key for CLI subcommands. Takes precedence over the macOS keychain entry. Set this in CI.
COSMOS_MCP_KEY(from token file)pmk_... per-user key. Honored for back-compat.
COSMOS_USER_ID(from token file)Polarity user id.
COSMOS_SYSTEM_KEY(unset)Single-tenant mode. Sends X-System-Key instead of X-MCP-Key. Requires COSMOS_USER_ID. For self-hosters or testing before per-user keys are deployed.

Self-hosting

The cosmos backend is open. Run taiscoding/cosmos on your own Cloudflare account, mint a key against your instance, set COSMOS_URL to your domain. The graph stays on your D1. The .polarity export still works.

The pitch in three lines

Your AI tools each know fragments of you. They are not allowed to share. Cosmos is the layer that lets them. You hold the key. The graph is portable. When you leave, you take the understanding with you.

License

MIT.

Related Servers