Separate MCP query logic from tool handler serialization#653
Draft
Separate MCP query logic from tool handler serialization#653
Conversation
Add offset/total pagination to search_declarations, get_descendants,
and find_constant_references. Uses a two-pass paginate! macro: filter
pass counts total, map pass builds JSON only for the requested page.
- search_declarations: response wrapped in {results, total} envelope
- get_descendants: gains limit (default 100, max 500) and offset
- find_constant_references: gains offset; total always present
- limit=0 treated as default to guard against accidental empty pages
- Tool descriptions and server instructions mention pagination
- Add GraphTest::into_graph() for test graph injection
- Add 26 unit tests calling tool handlers directly (no process spawn)
- Windows-compatible test URIs via test_root()/test_uri() helpers
Add MCP Server section covering the two-pass pagination approach, result ordering guarantees (stable within a session, may vary across restarts due to parallel indexing), and key file references.
Extract core query logic from server.rs tool handlers into a new queries.rs module with typed Rust result structs. This enables testing business logic directly without JSON serialization. - Add queries.rs with QueryError enum, 12 typed result structs, 6 pure query functions, and 22 unit tests - Refactor server.rs handlers to thin adapters (~5 lines each): acquire graph, normalize params, call query, serialize - Split tests: query logic tests in queries.rs (typed), JSON shape and error tests in server.rs (integration) - Remove intermediate Vec allocations in pagination (use iterator count) - Use &'static str for kind fields and HashMap keys instead of String
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.
Summary
server.rstool handlers into a newqueries.rsmodule with typed Rust result structs, enabling direct testing of business logic without JSON serializationqueries.rsfor business logic, JSON shape + error tests inserver.rsfor the MCP integration layerVecallocations in pagination by using iterator.count()+.filter().skip().take()&'static strforkindfields andHashMapkeys instead ofStringto eliminate unnecessary allocationsChanges
queries.rs(new)QueryErrorenum, 12 typed result structs, 6 query functions, 22 unit testsserver.rsmain.rsmod queries;