diff --git a/README.md b/README.md index 644a21c..22d2ff4 100644 --- a/README.md +++ b/README.md @@ -104,11 +104,31 @@ npm install -g @anyproto/anytype-mcp | `MCP_HOST` | `127.0.0.1` | Host to bind when `MCP_TRANSPORT=http`. | | `MCP_PORT` | `3666` | Port to listen on when `MCP_TRANSPORT=http`. Must be in range 1024–65535. | | `MCP_PASSTHROUGH_HEADERS` | `authorization,anytype-version` | Comma-separated list of inbound HTTP header names (lowercase) forwarded from the MCP HTTP client to the Anytype API. Extend with caution — arbitrary headers must not be forwarded. | -| `MCP_INSTRUCTIONS` | bundled `instructions.md` | Instructions broadcast to MCP clients on connect. `false` disables; a string overrides with custom content; `{file:/path}` loads content from a file. | +| `MCP_INSTRUCTIONS` | bundled `instructions.md` | Instructions broadcast to MCP clients on connect. `false` disables; a string overrides with custom content; `{file:/path}` loads content from a file; `anytype://object?objectId=&spaceId=` loads content from an Anytype page. | | `DISCOVERY_TOOL_CONFIG` | — | JSON config for the `discover-spaces` tool. Accepts inline JSON or `{file:/path/to/config.json}`. Options: `ttlMs` (cache TTL ms, default 300000), `spaces` (per-space/type filter). | +### Custom MCP Instructions + +By default the server broadcasts the bundled `instructions.md` to MCP clients on every connection. +You can replace it with your own content via `MCP_INSTRUCTIONS`: + +- **Disable:** `MCP_INSTRUCTIONS=false` +- **Inline string:** `MCP_INSTRUCTIONS="Your custom instructions here"` +- **File:** `MCP_INSTRUCTIONS="{file:/path/to/instructions.md}"` +- **Anytype page:** `MCP_INSTRUCTIONS="anytype://object?objectId=&spaceId="` + +The Anytype page option fetches the object's markdown content at startup and uses it as the instructions string. +This lets you maintain your MCP instructions as a regular Anytype page — edit it in the app, restart the server to pick up changes. + +To get a page's deep link in Anytype: open the page → three-dot menu → **Copy link**. The link has the form: +``` +anytype://object?objectId=bafyrei...&spaceId=bafyrei....31e0h... +``` + +If the page cannot be fetched (Anytype not running, invalid link, network error), the server logs a warning and falls back to the bundled instructions. The warning is also prepended to the instructions text so the connected AI client is aware. + ### discover-spaces Tool The `discover-spaces` tool returns a complete snapshot of your Anytype workspace — all spaces with their types, properties, tags, and select option IDs — in a single call. AI assistants use it to resolve IDs before creating or updating objects, eliminating the need to chain multiple list calls. diff --git a/instructions.md b/instructions.md index 61d6712..43961ec 100644 --- a/instructions.md +++ b/instructions.md @@ -1,34 +1,39 @@ # Anytype MCP Server — Instructions -You are connected to an Anytype knowledge base via the **Anytype MCP server**. -Follow these rules precisely to avoid data loss or API errors. +You are connected to an Anytype knowledge base. Follow these rules precisely. + +## Glossary + +- **Space** (aka Channel): container within the Vault holding a graph of objects. +- **Object**: any entity in a Space. Has a *Name* (display) and *Key* (`lower_snake_case` identifier). +- **Object Type**: describes properties and layout. System types: Page, Note, Task, Bookmark, etc. Can be user-defined. +- **Property**: attribute of an Object Type. Intrinsic (read-only) keys: `id`, `links`, `backlinks`. +- **Tag**: classification label applied to page-like objects. Space-scoped — same name ≠ same ID across spaces. +- **Deeplink**: `anytype://object?objectId=&spaceId=` ## Session start — mandatory first step -Call `discover-spaces` with no arguments **before any other tool call** in a new session. -It returns every space, type, property, tag, and select-option ID you need. -Cache this result mentally for the session — do not call it again unless you have performed a schema-mutating operation (creating or modifying a type, property, tag, or space). +Call `discover-spaces` (no args) **before any other tool call**. +It returns *Discover Info* — a JSON snapshot of all Spaces, Types, Properties, Tags, and their IDs, keyed by Name. +Cache mentally for the session. With *Discover Info* and a Deeplink you can get or modify any object directly. -## ID resolution +### Force-refresh when: +- After creating/modifying a **type, property, tag, or space**. +- After a 404 on an ID-dependent call. -- **Never invent or guess IDs.** Every object, space, type, property, tag, and select option has an opaque content-addressed ID returned by `discover-spaces`. -- **Tags are space-scoped.** The same tag name in two spaces has two different IDs. Always look up the ID from the correct space entry in the `discover-spaces` result. -- **Select option IDs** are nested under `spaces[""].types[""].properties[""].select["