feat: add discover-spaces tool and MCP_INSTRUCTIONS support#2
Draft
milichev wants to merge 3 commits into
Draft
Conversation
6 tasks
5b0ac31 to
23ef956
Compare
a88f8f8 to
7d36e5a
Compare
23ef956 to
003d296
Compare
bc07157 to
ace001b
Compare
… is not available
- Add discover-spaces hand-crafted tool: fetches all spaces with their types, properties, tags, and select option IDs; bracket-notation path narrowing; TTL cache with force_refresh; per-space/type opt-in filter via DISCOVERY_TOOL_CONFIG - Centralise env parsing into Zod-validated ConfigSchema; add JsonString helper with envKey labelling for error attribution; HttpClientConfig, ToolsConfig, InstructionsSchema all validated at startup - Add MCP_INSTRUCTIONS env var: unset/"true" → bundled instructions.md (inlined by esbuild via __BUNDLED_INSTRUCTIONS__); "false" → disabled; any other string → custom content; wired into serverOptions.instructions - Extract getPlainAxios singleton (non-OpenAPI-aware Axios) to src/utils/getPlainAxios.ts; extract resolveInstructions to src/utils/resolveInstructions.ts - Rename proxy-config.test.ts → config.test.ts; add test coverage for DISCOVERY_TOOL_CONFIG, MCP_INSTRUCTIONS, JsonString, and getPlainAxios; split getPlainAxios tests into dedicated file to isolate from axios mock - env:OPENAPI_MCP_HEADERS error message fix; discovery tool annotations
…PI_MCP_HEADERS='{file:headers.json}'; discover-spaces tool documentation added
003d296 to
9736b33
Compare
ace001b to
6155870
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.
Instead, it will be re-targeted to
anyproto/anytype-mcp:mainonce the outstanding PR anyproto#59 is merged.Therefore, it's marked as Draft. Still, you can review and try it out.
Description
This PR adds three related improvements:
discover-spacestool — a hand-crafted MCP tool that fetches all Anytype spaces with their types, properties, tags, and select option IDs in a single call. Reduces context bloat and roundtrips: clients call this once per session to resolve all IDs, instead of chaining list-spaces → list-types → list-properties → list-tags. Supports bracket-notation path narrowing (spaces["My Space"].tags), TTL cache withforce_refresh, and per-space/type opt-in filtering viaDISCOVERY_TOOL_CONFIG. The tool significantly decreases MCP-LLM roundtrips:MCP_INSTRUCTIONS— wiresinstructions.mdintoServerOptions.instructionsso MCP clients receive usage guidance on connect. The file is inlined at build time via esbuilddefine, so no runtime FS dependency in the distributed CLI. Configurable:falsedisables, any other string overrides with custom content.Config refactor — centralises all environment variable parsing into a single Zod-validated
ConfigSchema. Adds aJsonString<T>helper that labels parse errors with the originating env var name. Adds a{file:/path/to/file}mini-DSL, inspired by OpenCode, forDISCOVERY_TOOL_CONFIGandMCP_INSTRUCTIONS, so complex configs can be loaded from a file instead of inlined as escaped JSON strings. Validates all new env vars at startup alongside existing ones.What type of PR is this? (check all applicable)
Related Tickets & Documents
instructions.md— usage guide broadcast to MCP clients on connectMobile & Desktop Screenshots/Recordings
N/A
Added tests?
New/updated test files:
src/utils/__tests__/config.test.ts(renamed fromproxy-config.test.ts; extended withDISCOVERY_TOOL_CONFIG,MCP_INSTRUCTIONS,JsonString, and{file:}coverage)src/utils/__tests__/getPlainAxios.test.ts(isolated from axios mock interference)src/mcp/tools/__tests__/discovery.test.ts(resolvePath,fetchDiscovery,makeDiscoverSpacesHandlerincluding cache, TTL, andforce_refresh)Added to documentation?
Added
DISCOVERY_TOOL_CONFIGandMCP_INSTRUCTIONSto the environment variables table; addeddiscover-spacestool section covering path narrowing, space/type filtering,{file:}config reference, and cache behaviour.[optional] Are there any post-deployment tasks we need to perform?
None.
instructions.mdis bundled intobin/cli.mjsat build time — no deploy-time file placement needed.