Skip to content

feat(mcp): query_notes, the read tool over note.query - #247

Merged
bketelsen merged 2 commits into
mainfrom
irulan/query-notes
Nov 18, 2026
Merged

bketelsen merged 2 commits into
mainfrom
irulan/query-notes

Conversation

@frostyard-machines

Copy link
Copy Markdown
Contributor

Summary

Adds the MCP read tool query_notes over note.query: plan 0010, Phase 2, as ADR-0037 ("MCP query_notes is a read tool") shapes it. Its contract is in docs/specs/mcp.md.

  • Input: exactly one of filters (a Bases statement string, or an object with one of and, or, not) and path (a .base file, with an optional view); properties (default none); sort (with filters only); limit 1 to 1000, default 200.
  • Output: files: [{path, title, url, properties, writable}], total and notice (the read tools' sentence). writable appears only under a limited scope, as in list_notes. An attachment's title is its file.basename. The result never holds a note's body.
  • filters goes to note.query as the source of a base with 1 table view: the properties are its order, and sort is its sort. This form has no this, so notesd refuses a statement that uses it.
  • path evaluates the base's view as written. properties names columns of that view (KEY and note.KEY are the same column). Any other name is an error that lists the view's columns. sort is an error in this form, because the view sets its own order.
  • A view with a notice (a view type outside the subset, such as kanban, or groupOrder) is a tool error. Its text names the view and the notice, for example view "Board": views[1]: view type kanban is outside the subset. It never returns empty files.
  • Through lodge, the session serves its scope's vault (ADR-0028). The tool gets no other vault.

Docs: specs/mcp.md (the read tool list goes from 5 to 6, a new Queries section, the writable list, and the content rule gains the frontmatter clause), plan 0010 (status, and check 7 built), specs/bases.md and design/vault.md (back-links).

Shape choices

ADR-0037 gives a rough shape, and this PR pins these points in the spec:

  1. With path, properties picks columns of the view. note.query returns values only for the view's columns, so another property needs a contract change.
  2. sort with path is refused: note.query cannot reorder a view.
  3. A property that notesd cannot show (formula.*, this.*, an unknown file.*) is an error, not a silent null.
  4. limit: 0 is the default, as for list_notes and list_tasks.

Risk tier

Risk tier: 2 — a new read-only MCP tool; behaviour change in code. No path in .github/risk-paths.json is touched (internal/mcpserver/http.go, internal/lodgeapp/lodgeapp.go and api/scope.go are unchanged): the tool uses the existing scope and vault binding.

Verification

  • make ci green (host, with the nsl ui-check), before the first push
  • Tests (ADR-0037 check 7): internal/mcpserver/query_test.go (filters as a string and an object, properties with nulls, sort, limit edges 0/1/1000/1001/-1, path mode, this with a path and refused without one, the kanban, groupOrder and first-view-kanban errors with no files, input refusals), and TestQueryNotesThroughLodgeIsPinnedToTheScopesVault in internal/mcpserver/http_test.go (through lodge's socket with kittest: a read scope's rows are pinned to its vault with notice and url, view errors, writable under write=Garden/). The tool lists change from 5 to 6 read tools and from 8 to 9 tools.

Agents run Obsidian Bases filters, or a .base file's view, through
note.query (ADR-0037, plan 0010 Phase 2). Rows carry the properties the
call names, never a note's body. A view that shows a notice in the app
(a type outside the subset, or groupOrder) is a tool error that names
the view, never empty files. Through lodge the vault is the scope's.

The tests cover ADR-0037's check 7: the read tool list of 6, a read
scope through lodge's /mcp pinned to its vault with notice, the view
notices as tool errors with no files, the limit's edges and a refused
this filter. specs/mcp.md gains the tool and its Queries section.
@github-actions github-actions Bot added the level:L3 Skim label Nov 18, 2026
….base path

json/v2 writes U+0085, U+2028 and U+2029 raw, and YAML reads them as
line breaks, so a filter literal or a property name with one reached
the compiler changed. The tool now writes them as JSON escapes. An
unnamed view's notice says so, and a path must name a .base file.
Tests pin that no input changes the base the tool builds, and that the
default limit is 200.
@frostyard-machines

Copy link
Copy Markdown
Contributor Author

Cross-review record

  • Coder: openai/gpt-6.1-sol (code and tests); the docs are by anthropic/claude-opus-5-5. Reviewer: github-copilot/claude-sonnet-5.5. Base: f07797b00d841b8126ebce2c6cb506a15c7e8ba7.
  • Initial review at 9ebd7c2dc7662dbda1d6bba864ee0304f1737a9c: Ready, Blocking: none, with 7 findings (1 medium, 6 low). Fixed in 7307062:
    1. (Medium) json/v2 writes U+0085, U+2028 and U+2029 raw, and YAML folds them, so a literal changed. They are now JSON escapes. Test: TestQueryNotesPreservesUnicodeLineBreaksAndEmoji.
    2. An unnamed view's notice said view "". It now says an unnamed view: …. Test: TestQueryNotesUnnamedViewNoticeIsAnErrorWithoutFiles.
    3. No test showed that input cannot change the base's shape. Test: TestQueryNotesInputCannotChangeTheBaseShape.
    4. The default limit of 200 had no test. Test: TestQueryNotesDefaultLimitReturns200Of201Matches.
    5. A non-.base path was not refused. It is now refused, with a test case.
    6. The spec now says that with filters, error locations are in the base the tool builds.
    • Not changed: 5, integers beyond 2^53 decode as float64. read_note decodes properties the same way, and a raw-JSON type would change the output schema that the SDK infers.
  • Re-review 1 at 7307062c76099c8a52cb2537d19a9baeeb33a72b: Ready, Blocking: none. It confirms that the escape is exact: a raw rune can only occur inside a JSON string, and a backslash in the input is always written as \\.
    • Its 2 low points stay as they are: the refusal text does not repeat the path (style), and the float64 decoding (accepted, as above).

Revert test

In a scratch worktree at 9ebd7c2, each mutation was run with go test -count=1 ./internal/mcpserver/:

  • Without the notice-to-error branch in query.go, the 3 cases of TestQueryNotesUnsupportedViewsAreErrorsWithoutFiles and TestQueryNotesThroughLodgeIsPinnedToTheScopesVault fail on assertions.
  • Without the tool's registration, every TestQueryNotes* test and the tool-list tests fail on assertions.

The tests of 7307062 failed before its fixes and pass after them.

Gates: make ci passed at 9ebd7c2 before the first push. make check and go test -race on ./internal/mcpserver/ and ./cmd/notesctl/ passed at 7307062.

@frostyard-machines frostyard-machines added the ready-for-human Reviewed, CI green: ready for Brian to review and merge label Nov 18, 2026
@bketelsen
bketelsen merged commit 37eaf5d into main Nov 18, 2026
11 checks passed
@bketelsen
bketelsen deleted the irulan/query-notes branch November 18, 2026 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

level:L3 Skim ready-for-human Reviewed, CI green: ready for Brian to review and merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants