@dotlab-hq/vector-store-mcp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +225 -0
- package/dist/client.d.ts +11 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +28 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/schemas/index.d.ts +492 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +300 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +99 -0
- package/dist/server.js.map +1 -0
- package/dist/stdio.d.ts +3 -0
- package/dist/stdio.d.ts.map +1 -0
- package/dist/stdio.js +30 -0
- package/dist/stdio.js.map +1 -0
- package/dist/tools/files.d.ts +9 -0
- package/dist/tools/files.d.ts.map +1 -0
- package/dist/tools/files.js +153 -0
- package/dist/tools/files.js.map +1 -0
- package/dist/tools/index.d.ts +40 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +47 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/upload-file.d.ts +20 -0
- package/dist/tools/upload-file.d.ts.map +1 -0
- package/dist/tools/upload-file.js +60 -0
- package/dist/tools/upload-file.js.map +1 -0
- package/dist/tools/vector-stores.d.ts +8 -0
- package/dist/tools/vector-stores.d.ts.map +1 -0
- package/dist/tools/vector-stores.js +267 -0
- package/dist/tools/vector-stores.js.map +1 -0
- package/dist/tools/vs-file-batches.d.ts +8 -0
- package/dist/tools/vs-file-batches.d.ts.map +1 -0
- package/dist/tools/vs-file-batches.js +157 -0
- package/dist/tools/vs-file-batches.js.map +1 -0
- package/dist/tools/vs-files.d.ts +8 -0
- package/dist/tools/vs-files.d.ts.map +1 -0
- package/dist/tools/vs-files.js +222 -0
- package/dist/tools/vs-files.js.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Barrel export for all MCP tool registrations.
|
|
3
|
+
*/
|
|
4
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
5
|
+
/**
|
|
6
|
+
* Register all OpenAI Vector Store tools on the given MCP server.
|
|
7
|
+
*
|
|
8
|
+
* Tools provided (17 total):
|
|
9
|
+
*
|
|
10
|
+
* Vector Stores:
|
|
11
|
+
* - openai_create_vector_store
|
|
12
|
+
* - openai_retrieve_vector_store
|
|
13
|
+
* - openai_update_vector_store
|
|
14
|
+
* - openai_delete_vector_store
|
|
15
|
+
* - openai_list_vector_stores
|
|
16
|
+
* - openai_search_vector_store
|
|
17
|
+
*
|
|
18
|
+
* Files (global):
|
|
19
|
+
* - openai_upload_file
|
|
20
|
+
* - openai_list_files
|
|
21
|
+
* - openai_retrieve_file
|
|
22
|
+
* - openai_delete_file
|
|
23
|
+
* - openai_retrieve_file_content
|
|
24
|
+
*
|
|
25
|
+
* Vector Store Files:
|
|
26
|
+
* - openai_attach_file_to_vector_store
|
|
27
|
+
* - openai_list_vector_store_files
|
|
28
|
+
* - openai_retrieve_vector_store_file
|
|
29
|
+
* - openai_delete_vector_store_file
|
|
30
|
+
* - openai_retrieve_vector_store_file_content
|
|
31
|
+
* - openai_update_vector_store_file_attributes
|
|
32
|
+
*
|
|
33
|
+
* Vector Store File Batches:
|
|
34
|
+
* - openai_create_vector_store_file_batch
|
|
35
|
+
* - openai_retrieve_vector_store_file_batch
|
|
36
|
+
* - openai_cancel_vector_store_file_batch
|
|
37
|
+
* - openai_list_vector_store_file_batch_files
|
|
38
|
+
*/
|
|
39
|
+
export declare function registerAllTools(server: McpServer): void;
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAOpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAMxD"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { registerVectorStoreTools } from "./vector-stores.js";
|
|
2
|
+
import { registerFileTools } from "./files.js";
|
|
3
|
+
import { registerVectorStoreFileTools } from "./vs-files.js";
|
|
4
|
+
import { registerVectorStoreFileBatchTools } from "./vs-file-batches.js";
|
|
5
|
+
import { registerUploadFileTool } from "./upload-file.js";
|
|
6
|
+
/**
|
|
7
|
+
* Register all OpenAI Vector Store tools on the given MCP server.
|
|
8
|
+
*
|
|
9
|
+
* Tools provided (17 total):
|
|
10
|
+
*
|
|
11
|
+
* Vector Stores:
|
|
12
|
+
* - openai_create_vector_store
|
|
13
|
+
* - openai_retrieve_vector_store
|
|
14
|
+
* - openai_update_vector_store
|
|
15
|
+
* - openai_delete_vector_store
|
|
16
|
+
* - openai_list_vector_stores
|
|
17
|
+
* - openai_search_vector_store
|
|
18
|
+
*
|
|
19
|
+
* Files (global):
|
|
20
|
+
* - openai_upload_file
|
|
21
|
+
* - openai_list_files
|
|
22
|
+
* - openai_retrieve_file
|
|
23
|
+
* - openai_delete_file
|
|
24
|
+
* - openai_retrieve_file_content
|
|
25
|
+
*
|
|
26
|
+
* Vector Store Files:
|
|
27
|
+
* - openai_attach_file_to_vector_store
|
|
28
|
+
* - openai_list_vector_store_files
|
|
29
|
+
* - openai_retrieve_vector_store_file
|
|
30
|
+
* - openai_delete_vector_store_file
|
|
31
|
+
* - openai_retrieve_vector_store_file_content
|
|
32
|
+
* - openai_update_vector_store_file_attributes
|
|
33
|
+
*
|
|
34
|
+
* Vector Store File Batches:
|
|
35
|
+
* - openai_create_vector_store_file_batch
|
|
36
|
+
* - openai_retrieve_vector_store_file_batch
|
|
37
|
+
* - openai_cancel_vector_store_file_batch
|
|
38
|
+
* - openai_list_vector_store_file_batch_files
|
|
39
|
+
*/
|
|
40
|
+
export function registerAllTools(server) {
|
|
41
|
+
registerVectorStoreTools(server);
|
|
42
|
+
registerFileTools(server);
|
|
43
|
+
registerVectorStoreFileTools(server);
|
|
44
|
+
registerVectorStoreFileBatchTools(server);
|
|
45
|
+
registerUploadFileTool(server);
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,iCAAiC,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAiB;IAChD,wBAAwB,CAAC,MAAM,CAAC,CAAC;IACjC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC1B,4BAA4B,CAAC,MAAM,CAAC,CAAC;IACrC,iCAAiC,CAAC,MAAM,CAAC,CAAC;IAC1C,sBAAsB,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vector Store Upload File tool for MCP.
|
|
3
|
+
*
|
|
4
|
+
* Uses OpenAI SDK's file upload (multipart/form-data).
|
|
5
|
+
* This is a standalone tool since upload requires file handling.
|
|
6
|
+
*/
|
|
7
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
export declare const UploadFileSchema: z.ZodObject<{
|
|
10
|
+
file_path: z.ZodString;
|
|
11
|
+
purpose: z.ZodEnum<["assistants", "batch", "fine-tune", "vision", "user_data", "evals"]>;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
purpose: "assistants" | "batch" | "fine-tune" | "vision" | "user_data" | "evals";
|
|
14
|
+
file_path: string;
|
|
15
|
+
}, {
|
|
16
|
+
purpose: "assistants" | "batch" | "fine-tune" | "vision" | "user_data" | "evals";
|
|
17
|
+
file_path: string;
|
|
18
|
+
}>;
|
|
19
|
+
export declare function registerUploadFileTool(server: McpServer): void;
|
|
20
|
+
//# sourceMappingURL=upload-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-file.d.ts","sourceRoot":"","sources":["../../src/tools/upload-file.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,gBAAgB;;;;;;;;;EAK3B,CAAC;AAEH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAsD9D"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { getClient } from "../client.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
export const UploadFileSchema = z.object({
|
|
6
|
+
file_path: z.string().describe("Absolute or relative path to the local file to upload."),
|
|
7
|
+
purpose: z
|
|
8
|
+
.enum(["assistants", "batch", "fine-tune", "vision", "user_data", "evals"])
|
|
9
|
+
.describe("The intended purpose of the uploaded file."),
|
|
10
|
+
});
|
|
11
|
+
export function registerUploadFileTool(server) {
|
|
12
|
+
server.registerTool("openai_upload_file", {
|
|
13
|
+
title: "Upload File",
|
|
14
|
+
description: `Upload a local file to OpenAI.
|
|
15
|
+
|
|
16
|
+
The file is uploaded using multipart/form-data. Once uploaded, you can attach the returned file ID to a vector store using openai_attach_file_to_vector_store.
|
|
17
|
+
|
|
18
|
+
Supported purposes:
|
|
19
|
+
- **assistants**: Used in the Assistants API
|
|
20
|
+
- **batch**: Used in the Batch API
|
|
21
|
+
- **fine-tune**: Used for fine-tuning
|
|
22
|
+
- **vision**: Images for vision fine-tuning
|
|
23
|
+
- **user_data**: Flexible file type for any purpose
|
|
24
|
+
- **evals**: Used for eval data sets
|
|
25
|
+
|
|
26
|
+
Individual files can be up to 512 MB.`,
|
|
27
|
+
inputSchema: UploadFileSchema.shape,
|
|
28
|
+
annotations: {
|
|
29
|
+
readOnlyHint: false,
|
|
30
|
+
destructiveHint: false,
|
|
31
|
+
idempotentHint: false,
|
|
32
|
+
openWorldHint: true,
|
|
33
|
+
},
|
|
34
|
+
}, async (params) => {
|
|
35
|
+
try {
|
|
36
|
+
const client = getClient();
|
|
37
|
+
const filePath = path.resolve(params.file_path);
|
|
38
|
+
if (!fs.existsSync(filePath)) {
|
|
39
|
+
return {
|
|
40
|
+
isError: true,
|
|
41
|
+
content: [{ type: "text", text: `Error: File not found at path: ${filePath}` }],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const file = await client.files.create({
|
|
45
|
+
file: fs.createReadStream(filePath),
|
|
46
|
+
purpose: params.purpose,
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
content: [{ type: "text", text: JSON.stringify(file, null, 2) }],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
return {
|
|
54
|
+
isError: true,
|
|
55
|
+
content: [{ type: "text", text: `Error uploading file: ${error instanceof Error ? error.message : String(error)}` }],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=upload-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-file.js","sourceRoot":"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ChF,CAAC;YACJ,CAAC;YAED,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;gBACrC,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC;gBACnC,OAAO,EAAE,MAAM,CAAC,OAAkF;aACnG,CAAC,CAAC;YAEH,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;aACjE,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,yBAAyB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;aACrH,CAAC;QACJ,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI Vector Store tools for MCP.
|
|
3
|
+
*
|
|
4
|
+
* Covers: create, retrieve, update, delete, list, search vector stores.
|
|
5
|
+
*/
|
|
6
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
7
|
+
export declare function registerVectorStoreTools(server: McpServer): void;
|
|
8
|
+
//# sourceMappingURL=vector-stores.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector-stores.d.ts","sourceRoot":"","sources":["../../src/tools/vector-stores.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAyCpE,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAgRhE"}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { getClient } from "../client.js";
|
|
2
|
+
import { CreateVectorStoreSchema, UpdateVectorStoreSchema, RetrieveVectorStoreSchema, DeleteVectorStoreSchema, ListVectorStoresSchema, SearchVectorStoreSchema, } from "../schemas/index.js";
|
|
3
|
+
function formatVectorStore(vs, format) {
|
|
4
|
+
if (format === "json")
|
|
5
|
+
return JSON.stringify(vs, null, 2);
|
|
6
|
+
const lines = [
|
|
7
|
+
`### Vector Store: ${vs.name ?? "Untitled"}`,
|
|
8
|
+
"",
|
|
9
|
+
`- **ID**: \`${vs.id}\``,
|
|
10
|
+
`- **Created**: ${new Date(vs.created_at * 1000).toISOString()}`,
|
|
11
|
+
];
|
|
12
|
+
const fc = vs.file_counts;
|
|
13
|
+
if (fc) {
|
|
14
|
+
lines.push(`- **Files**: ${fc.total} total (${fc.completed} completed, ${fc.in_progress} in progress, ${fc.failed} failed, ${fc.cancelled} cancelled)`);
|
|
15
|
+
}
|
|
16
|
+
if (vs.last_active_at) {
|
|
17
|
+
lines.push(`- **Last Active**: ${new Date(vs.last_active_at * 1000).toISOString()}`);
|
|
18
|
+
}
|
|
19
|
+
if (vs.metadata && Object.keys(vs.metadata).length > 0) {
|
|
20
|
+
lines.push(`- **Metadata**: \`${JSON.stringify(vs.metadata)}\``);
|
|
21
|
+
}
|
|
22
|
+
lines.push("");
|
|
23
|
+
return lines.join("\n");
|
|
24
|
+
}
|
|
25
|
+
export function registerVectorStoreTools(server) {
|
|
26
|
+
server.registerTool("openai_create_vector_store", {
|
|
27
|
+
title: "Create Vector Store",
|
|
28
|
+
description: `Create a new OpenAI vector store — a collection of processed files that can be used with the \`file_search\` tool.
|
|
29
|
+
|
|
30
|
+
Use this when you need a new vector store to hold uploaded documents for semantic search or retrieval-augmented generation (RAG).
|
|
31
|
+
|
|
32
|
+
You can optionally provide file_ids to attach already-uploaded files, a chunking strategy, and metadata (up to 16 key-value pairs).`,
|
|
33
|
+
inputSchema: CreateVectorStoreSchema.shape,
|
|
34
|
+
annotations: {
|
|
35
|
+
readOnlyHint: false,
|
|
36
|
+
destructiveHint: false,
|
|
37
|
+
idempotentHint: false,
|
|
38
|
+
openWorldHint: true,
|
|
39
|
+
},
|
|
40
|
+
}, async (params) => {
|
|
41
|
+
try {
|
|
42
|
+
const client = getClient();
|
|
43
|
+
const vs = await client.vectorStores.create({
|
|
44
|
+
name: params.name,
|
|
45
|
+
file_ids: params.file_ids,
|
|
46
|
+
expires_after: params.expires_after,
|
|
47
|
+
metadata: params.metadata,
|
|
48
|
+
chunking_strategy: params.chunking_strategy,
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
content: [{ type: "text", text: formatVectorStore(vs, "json") }],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
return {
|
|
56
|
+
isError: true,
|
|
57
|
+
content: [{ type: "text", text: `Error creating vector store: ${error instanceof Error ? error.message : String(error)}` }],
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
server.registerTool("openai_retrieve_vector_store", {
|
|
62
|
+
title: "Retrieve Vector Store",
|
|
63
|
+
description: `Retrieve details of a specific OpenAI vector store by its ID.
|
|
64
|
+
|
|
65
|
+
Use this to check the status, file counts, metadata, and other properties of an existing vector store.`,
|
|
66
|
+
inputSchema: RetrieveVectorStoreSchema.shape,
|
|
67
|
+
annotations: {
|
|
68
|
+
readOnlyHint: true,
|
|
69
|
+
destructiveHint: false,
|
|
70
|
+
idempotentHint: true,
|
|
71
|
+
openWorldHint: true,
|
|
72
|
+
},
|
|
73
|
+
}, async (params) => {
|
|
74
|
+
try {
|
|
75
|
+
const client = getClient();
|
|
76
|
+
const vs = await client.vectorStores.retrieve(params.vector_store_id);
|
|
77
|
+
return {
|
|
78
|
+
content: [{ type: "text", text: formatVectorStore(vs, "json") }],
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
return {
|
|
83
|
+
isError: true,
|
|
84
|
+
content: [{ type: "text", text: `Error retrieving vector store: ${error instanceof Error ? error.message : String(error)}` }],
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
server.registerTool("openai_update_vector_store", {
|
|
89
|
+
title: "Update Vector Store",
|
|
90
|
+
description: `Modify an existing OpenAI vector store — rename it, update metadata, or change the expiration policy.
|
|
91
|
+
|
|
92
|
+
Use this when you need to update properties of an existing vector store without recreating it.`,
|
|
93
|
+
inputSchema: UpdateVectorStoreSchema.shape,
|
|
94
|
+
annotations: {
|
|
95
|
+
readOnlyHint: false,
|
|
96
|
+
destructiveHint: false,
|
|
97
|
+
idempotentHint: true,
|
|
98
|
+
openWorldHint: true,
|
|
99
|
+
},
|
|
100
|
+
}, async (params) => {
|
|
101
|
+
try {
|
|
102
|
+
const client = getClient();
|
|
103
|
+
const { vector_store_id, ...body } = params;
|
|
104
|
+
const vs = await client.vectorStores.update(vector_store_id, {
|
|
105
|
+
name: body.name,
|
|
106
|
+
expires_after: body.expires_after,
|
|
107
|
+
metadata: body.metadata,
|
|
108
|
+
});
|
|
109
|
+
return {
|
|
110
|
+
content: [{ type: "text", text: formatVectorStore(vs, "json") }],
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
return {
|
|
115
|
+
isError: true,
|
|
116
|
+
content: [{ type: "text", text: `Error updating vector store: ${error instanceof Error ? error.message : String(error)}` }],
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
server.registerTool("openai_delete_vector_store", {
|
|
121
|
+
title: "Delete Vector Store",
|
|
122
|
+
description: `Permanently delete an OpenAI vector store by its ID.
|
|
123
|
+
|
|
124
|
+
This will remove the vector store and all its associated files. This action cannot be undone.`,
|
|
125
|
+
inputSchema: DeleteVectorStoreSchema.shape,
|
|
126
|
+
annotations: {
|
|
127
|
+
readOnlyHint: false,
|
|
128
|
+
destructiveHint: true,
|
|
129
|
+
idempotentHint: true,
|
|
130
|
+
openWorldHint: true,
|
|
131
|
+
},
|
|
132
|
+
}, async (params) => {
|
|
133
|
+
try {
|
|
134
|
+
const client = getClient();
|
|
135
|
+
const result = await client.vectorStores.del(params.vector_store_id);
|
|
136
|
+
return {
|
|
137
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
return {
|
|
142
|
+
isError: true,
|
|
143
|
+
content: [{ type: "text", text: `Error deleting vector store: ${error instanceof Error ? error.message : String(error)}` }],
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
server.registerTool("openai_list_vector_stores", {
|
|
148
|
+
title: "List Vector Stores",
|
|
149
|
+
description: `List all OpenAI vector stores with pagination support.
|
|
150
|
+
|
|
151
|
+
Returns a paginated list of vector stores in your project. Use 'after' or 'before' cursors to navigate pages.`,
|
|
152
|
+
inputSchema: ListVectorStoresSchema.shape,
|
|
153
|
+
annotations: {
|
|
154
|
+
readOnlyHint: true,
|
|
155
|
+
destructiveHint: false,
|
|
156
|
+
idempotentHint: true,
|
|
157
|
+
openWorldHint: true,
|
|
158
|
+
},
|
|
159
|
+
}, async (params) => {
|
|
160
|
+
try {
|
|
161
|
+
const client = getClient();
|
|
162
|
+
const page = await client.vectorStores.list({
|
|
163
|
+
after: params.after,
|
|
164
|
+
before: params.before,
|
|
165
|
+
limit: params.limit,
|
|
166
|
+
order: params.order,
|
|
167
|
+
});
|
|
168
|
+
const data = page.data;
|
|
169
|
+
const format = params.response_format;
|
|
170
|
+
if (format === "json") {
|
|
171
|
+
return {
|
|
172
|
+
content: [
|
|
173
|
+
{
|
|
174
|
+
type: "text",
|
|
175
|
+
text: JSON.stringify({ total: data.length, stores: data }, null, 2),
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
const lines = [
|
|
181
|
+
`# Vector Stores (${data.length} results)`,
|
|
182
|
+
"",
|
|
183
|
+
];
|
|
184
|
+
for (const vs of data) {
|
|
185
|
+
lines.push(formatVectorStore(vs, "markdown"));
|
|
186
|
+
}
|
|
187
|
+
return { content: [{ type: "text", text: lines.join("\n") }] };
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
return {
|
|
191
|
+
isError: true,
|
|
192
|
+
content: [{ type: "text", text: `Error listing vector stores: ${error instanceof Error ? error.message : String(error)}` }],
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
server.registerTool("openai_search_vector_store", {
|
|
197
|
+
title: "Search Vector Store",
|
|
198
|
+
description: `Search an OpenAI vector store for relevant chunks based on a query and optional file-attribute filters.
|
|
199
|
+
|
|
200
|
+
Use this to perform semantic search across the documents in a vector store. You can provide a single query string or an array of queries, and optionally filter by file attributes (e.g., department = "engineering").
|
|
201
|
+
|
|
202
|
+
Results include ranked search hits with content snippets, file IDs, and relevance scores.`,
|
|
203
|
+
inputSchema: SearchVectorStoreSchema.shape,
|
|
204
|
+
annotations: {
|
|
205
|
+
readOnlyHint: true,
|
|
206
|
+
destructiveHint: false,
|
|
207
|
+
idempotentHint: true,
|
|
208
|
+
openWorldHint: true,
|
|
209
|
+
},
|
|
210
|
+
}, async (params) => {
|
|
211
|
+
try {
|
|
212
|
+
const client = getClient();
|
|
213
|
+
const format = params.response_format;
|
|
214
|
+
const { vector_store_id, query, max_num_results, rewrite_query, filters, response_format: _fmt, ...rest } = params;
|
|
215
|
+
const searchBody = {
|
|
216
|
+
query,
|
|
217
|
+
max_num_results,
|
|
218
|
+
rewrite_query,
|
|
219
|
+
};
|
|
220
|
+
if (filters) {
|
|
221
|
+
searchBody.filters = {
|
|
222
|
+
type: "comparison",
|
|
223
|
+
key: filters.key,
|
|
224
|
+
comparison: filters.type,
|
|
225
|
+
value: filters.value,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
const page = await client.vectorStores.search(vector_store_id, searchBody);
|
|
229
|
+
const data = page.data;
|
|
230
|
+
if (format === "json") {
|
|
231
|
+
return {
|
|
232
|
+
content: [{ type: "text", text: JSON.stringify({ total: data.length, results: data }, null, 2) }],
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
const lines = [
|
|
236
|
+
`# Search Results for vector store \`${vector_store_id}\``,
|
|
237
|
+
"",
|
|
238
|
+
`Found **${data.length}** result(s).`,
|
|
239
|
+
"",
|
|
240
|
+
];
|
|
241
|
+
for (const [i, r] of data.entries()) {
|
|
242
|
+
lines.push(`## ${i + 1}. ${r.file_id ?? "Unknown File"}`);
|
|
243
|
+
if (r.filename)
|
|
244
|
+
lines.push(`- **Filename**: ${r.filename}`);
|
|
245
|
+
if (r.score !== undefined) {
|
|
246
|
+
lines.push(`- **Score**: ${String(r.score)}`);
|
|
247
|
+
}
|
|
248
|
+
const content = r.content;
|
|
249
|
+
if (content && Array.isArray(content)) {
|
|
250
|
+
for (const c of content) {
|
|
251
|
+
if (c.text)
|
|
252
|
+
lines.push(`\n> ${c.text.substring(0, 500)}${c.text.length > 500 ? "…" : ""}`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
lines.push("");
|
|
256
|
+
}
|
|
257
|
+
return { content: [{ type: "text", text: lines.join("\n") }] };
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
return {
|
|
261
|
+
isError: true,
|
|
262
|
+
content: [{ type: "text", text: `Error searching vector store: ${error instanceof Error ? error.message : String(error)}` }],
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
//# sourceMappingURL=vector-stores.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector-stores.js","sourceRoot":"","sources":["../../src/tools/vector-stores.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,yBAAyB,EACzB,uBAAu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ector Store File Batch tools for MCP.
|
|
3
|
+
*
|
|
4
|
+
* Covers: create batch, retrieve batch, cancel batch, list batch files.
|
|
5
|
+
*/
|
|
6
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
7
|
+
export declare function registerVectorStoreFileBatchTools(server: McpServer): void;
|
|
8
|
+
//# sourceMappingURL=vs-file-batches.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vs-file-batches.d.ts","sourceRoot":"","sources":["../../src/tools/vs-file-batches.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AA+BpE,wBAAgB,iCAAiC,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAiKzE"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { getClient } from "../client.js";
|
|
2
|
+
import { CreateVectorStoreFileBatchSchema, RetrieveVectorStoreFileBatchSchema, CancelVectorStoreFileBatchSchema, ListVectorStoreFileBatchFilesSchema, } from "../schemas/index.js";
|
|
3
|
+
function formatBatch(b, format) {
|
|
4
|
+
if (format === "json")
|
|
5
|
+
return JSON.stringify(b, null, 2);
|
|
6
|
+
const lines = [
|
|
7
|
+
`### File Batch: ${b.id}`,
|
|
8
|
+
"",
|
|
9
|
+
`- **Created**: ${new Date(b.created_at * 1000).toISOString()}`,
|
|
10
|
+
`- **Status**: ${b.status ?? "unknown"}`,
|
|
11
|
+
];
|
|
12
|
+
const fc = b.file_counts;
|
|
13
|
+
if (fc) {
|
|
14
|
+
lines.push(`- **Files**: ${fc.total} total (${fc.completed} completed, ${fc.in_progress} in progress, ${fc.failed} failed, ${fc.cancelled} cancelled)`);
|
|
15
|
+
}
|
|
16
|
+
if (b.metadata && Object.keys(b.metadata).length > 0) {
|
|
17
|
+
lines.push(`- **Metadata**: \`${JSON.stringify(b.metadata)}\``);
|
|
18
|
+
}
|
|
19
|
+
lines.push("");
|
|
20
|
+
return lines.join("\n");
|
|
21
|
+
}
|
|
22
|
+
export function registerVectorStoreFileBatchTools(server) {
|
|
23
|
+
server.registerTool("openai_create_vector_store_file_batch", {
|
|
24
|
+
title: "Create Vector Store File Batch",
|
|
25
|
+
description: `Create a batch of files to attach to a vector store.
|
|
26
|
+
|
|
27
|
+
This is the recommended way to attach multiple files at once — it minimizes per-vector-store write requests and is more efficient than attaching files one by one.`,
|
|
28
|
+
inputSchema: CreateVectorStoreFileBatchSchema.shape,
|
|
29
|
+
annotations: {
|
|
30
|
+
readOnlyHint: false,
|
|
31
|
+
destructiveHint: false,
|
|
32
|
+
idempotentHint: false,
|
|
33
|
+
openWorldHint: true,
|
|
34
|
+
},
|
|
35
|
+
}, async (params) => {
|
|
36
|
+
try {
|
|
37
|
+
const client = getClient();
|
|
38
|
+
const result = await client.vectorStores.fileBatches.create(params.vector_store_id, {
|
|
39
|
+
file_ids: params.file_ids,
|
|
40
|
+
attributes: params.attributes,
|
|
41
|
+
chunking_strategy: params.chunking_strategy,
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
content: [{ type: "text", text: formatBatch(result, "json") }],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
return {
|
|
49
|
+
isError: true,
|
|
50
|
+
content: [{ type: "text", text: `Error creating file batch: ${error instanceof Error ? error.message : String(error)}` }],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
server.registerTool("openai_retrieve_vector_store_file_batch", {
|
|
55
|
+
title: "Retrieve Vector Store File Batch",
|
|
56
|
+
description: `Retrieve the status and details of a file batch, including file counts by status.`,
|
|
57
|
+
inputSchema: RetrieveVectorStoreFileBatchSchema.shape,
|
|
58
|
+
annotations: {
|
|
59
|
+
readOnlyHint: true,
|
|
60
|
+
destructiveHint: false,
|
|
61
|
+
idempotentHint: true,
|
|
62
|
+
openWorldHint: true,
|
|
63
|
+
},
|
|
64
|
+
}, async (params) => {
|
|
65
|
+
try {
|
|
66
|
+
const client = getClient();
|
|
67
|
+
const result = await client.vectorStores.fileBatches.retrieve(params.vector_store_id, params.batch_id);
|
|
68
|
+
return {
|
|
69
|
+
content: [{ type: "text", text: formatBatch(result, "json") }],
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
return {
|
|
74
|
+
isError: true,
|
|
75
|
+
content: [{ type: "text", text: `Error retrieving file batch: ${error instanceof Error ? error.message : String(error)}` }],
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
server.registerTool("openai_cancel_vector_store_file_batch", {
|
|
80
|
+
title: "Cancel Vector Store File Batch",
|
|
81
|
+
description: `Cancel processing of a file batch as soon as possible.
|
|
82
|
+
|
|
83
|
+
Use this to stop ingestion of files that are still being processed. Already-processed files will remain attached.`,
|
|
84
|
+
inputSchema: CancelVectorStoreFileBatchSchema.shape,
|
|
85
|
+
annotations: {
|
|
86
|
+
readOnlyHint: false,
|
|
87
|
+
destructiveHint: false,
|
|
88
|
+
idempotentHint: false,
|
|
89
|
+
openWorldHint: true,
|
|
90
|
+
},
|
|
91
|
+
}, async (params) => {
|
|
92
|
+
try {
|
|
93
|
+
const client = getClient();
|
|
94
|
+
const result = await client.vectorStores.fileBatches.cancel(params.vector_store_id, params.batch_id);
|
|
95
|
+
return {
|
|
96
|
+
content: [{ type: "text", text: formatBatch(result, "json") }],
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
return {
|
|
101
|
+
isError: true,
|
|
102
|
+
content: [{ type: "text", text: `Error cancelling file batch: ${error instanceof Error ? error.message : String(error)}` }],
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
server.registerTool("openai_list_vector_store_file_batch_files", {
|
|
107
|
+
title: "List Vector Store File Batch Files",
|
|
108
|
+
description: `List all files in a specific file batch with pagination and optional status filter.
|
|
109
|
+
|
|
110
|
+
Use this to inspect which files in a batch have been processed, are still in progress, or have failed.`,
|
|
111
|
+
inputSchema: ListVectorStoreFileBatchFilesSchema.shape,
|
|
112
|
+
annotations: {
|
|
113
|
+
readOnlyHint: true,
|
|
114
|
+
destructiveHint: false,
|
|
115
|
+
idempotentHint: true,
|
|
116
|
+
openWorldHint: true,
|
|
117
|
+
},
|
|
118
|
+
}, async (params) => {
|
|
119
|
+
try {
|
|
120
|
+
const client = getClient();
|
|
121
|
+
const format = params.response_format;
|
|
122
|
+
const page = await client.vectorStores.fileBatches.listFiles(params.vector_store_id, params.batch_id, {
|
|
123
|
+
after: params.after,
|
|
124
|
+
before: params.before,
|
|
125
|
+
filter: params.filter,
|
|
126
|
+
limit: params.limit,
|
|
127
|
+
order: params.order,
|
|
128
|
+
});
|
|
129
|
+
const data = page.data;
|
|
130
|
+
if (format === "json") {
|
|
131
|
+
return {
|
|
132
|
+
content: [{ type: "text", text: JSON.stringify({ total: data.length, files: data }, null, 2) }],
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
const lines = [
|
|
136
|
+
`# Batch Files (${data.length} results)`,
|
|
137
|
+
"",
|
|
138
|
+
];
|
|
139
|
+
for (const f of data) {
|
|
140
|
+
lines.push(`- **\`${f.id}\`** — Status: ${f.status ?? "unknown"}`);
|
|
141
|
+
const err = f.last_error;
|
|
142
|
+
if (err) {
|
|
143
|
+
lines.push(` - Error: ${err.code} — ${err.message}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
lines.push("");
|
|
147
|
+
return { content: [{ type: "text", text: lines.join("\n") }] };
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
return {
|
|
151
|
+
isError: true,
|
|
152
|
+
content: [{ type: "text", text: `Error listing batch files: ${error instanceof Error ? error.message : String(error)}` }],
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=vs-file-batches.js.map
|