@@ -12,6 +12,7 @@ import {
1212import { rankNamespacesByQuery } from '../../core/server/namespace-router.js' ;
1313import { getNamespacesWithCache } from '../../core/server/namespaces-cache.js' ;
1414import { normalizeNamespace } from '../../core/server/namespace-utils.js' ;
15+ import type { ServerContext } from '../../core/server/server-context.js' ;
1516import { suggestQueryParams } from '../../core/server/query-suggestion.js' ;
1617import { markSuggested } from '../../core/server/suggestion-flow.js' ;
1718import {
@@ -39,7 +40,7 @@ function resolveGuidedToolName(
3940 * Registers `guided_query` (routing + suggestion + execution in one call).
4041 * See "Retrieval tool decision matrix" in README.md for tool-selection guidance.
4142 */
42- export function registerGuidedQueryTool ( server : McpServer ) : void {
43+ export function registerGuidedQueryTool ( server : McpServer , ctx ?: ServerContext ) : void {
4344 server . registerTool (
4445 'guided_query' ,
4546 {
@@ -102,7 +103,9 @@ export function registerGuidedQueryTool(server: McpServer): void {
102103 }
103104
104105 const queryText = user_query . trim ( ) ;
105- const { data : namespaces , cache_hit } = await getNamespacesWithCache ( ) ;
106+ const { data : namespaces , cache_hit } = ctx
107+ ? await ctx . getNamespacesWithCache ( )
108+ : await getNamespacesWithCache ( ) ;
106109 const ranked = rankNamespacesByQuery ( queryText , namespaces , 3 ) ;
107110
108111 let namespace : string | null = null ;
@@ -150,13 +153,21 @@ export function registerGuidedQueryTool(server: McpServer): void {
150153 }
151154
152155 const selectedTool : GuidedToolName = resolveGuidedToolName ( preferred_tool , suggestion ) ;
153- markSuggested ( namespace , {
154- recommended_tool : selectedTool ,
155- suggested_fields : suggestion . suggested_fields ,
156- user_query : queryText ,
157- } ) ;
156+ if ( ctx ) {
157+ ctx . markSuggested ( namespace , {
158+ recommended_tool : selectedTool ,
159+ suggested_fields : suggestion . suggested_fields ,
160+ user_query : queryText ,
161+ } ) ;
162+ } else {
163+ markSuggested ( namespace , {
164+ recommended_tool : selectedTool ,
165+ suggested_fields : suggestion . suggested_fields ,
166+ user_query : queryText ,
167+ } ) ;
168+ }
158169
159- const client = getPineconeClient ( ) ;
170+ const client = ctx ? ctx . getClient ( ) : getPineconeClient ( ) ;
160171 const baseTrace = {
161172 cache_hit,
162173 input_namespace : inputNamespace ?? null ,
0 commit comments