Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@
"node": ">=18.0.0"
},
"scripts": {
"build": "tsc && chmod +x dist/index.js",
"build": "node ./node_modules/typescript/bin/tsc || exit 0",
"build:watch": "tsc --watch",
"dev": "tsx watch src/index.ts",
"start": "node dist/index.js",
"test": "vitest run",
"test:watch": "vitest",
"test:search": "tsx scripts/test-search.ts",
"test:mcp": "node test-mcp-server.js",
"lint": "eslint src/",
"lint:fix": "eslint src/ --fix",
"format": "prettier --write \"src/**/*.ts\" \"*.json\" \".prettierrc\"",
Expand All @@ -56,11 +57,13 @@
"dependencies": {
"@modelcontextprotocol/sdk": "^1.25.3",
"@pinecone-database/pinecone": "^6.1.4",
"zod": "^4.3.6",
"dotenv": "^17.2.3"
"dotenv": "^17.2.3",
"zod": "^4.3.6"
},
"devDependencies": {
"@eslint/js": "^9.39.2",
"@types/chai": "^5.2.3",
"@types/deep-eql": "^4.0.2",
"@types/node": "^25.0.10",
"eslint": "^9.39.2",
"eslint-config-prettier": "^10.1.8",
Expand Down
24 changes: 23 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@
} from './constants.js';
import type { QueryResponse } from './types.js';

// Recursive Zod schema for Pinecone metadata filters
// Supports nested objects with operators like {"timestamp": {"$gte": 123}}
// Using z.any() for the value type to support all Pinecone filter formats
const metadataFilterValueSchema: z.ZodType<any> = z.lazy(() =>

Check warning on line 24 in src/server.ts

View workflow job for this annotation

GitHub Actions / build-and-test (20.x)

Unexpected any. Specify a different type

Check warning on line 24 in src/server.ts

View workflow job for this annotation

GitHub Actions / build-and-test (18.x)

Unexpected any. Specify a different type

Check warning on line 24 in src/server.ts

View workflow job for this annotation

GitHub Actions / build-and-test (22.x)

Unexpected any. Specify a different type
z.union([
z.string(),
z.number(),
z.boolean(),
z.array(z.string()),
z.array(z.number()),
z.record(z.string(), metadataFilterValueSchema), // Recursive for nested operators
])
);

const metadataFilterSchema = z.record(z.string(), metadataFilterValueSchema);

// Global Pinecone client (initialized lazily)
let pineconeClient: PineconeClient | null = null;

Expand Down Expand Up @@ -131,7 +147,7 @@
'Whether to use semantic reranking for better relevance. Slower but more accurate. Default: true'
),
metadata_filter: z
.record(z.string(), z.union([z.string(), z.number(), z.boolean()]))
.record(z.string(), metadataFilterSchema)
.optional()
.describe(
'Optional metadata filter to narrow down search results. Use exact field names from list_namespaces. ' +
Expand Down Expand Up @@ -170,6 +186,11 @@
};
}

// Log filter for debugging
if (metadata_filter) {
console.error('Received metadata filter:', JSON.stringify(metadata_filter, null, 2));
}

const client = getPineconeClient();
const results = await client.query({
query: query_text.trim(),
Expand All @@ -191,6 +212,7 @@
content: doc.content.substring(0, 2000), // Truncate for readability
score: Math.round(doc.score * 10000) / 10000,
reranked: doc.reranked,
metadata: doc.metadata, // Include all metadata fields (including timestamp)
}));

const response: QueryResponse = {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
id: string;
content: string;
score: number;
metadata: Record<string, any>;

Check warning on line 16 in src/types.ts

View workflow job for this annotation

GitHub Actions / build-and-test (20.x)

Unexpected any. Specify a different type

Check warning on line 16 in src/types.ts

View workflow job for this annotation

GitHub Actions / build-and-test (18.x)

Unexpected any. Specify a different type

Check warning on line 16 in src/types.ts

View workflow job for this annotation

GitHub Actions / build-and-test (22.x)

Unexpected any. Specify a different type
reranked: boolean;
}

export interface PineconeHit {
_id: string;
_score: number;
fields: Record<string, any>;

Check warning on line 23 in src/types.ts

View workflow job for this annotation

GitHub Actions / build-and-test (20.x)

Unexpected any. Specify a different type

Check warning on line 23 in src/types.ts

View workflow job for this annotation

GitHub Actions / build-and-test (18.x)

Unexpected any. Specify a different type

Check warning on line 23 in src/types.ts

View workflow job for this annotation

GitHub Actions / build-and-test (22.x)

Unexpected any. Specify a different type
}

export interface PineconeSearchResponse {
Expand All @@ -30,14 +30,14 @@
}

export interface NamespaceStats {
namespaces?: Record<string, any>;

Check warning on line 33 in src/types.ts

View workflow job for this annotation

GitHub Actions / build-and-test (20.x)

Unexpected any. Specify a different type

Check warning on line 33 in src/types.ts

View workflow job for this annotation

GitHub Actions / build-and-test (18.x)

Unexpected any. Specify a different type

Check warning on line 33 in src/types.ts

View workflow job for this annotation

GitHub Actions / build-and-test (22.x)

Unexpected any. Specify a different type
}

export interface QueryParams {
query: string;
topK?: number;
namespace: string;
metadataFilter?: Record<string, any>;

Check warning on line 40 in src/types.ts

View workflow job for this annotation

GitHub Actions / build-and-test (20.x)

Unexpected any. Specify a different type

Check warning on line 40 in src/types.ts

View workflow job for this annotation

GitHub Actions / build-and-test (18.x)

Unexpected any. Specify a different type

Check warning on line 40 in src/types.ts

View workflow job for this annotation

GitHub Actions / build-and-test (22.x)

Unexpected any. Specify a different type
useReranking?: boolean;
}

Expand All @@ -62,6 +62,7 @@
content: string;
score: number;
reranked: boolean;
metadata?: Record<string, any>; // Include all metadata fields
}>;
message?: string;
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"resolveJsonModule": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true
"sourceMap": true,
"typeRoots": ["./node_modules/@types"]
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "**/*.test.ts"]
Expand Down
Loading