Skip to content

feat: load MCP instructions from an Anytype page via anytype:// deep link#3

Draft
milichev wants to merge 1 commit into
feature/space-discovery-toolfrom
feature/deeplink-mcp-instructions
Draft

feat: load MCP instructions from an Anytype page via anytype:// deep link#3
milichev wants to merge 1 commit into
feature/space-discovery-toolfrom
feature/deeplink-mcp-instructions

Conversation

@milichev
Copy link
Copy Markdown
Owner

@milichev milichev commented Mar 14, 2026

Warning

THIS PR IS NOT SUPPOSED TO BE MERGED HERE.
Instead, it will be re-targeted to anyproto/anytype-mcp:main once #2 is merged.


Note

Extends MCP_INSTRUCTIONS to accept an Anytype object deep link as its value. On startup, the server fetches the linked page and uses its markdown content as the instructions string broadcast to MCP clients in the initialize response.

Motivation

The bundled instructions.md is a static file — updating it requires editing the source tree, rebuilding, and redeploying. For users who maintain a living knowledge base in Anytype, this creates an awkward split: workspace rules and conventions live in Anytype, but the MCP server's behavioural instructions live outside it, in a config file or environment variable.

Storing instructions as a regular Anytype page closes that gap. The page can be edited in the app like any other document — with rich text, internal links to per-space rule pages, and version history — and the updated instructions take effect on the next server restart. No source changes, no rebuild.

This is also consistent with the existing discover-spaces philosophy: the server treats Anytype as the authoritative source of workspace knowledge, rather than duplicating that knowledge in static config.

Changes

src/utils/resolveAnytypeLink.ts (new)

  • parseAnytypeLink(value) — parses anytype://object?objectId=<id>&spaceId=<id>, returns null for non-matching input
  • resolveAnytypeObject(spaceId, objectId, axios)GET /v1/spaces/:spaceId/objects/:objectId, returns # <name>\n\n<markdown>; throws on error, caller handles fallback

src/utils/resolveInstructions.ts

  • Converted to async
  • New resolution branch: if configured value matches anytype://object?, fetch via resolveAnytypeObject; on any error fall back to bundled instructions with a warning block prepended (visible to the connected AI client) and console.error

src/mcp/proxy.ts

  • Constructor made private
  • static async MCPProxy.create(name, spec) factory added — resolves instructions before constructing the instance, keeping the constructor synchronous internally

src/init-server.ts

  • new MCPProxy(...)await MCPProxy.create(...)

instructions.md

  • Added ## Anytype deep links section explaining anytype:// link resolution via API-get-object

README.md

  • MCP_INSTRUCTIONS table row extended with anytype:// option
  • New ### Custom MCP Instructions subsection documenting all four modes with UX hint for copying deep links from the Anytype app

Tests

  • src/utils/__tests__/resolveAnytypeLink.test.ts (new) — 13 cases covering parseAnytypeLink and resolveAnytypeObject
  • src/utils/__tests__/resolveInstructions.test.ts (new) — 8 cases covering all resolution paths including fallback warning and console.error
  • src/mcp/__tests__/proxy.test.ts — updated to use MCPProxy.create, mocks added for resolveInstructions and getPlainAxios

Fallback behaviour

If the Anytype page cannot be fetched (app not running, invalid link, network error), the server logs the error to stderr and prepends a human-readable warning block to the bundled instructions. The connected AI client sees the warning immediately at session start rather than silently operating on stale or incorrect rules.

Dependency

@milichev milichev self-assigned this Mar 14, 2026
@milichev milichev force-pushed the feature/space-discovery-tool branch from bc07157 to ace001b Compare March 31, 2026 16:31
@milichev milichev force-pushed the feature/deeplink-mcp-instructions branch from d0aef8a to dadb27f Compare March 31, 2026 16:32
- discovery docs updated

- instructions.md squeezed more

- minor prettier formatting
@milichev milichev force-pushed the feature/space-discovery-tool branch from ace001b to 6155870 Compare March 31, 2026 17:09
@milichev milichev force-pushed the feature/deeplink-mcp-instructions branch from dadb27f to bd41457 Compare March 31, 2026 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant