@@ -18,6 +18,22 @@ import {
1818} from './constants.js' ;
1919import type { QueryResponse } from './types.js' ;
2020
21+ // Recursive Zod schema for Pinecone metadata filters
22+ // Supports nested objects with operators like {"timestamp": {"$gte": 123}}
23+ // Using z.any() for the value type to support all Pinecone filter formats
24+ const metadataFilterValueSchema : z . ZodType < any > = z . lazy ( ( ) =>
25+ z . union ( [
26+ z . string ( ) ,
27+ z . number ( ) ,
28+ z . boolean ( ) ,
29+ z . array ( z . string ( ) ) ,
30+ z . array ( z . number ( ) ) ,
31+ z . record ( z . string ( ) , metadataFilterValueSchema ) , // Recursive for nested operators
32+ ] )
33+ ) ;
34+
35+ const metadataFilterSchema = z . record ( z . string ( ) , metadataFilterValueSchema ) ;
36+
2137// Global Pinecone client (initialized lazily)
2238let pineconeClient : PineconeClient | null = null ;
2339
@@ -131,7 +147,7 @@ export async function setupServer(): Promise<McpServer> {
131147 'Whether to use semantic reranking for better relevance. Slower but more accurate. Default: true'
132148 ) ,
133149 metadata_filter : z
134- . record ( z . string ( ) , z . union ( [ z . string ( ) , z . number ( ) , z . boolean ( ) ] ) )
150+ . record ( z . string ( ) , metadataFilterSchema )
135151 . optional ( )
136152 . describe (
137153 'Optional metadata filter to narrow down search results. Use exact field names from list_namespaces. ' +
@@ -170,6 +186,11 @@ export async function setupServer(): Promise<McpServer> {
170186 } ;
171187 }
172188
189+ // Log filter for debugging
190+ if ( metadata_filter ) {
191+ console . error ( 'Received metadata filter:' , JSON . stringify ( metadata_filter , null , 2 ) ) ;
192+ }
193+
173194 const client = getPineconeClient ( ) ;
174195 const results = await client . query ( {
175196 query : query_text . trim ( ) ,
@@ -191,6 +212,7 @@ export async function setupServer(): Promise<McpServer> {
191212 content : doc . content . substring ( 0 , 2000 ) , // Truncate for readability
192213 score : Math . round ( doc . score * 10000 ) / 10000 ,
193214 reranked : doc . reranked ,
215+ metadata : doc . metadata , // Include all metadata fields (including timestamp)
194216 } ) ) ;
195217
196218 const response : QueryResponse = {
0 commit comments