Repository navigation
fix(cli): return every requested chunk from the MCP chunk_list tool - #6209
Open
columbia11 wants to merge 1 commit into
Open
columbia11 wants to merge 1 commit into
columbia11 wants to merge 1 commit into
Conversation
The server caps a page of chunks at 100, but chunk_list sent one request with page_size=limit (up to 1000) and reported truncated_at_limit from total > limit. A 300-chunk document with limit 500 came back as 100 chunks with truncated_at_limit=false. Walk the server pages until limit or total is reached, and compute the flag from the number of chunks actually returned.
This branch has not been deployed
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.
Description
The MCP tool
chunk_list(served byweknora mcp serve) acceptslimitup to 1000 and says it returns at mostlimitchunks, withtruncated_at_limit=truewhen the document has more. For anylimitabove 100 on a document with more than 100 chunks, it returns only the first 100 and still reportstruncated_at_limit=false.Example: a document with 300 chunks,
chunk_listwithlimit: 500→ 100 chunks,total: 300,truncated_at_limit: false. An agent that reads the flag takes those 100 chunks for the whole document.Cause
The tool makes one request with
page=1, page_size=limit. The server capspage_sizeforGET /api/v1/chunks/:knowledge_idat 100 (internal/handler/chunk.go), so the response never holds more than 100 chunks. The flag is computed astotal > limit, which compares against what was asked for, not against what came back.Change
chunk_listnow requests the next page until it haslimitchunks, has alltotalchunks, or gets an empty page, and trims the result tolimit.truncated_at_limitis computed from the number of chunks actually returned. The page size is the same on every request, so the offsets line up whatever cap the server applies, and alimitof 100 or less is still a single request.Not changed:
weknora chunk list --page-sizealso allows values above the server's cap. Without--all-pagesit prints one page by design and reportstotal_count, so I left it as it is.Type of Change
Related Issue
None found.
Testing
New test
TestTool_ChunkList_WalksServerPagesUpToLimitincli/internal/mcp/tools_test.go. The fake service now can serve chunks in pages of at most 100, as the server does. Two cases on a 300-chunk document:limit: 500must return all 300 withtruncated_at_limit=false;limit: 250must return chunks 0..249 withtruncated_at_limit=true.With
main'stools.goboth cases fail (100 chunks returned); with the change both pass.Commands, run in WSL (Ubuntu 24.04, Go 1.26.7), from
cli/:go test -count=1 ./...→ every packageok(includingacceptance/contract).go vet ./...→ clean.gofmt -lon the two files → no output.golangci-lint run --new-from-patch=<git diff origin/main>on./internal/mcp/with golangci-lint v2.12.2 → 0 issues.git diff --check origin/main...HEAD→ clean.Not run: the live-server e2e suite (
-tags acceptance_e2e), and the tool was not called against a running server.Checklist
git diff --check origin/main...HEADpassesgolangci-lint run --new-from-rev=origin/main ./...) — run as--new-from-patchclimodulewebsite-docs/, Swagger annotations, etc.) — none neededScreenshots / Recordings
Not a UI change.