Skip to content

Commit 4009089

Browse files
committed
Enhance query_documents tool with limit parameter and updated JSDoc #7883
1 parent de2d5c9 commit 4009089

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

ai/mcp/server/knowledge-base/openapi.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,10 @@ components:
547547
- `release`: Release notes and changelogs
548548
enum: [all, blog, guide, src, example, ticket, release]
549549
default: all
550+
limit:
551+
type: integer
552+
description: The maximum number of results to return.
553+
default: 25
550554

551555
QueryResultItem:
552556
type: object

ai/mcp/server/knowledge-base/services/QueryService.mjs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ class QueryService extends Base {
4040
/**
4141
* Performs a semantic search on the knowledge base using a natural language query.
4242
* Returns a scored and ranked list of the most relevant source files.
43-
* @param {string} query - The natural language search query.
44-
* @param {string} [type='all'] - The content type to filter by.
43+
* @param {string} query - The natural language search query.
44+
* @param {string} [type='all'] - The content type to filter by. Valid values: 'all', 'blog', 'guide', 'src', 'example', 'ticket', 'release'.
45+
* @param {number} [limit=25] - The maximum number of results to return.
4546
* @returns {Promise<object>} A promise that resolves to the query results object.
4647
*/
47-
async queryDocuments({query, type='all'}) {
48+
async queryDocuments({query, type='all', limit=25}) {
4849
if (!query) {
4950
throw new Error('A query string must be provided.');
5051
}
@@ -149,7 +150,7 @@ class QueryService extends Base {
149150

150151
const finalSorted = Object.entries(finalScores)
151152
.sort(([, a], [, b]) => b - a)
152-
.slice(0, 25)
153+
.slice(0, limit)
153154
.map(([source, score]) => ({ source, score: score.toFixed(0) }));
154155

155156
if (finalSorted.length > 0) {

0 commit comments

Comments
 (0)