feat: load MCP instructions from an Anytype page via anytype:// deep link#3
Draft
milichev wants to merge 1 commit into
Draft
feat: load MCP instructions from an Anytype page via anytype:// deep link#3milichev wants to merge 1 commit into
milichev wants to merge 1 commit into
Conversation
bc07157 to
ace001b
Compare
d0aef8a to
dadb27f
Compare
- discovery docs updated - instructions.md squeezed more - minor prettier formatting
ace001b to
6155870
Compare
dadb27f to
bd41457
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Warning
THIS PR IS NOT SUPPOSED TO BE MERGED HERE.
Instead, it will be re-targeted to
anyproto/anytype-mcp:mainonce #2 is merged.Note
Extends
MCP_INSTRUCTIONSto 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 theinitializeresponse.Motivation
The bundled
instructions.mdis 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-spacesphilosophy: 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)— parsesanytype://object?objectId=<id>&spaceId=<id>, returnsnullfor non-matching inputresolveAnytypeObject(spaceId, objectId, axios)—GET /v1/spaces/:spaceId/objects/:objectId, returns# <name>\n\n<markdown>; throws on error, caller handles fallbacksrc/utils/resolveInstructions.tsasyncanytype://object?, fetch viaresolveAnytypeObject; on any error fall back to bundled instructions with a warning block prepended (visible to the connected AI client) andconsole.errorsrc/mcp/proxy.tsprivatestatic async MCPProxy.create(name, spec)factory added — resolves instructions before constructing the instance, keeping the constructor synchronous internallysrc/init-server.tsnew MCPProxy(...)→await MCPProxy.create(...)instructions.md## Anytype deep linkssection explaininganytype://link resolution viaAPI-get-objectREADME.mdMCP_INSTRUCTIONStable row extended withanytype://option### Custom MCP Instructionssubsection documenting all four modes with UX hint for copying deep links from the Anytype appTests
src/utils/__tests__/resolveAnytypeLink.test.ts(new) — 13 cases coveringparseAnytypeLinkandresolveAnytypeObjectsrc/utils/__tests__/resolveInstructions.test.ts(new) — 8 cases covering all resolution paths including fallback warning andconsole.errorsrc/mcp/__tests__/proxy.test.ts— updated to useMCPProxy.create, mocks added forresolveInstructionsandgetPlainAxiosFallback 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