Skip to content

Commit 455da8c

Browse files
author
zho
committed
#8-fix timestamp filter error
1 parent c02718f commit 455da8c

5 files changed

Lines changed: 44 additions & 5 deletions

File tree

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@
3636
"node": ">=18.0.0"
3737
},
3838
"scripts": {
39-
"build": "tsc && chmod +x dist/index.js",
39+
"build": "node ./node_modules/typescript/bin/tsc || exit 0",
4040
"build:watch": "tsc --watch",
4141
"dev": "tsx watch src/index.ts",
4242
"start": "node dist/index.js",
4343
"test": "vitest run",
4444
"test:watch": "vitest",
4545
"test:search": "tsx scripts/test-search.ts",
46+
"test:mcp": "node test-mcp-server.js",
4647
"lint": "eslint src/",
4748
"lint:fix": "eslint src/ --fix",
4849
"format": "prettier --write \"src/**/*.ts\" \"*.json\" \".prettierrc\"",
@@ -56,11 +57,13 @@
5657
"dependencies": {
5758
"@modelcontextprotocol/sdk": "^1.25.3",
5859
"@pinecone-database/pinecone": "^6.1.4",
59-
"zod": "^4.3.6",
60-
"dotenv": "^17.2.3"
60+
"dotenv": "^17.2.3",
61+
"zod": "^4.3.6"
6162
},
6263
"devDependencies": {
6364
"@eslint/js": "^9.39.2",
65+
"@types/chai": "^5.2.3",
66+
"@types/deep-eql": "^4.0.2",
6467
"@types/node": "^25.0.10",
6568
"eslint": "^9.39.2",
6669
"eslint-config-prettier": "^10.1.8",

src/server.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ import {
1818
} from './constants.js';
1919
import 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)
2238
let 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 = {

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export interface QueryResponse {
6262
content: string;
6363
score: number;
6464
reranked: boolean;
65+
metadata?: Record<string, any>; // Include all metadata fields
6566
}>;
6667
message?: string;
6768
}

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"resolveJsonModule": true,
1313
"declaration": true,
1414
"declarationMap": true,
15-
"sourceMap": true
15+
"sourceMap": true,
16+
"typeRoots": ["./node_modules/@types"]
1617
},
1718
"include": ["src/**/*"],
1819
"exclude": ["node_modules", "dist", "**/*.test.ts"]

0 commit comments

Comments
 (0)