@moorchehai/mcp 1.3.2 → 1.3.4
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 +16 -10
- package/package.json +1 -1
- package/src/server/index.js +247 -225
- package/src/server/tools/data-tools.js +356 -209
- package/src/server/tools/namespace-tools.js +129 -129
- package/src/server/tools/search-tools.js +13 -1
- package/src/server/utils/prompts.js +358 -358
- package/src/server/utils/resources.js +7 -18
|
@@ -1,210 +1,357 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { makeApiRequest, API_ENDPOINTS, uploadFile } from '../config/api.js';
|
|
3
|
-
|
|
4
|
-
// Upload text documents tool
|
|
5
|
-
export const uploadTextTool = {
|
|
6
|
-
name: "upload-text",
|
|
7
|
-
description: "Upload text documents to a namespace in Moorcheh",
|
|
8
|
-
parameters: {
|
|
9
|
-
namespace_name: z.string().describe("Name of the namespace to upload to"),
|
|
10
|
-
documents: z.array(z.object({
|
|
11
|
-
id: z.string().describe("Unique identifier for the document"),
|
|
12
|
-
text: z.string().describe("Text content of the document"),
|
|
13
|
-
metadata: z.record(z.string(), z.any()).optional().describe("Optional metadata for the document. Will be flattened as top-level fields to match API format."),
|
|
14
|
-
})).describe("Array of documents to upload"),
|
|
15
|
-
},
|
|
16
|
-
handler: async ({ namespace_name, documents }) => {
|
|
17
|
-
try {
|
|
18
|
-
const normalizedDocuments = documents.map((doc) => {
|
|
19
|
-
const { metadata, ...rest } = doc;
|
|
20
|
-
return metadata && typeof metadata === 'object'
|
|
21
|
-
? { ...rest, ...metadata }
|
|
22
|
-
: rest;
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const data = await makeApiRequest('POST', `${API_ENDPOINTS.namespaces}/${namespace_name}/documents`, {
|
|
26
|
-
documents: normalizedDocuments,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const resultText = `Successfully uploaded ${documents.length} document(s) to namespace "${namespace_name}":\n${JSON.stringify(data, null, 2)}`;
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
content: [
|
|
33
|
-
{
|
|
34
|
-
type: "text",
|
|
35
|
-
text: resultText,
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
};
|
|
39
|
-
} catch (error) {
|
|
40
|
-
return {
|
|
41
|
-
content: [
|
|
42
|
-
{
|
|
43
|
-
type: "text",
|
|
44
|
-
text: `Error uploading text documents: ${error.message}`,
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
// Upload vectors tool
|
|
53
|
-
export const uploadVectorsTool = {
|
|
54
|
-
name: "upload-vectors",
|
|
55
|
-
description: "Upload vector data to a namespace in Moorcheh",
|
|
56
|
-
parameters: {
|
|
57
|
-
namespace_name: z.string().describe("Name of the namespace to upload to"),
|
|
58
|
-
vectors: z.array(z.object({
|
|
59
|
-
id: z.string().describe("Unique identifier for the vector"),
|
|
60
|
-
vector: z.array(z.number()).describe("Vector values"),
|
|
61
|
-
text: z.string().optional().describe("Optional original text for the vector"),
|
|
62
|
-
metadata: z.record(z.string(), z.any()).optional().describe("Optional metadata for the vector. Will be flattened as top-level fields to match API format."),
|
|
63
|
-
})).describe("Array of vectors to upload"),
|
|
64
|
-
},
|
|
65
|
-
handler: async ({ namespace_name, vectors }) => {
|
|
66
|
-
try {
|
|
67
|
-
const normalizedVectors = vectors.map((vectorItem) => {
|
|
68
|
-
const { metadata, ...rest } = vectorItem;
|
|
69
|
-
return metadata && typeof metadata === 'object'
|
|
70
|
-
? { ...rest, ...metadata }
|
|
71
|
-
: rest;
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
const data = await makeApiRequest('POST', `${API_ENDPOINTS.namespaces}/${namespace_name}/vectors`, {
|
|
75
|
-
vectors: normalizedVectors,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const resultText = `Successfully uploaded ${vectors.length} vector(s) to namespace "${namespace_name}":\n${JSON.stringify(data, null, 2)}`;
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
content: [
|
|
82
|
-
{
|
|
83
|
-
type: "text",
|
|
84
|
-
text: resultText,
|
|
85
|
-
},
|
|
86
|
-
],
|
|
87
|
-
};
|
|
88
|
-
} catch (error) {
|
|
89
|
-
return {
|
|
90
|
-
content: [
|
|
91
|
-
{
|
|
92
|
-
type: "text",
|
|
93
|
-
text: `Error uploading vectors: ${error.message}`,
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
// Delete data tool
|
|
102
|
-
export const deleteDataTool = {
|
|
103
|
-
name: "delete-data",
|
|
104
|
-
description: "Delete specific data items from a namespace in Moorcheh",
|
|
105
|
-
parameters: {
|
|
106
|
-
namespace_name: z.string().describe("Name of the namespace to delete from"),
|
|
107
|
-
data_type: z.enum(["documents", "vectors"]).optional().describe("Data type to delete from. Use 'documents' for text namespaces and 'vectors' for vector namespaces. Default is 'documents'."),
|
|
108
|
-
ids: z.array(z.string()).describe("Array of document/vector IDs to delete"),
|
|
109
|
-
},
|
|
110
|
-
handler: async ({ namespace_name, data_type = "documents", ids }) => {
|
|
111
|
-
try {
|
|
112
|
-
const data = await makeApiRequest('POST', `${API_ENDPOINTS.namespaces}/${namespace_name}/${data_type}/delete`, {
|
|
113
|
-
ids,
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
const resultText = `Successfully processed deletion of ${ids.length} ${data_type} item(s) in namespace "${namespace_name}":\n${JSON.stringify(data, null, 2)}`;
|
|
117
|
-
|
|
118
|
-
return {
|
|
119
|
-
content: [
|
|
120
|
-
{
|
|
121
|
-
type: "text",
|
|
122
|
-
text: resultText,
|
|
123
|
-
},
|
|
124
|
-
],
|
|
125
|
-
};
|
|
126
|
-
} catch (error) {
|
|
127
|
-
return {
|
|
128
|
-
content: [
|
|
129
|
-
{
|
|
130
|
-
type: "text",
|
|
131
|
-
text: `Error deleting data: ${error.message}`,
|
|
132
|
-
},
|
|
133
|
-
],
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
// Get data by IDs tool (for text namespaces)
|
|
140
|
-
export const getDataTool = {
|
|
141
|
-
name: "get-data",
|
|
142
|
-
description: "Get specific data items by ID from a text namespace in Moorcheh",
|
|
143
|
-
parameters: {
|
|
144
|
-
namespace_name: z.string().describe("Name of the text namespace to read from"),
|
|
145
|
-
ids: z.array(z.string()).describe("Array of document IDs to retrieve"),
|
|
146
|
-
},
|
|
147
|
-
handler: async ({ namespace_name, ids }) => {
|
|
148
|
-
try {
|
|
149
|
-
const data = await makeApiRequest('POST', `${API_ENDPOINTS.namespaces}/${namespace_name}/documents/get`, {
|
|
150
|
-
ids,
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
const resultText = `Fetched ${ids.length} item(s) from namespace "${namespace_name}":\n${JSON.stringify(data, null, 2)}`;
|
|
154
|
-
|
|
155
|
-
return {
|
|
156
|
-
content: [
|
|
157
|
-
{
|
|
158
|
-
type: "text",
|
|
159
|
-
text: resultText,
|
|
160
|
-
},
|
|
161
|
-
],
|
|
162
|
-
};
|
|
163
|
-
} catch (error) {
|
|
164
|
-
return {
|
|
165
|
-
content: [
|
|
166
|
-
{
|
|
167
|
-
type: "text",
|
|
168
|
-
text: `Error fetching data: ${error.message}`,
|
|
169
|
-
},
|
|
170
|
-
],
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
},
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
//
|
|
177
|
-
export const
|
|
178
|
-
name: "
|
|
179
|
-
description:
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { makeApiRequest, API_ENDPOINTS, uploadFile } from '../config/api.js';
|
|
3
|
+
|
|
4
|
+
// Upload text documents tool
|
|
5
|
+
export const uploadTextTool = {
|
|
6
|
+
name: "upload-text",
|
|
7
|
+
description: "Upload text documents to a namespace in Moorcheh",
|
|
8
|
+
parameters: {
|
|
9
|
+
namespace_name: z.string().describe("Name of the namespace to upload to"),
|
|
10
|
+
documents: z.array(z.object({
|
|
11
|
+
id: z.string().describe("Unique identifier for the document"),
|
|
12
|
+
text: z.string().describe("Text content of the document"),
|
|
13
|
+
metadata: z.record(z.string(), z.any()).optional().describe("Optional metadata for the document. Will be flattened as top-level fields to match API format."),
|
|
14
|
+
})).describe("Array of documents to upload"),
|
|
15
|
+
},
|
|
16
|
+
handler: async ({ namespace_name, documents }) => {
|
|
17
|
+
try {
|
|
18
|
+
const normalizedDocuments = documents.map((doc) => {
|
|
19
|
+
const { metadata, ...rest } = doc;
|
|
20
|
+
return metadata && typeof metadata === 'object'
|
|
21
|
+
? { ...rest, ...metadata }
|
|
22
|
+
: rest;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const data = await makeApiRequest('POST', `${API_ENDPOINTS.namespaces}/${namespace_name}/documents`, {
|
|
26
|
+
documents: normalizedDocuments,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const resultText = `Successfully uploaded ${documents.length} document(s) to namespace "${namespace_name}":\n${JSON.stringify(data, null, 2)}`;
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
content: [
|
|
33
|
+
{
|
|
34
|
+
type: "text",
|
|
35
|
+
text: resultText,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
} catch (error) {
|
|
40
|
+
return {
|
|
41
|
+
content: [
|
|
42
|
+
{
|
|
43
|
+
type: "text",
|
|
44
|
+
text: `Error uploading text documents: ${error.message}`,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Upload vectors tool
|
|
53
|
+
export const uploadVectorsTool = {
|
|
54
|
+
name: "upload-vectors",
|
|
55
|
+
description: "Upload vector data to a namespace in Moorcheh",
|
|
56
|
+
parameters: {
|
|
57
|
+
namespace_name: z.string().describe("Name of the namespace to upload to"),
|
|
58
|
+
vectors: z.array(z.object({
|
|
59
|
+
id: z.string().describe("Unique identifier for the vector"),
|
|
60
|
+
vector: z.array(z.number()).describe("Vector values"),
|
|
61
|
+
text: z.string().optional().describe("Optional original text for the vector"),
|
|
62
|
+
metadata: z.record(z.string(), z.any()).optional().describe("Optional metadata for the vector. Will be flattened as top-level fields to match API format."),
|
|
63
|
+
})).describe("Array of vectors to upload"),
|
|
64
|
+
},
|
|
65
|
+
handler: async ({ namespace_name, vectors }) => {
|
|
66
|
+
try {
|
|
67
|
+
const normalizedVectors = vectors.map((vectorItem) => {
|
|
68
|
+
const { metadata, ...rest } = vectorItem;
|
|
69
|
+
return metadata && typeof metadata === 'object'
|
|
70
|
+
? { ...rest, ...metadata }
|
|
71
|
+
: rest;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const data = await makeApiRequest('POST', `${API_ENDPOINTS.namespaces}/${namespace_name}/vectors`, {
|
|
75
|
+
vectors: normalizedVectors,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const resultText = `Successfully uploaded ${vectors.length} vector(s) to namespace "${namespace_name}":\n${JSON.stringify(data, null, 2)}`;
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
content: [
|
|
82
|
+
{
|
|
83
|
+
type: "text",
|
|
84
|
+
text: resultText,
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
};
|
|
88
|
+
} catch (error) {
|
|
89
|
+
return {
|
|
90
|
+
content: [
|
|
91
|
+
{
|
|
92
|
+
type: "text",
|
|
93
|
+
text: `Error uploading vectors: ${error.message}`,
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// Delete data tool
|
|
102
|
+
export const deleteDataTool = {
|
|
103
|
+
name: "delete-data",
|
|
104
|
+
description: "Delete specific data items from a namespace in Moorcheh",
|
|
105
|
+
parameters: {
|
|
106
|
+
namespace_name: z.string().describe("Name of the namespace to delete from"),
|
|
107
|
+
data_type: z.enum(["documents", "vectors"]).optional().describe("Data type to delete from. Use 'documents' for text namespaces and 'vectors' for vector namespaces. Default is 'documents'."),
|
|
108
|
+
ids: z.array(z.string()).describe("Array of document/vector IDs to delete"),
|
|
109
|
+
},
|
|
110
|
+
handler: async ({ namespace_name, data_type = "documents", ids }) => {
|
|
111
|
+
try {
|
|
112
|
+
const data = await makeApiRequest('POST', `${API_ENDPOINTS.namespaces}/${namespace_name}/${data_type}/delete`, {
|
|
113
|
+
ids,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const resultText = `Successfully processed deletion of ${ids.length} ${data_type} item(s) in namespace "${namespace_name}":\n${JSON.stringify(data, null, 2)}`;
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
content: [
|
|
120
|
+
{
|
|
121
|
+
type: "text",
|
|
122
|
+
text: resultText,
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
};
|
|
126
|
+
} catch (error) {
|
|
127
|
+
return {
|
|
128
|
+
content: [
|
|
129
|
+
{
|
|
130
|
+
type: "text",
|
|
131
|
+
text: `Error deleting data: ${error.message}`,
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// Get data by IDs tool (for text namespaces)
|
|
140
|
+
export const getDataTool = {
|
|
141
|
+
name: "get-data",
|
|
142
|
+
description: "Get specific data items by ID from a text namespace in Moorcheh",
|
|
143
|
+
parameters: {
|
|
144
|
+
namespace_name: z.string().describe("Name of the text namespace to read from"),
|
|
145
|
+
ids: z.array(z.string()).describe("Array of document IDs to retrieve"),
|
|
146
|
+
},
|
|
147
|
+
handler: async ({ namespace_name, ids }) => {
|
|
148
|
+
try {
|
|
149
|
+
const data = await makeApiRequest('POST', `${API_ENDPOINTS.namespaces}/${namespace_name}/documents/get`, {
|
|
150
|
+
ids,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const resultText = `Fetched ${ids.length} item(s) from namespace "${namespace_name}":\n${JSON.stringify(data, null, 2)}`;
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
content: [
|
|
157
|
+
{
|
|
158
|
+
type: "text",
|
|
159
|
+
text: resultText,
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
};
|
|
163
|
+
} catch (error) {
|
|
164
|
+
return {
|
|
165
|
+
content: [
|
|
166
|
+
{
|
|
167
|
+
type: "text",
|
|
168
|
+
text: `Error fetching data: ${error.message}`,
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// Fetch text chunks from a text namespace (list / export / RAG)
|
|
177
|
+
export const fetchTextDataTool = {
|
|
178
|
+
name: "fetch-text-data",
|
|
179
|
+
description:
|
|
180
|
+
"List text and summary chunks from a text-type namespace via GET /documents/fetch-text-data. Returns up to 100 items per request with statistics (text vs summary counts, source_counts). Only text namespaces are supported; not for vector namespaces. See Moorcheh API docs.",
|
|
181
|
+
parameters: {
|
|
182
|
+
namespace_name: z
|
|
183
|
+
.string()
|
|
184
|
+
.describe("Name of the text namespace (e.g. my-docs). Must be a text-type namespace."),
|
|
185
|
+
},
|
|
186
|
+
handler: async ({ namespace_name }) => {
|
|
187
|
+
try {
|
|
188
|
+
const data = await makeApiRequest(
|
|
189
|
+
"GET",
|
|
190
|
+
`${API_ENDPOINTS.namespaces}/${namespace_name}/documents/fetch-text-data`
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
const resultText = `Fetched text data from namespace "${namespace_name}":\n${JSON.stringify(data, null, 2)}`;
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
content: [
|
|
197
|
+
{
|
|
198
|
+
type: "text",
|
|
199
|
+
text: resultText,
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
};
|
|
203
|
+
} catch (error) {
|
|
204
|
+
return {
|
|
205
|
+
content: [
|
|
206
|
+
{
|
|
207
|
+
type: "text",
|
|
208
|
+
text: `Error fetching text data: ${error.message}`,
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
// Upload file tool
|
|
217
|
+
export const uploadFileTool = {
|
|
218
|
+
name: "upload-file",
|
|
219
|
+
description: "Upload a file to a text namespace using pre-signed URL flow. The tool requests an upload URL, uploads the file directly to storage, then the file is queued for processing and indexing.",
|
|
220
|
+
parameters: {
|
|
221
|
+
namespace_name: z.string().describe("Name of the text namespace to upload the file to"),
|
|
222
|
+
file_path: z.string().describe("Absolute path to the file to upload. Must be one of: .pdf, .docx, .xlsx, .json, .txt, .csv, .md"),
|
|
223
|
+
},
|
|
224
|
+
handler: async ({ namespace_name, file_path }) => {
|
|
225
|
+
try {
|
|
226
|
+
const data = await uploadFile(namespace_name, file_path);
|
|
227
|
+
|
|
228
|
+
const uploaded_file_name = data.file_name || 'uploaded file';
|
|
229
|
+
const resultText = `Successfully uploaded file "${uploaded_file_name}" to namespace "${namespace_name}":\n${JSON.stringify(data, null, 2)}`;
|
|
230
|
+
|
|
231
|
+
return {
|
|
232
|
+
content: [
|
|
233
|
+
{
|
|
234
|
+
type: "text",
|
|
235
|
+
text: resultText,
|
|
236
|
+
},
|
|
237
|
+
],
|
|
238
|
+
};
|
|
239
|
+
} catch (error) {
|
|
240
|
+
return {
|
|
241
|
+
content: [
|
|
242
|
+
{
|
|
243
|
+
type: "text",
|
|
244
|
+
text: `Error uploading file: ${error.message}`,
|
|
245
|
+
},
|
|
246
|
+
],
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
// List raw file objects in document storage (S3) for a namespace
|
|
253
|
+
export const listFilesTool = {
|
|
254
|
+
name: "list-files",
|
|
255
|
+
description:
|
|
256
|
+
"List file objects stored in document storage (S3) for a namespace: file_name, size (bytes), last_modified. This is raw storage listing (e.g. after upload-url uploads), not indexed text documents. GET only; no body.",
|
|
257
|
+
parameters: {
|
|
258
|
+
namespace_name: z.string().describe("Namespace name. Must exist and belong to your account."),
|
|
259
|
+
},
|
|
260
|
+
handler: async ({ namespace_name }) => {
|
|
261
|
+
try {
|
|
262
|
+
const data = await makeApiRequest(
|
|
263
|
+
"GET",
|
|
264
|
+
`${API_ENDPOINTS.namespaces}/${namespace_name}/list-files`
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
const resultText = `Listed files in namespace "${namespace_name}":\n${JSON.stringify(data, null, 2)}`;
|
|
268
|
+
|
|
269
|
+
return {
|
|
270
|
+
content: [
|
|
271
|
+
{
|
|
272
|
+
type: "text",
|
|
273
|
+
text: resultText,
|
|
274
|
+
},
|
|
275
|
+
],
|
|
276
|
+
};
|
|
277
|
+
} catch (error) {
|
|
278
|
+
return {
|
|
279
|
+
content: [
|
|
280
|
+
{
|
|
281
|
+
type: "text",
|
|
282
|
+
text: `Error listing files: ${error.message}`,
|
|
283
|
+
},
|
|
284
|
+
],
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
// Delete one or more raw files from document storage (S3) for a namespace
|
|
291
|
+
export const deleteFileTool = {
|
|
292
|
+
name: "delete-file",
|
|
293
|
+
description:
|
|
294
|
+
"Permanently delete file(s) from document storage (S3) for a namespace. Use snake_case: file_name (one file) and/or file_names (array). At least one is required. This deletes storage objects, not indexed documents by pipeline ID (use delete-data for documents/vectors by id).",
|
|
295
|
+
parameters: {
|
|
296
|
+
namespace_name: z.string().describe("Namespace that contains the file(s). You must own this namespace."),
|
|
297
|
+
file_name: z
|
|
298
|
+
.string()
|
|
299
|
+
.optional()
|
|
300
|
+
.describe('Single file to delete (e.g. "document.pdf"). Can be combined with file_names.'),
|
|
301
|
+
file_names: z
|
|
302
|
+
.array(z.string())
|
|
303
|
+
.optional()
|
|
304
|
+
.describe('Multiple files to delete, e.g. ["a.pdf", "b.docx"]. Can be combined with file_name.'),
|
|
305
|
+
},
|
|
306
|
+
handler: async ({ namespace_name, file_name, file_names }) => {
|
|
307
|
+
try {
|
|
308
|
+
const hasSingle = typeof file_name === "string" && file_name.trim().length > 0;
|
|
309
|
+
const hasMany = Array.isArray(file_names) && file_names.length > 0;
|
|
310
|
+
|
|
311
|
+
if (!hasSingle && !hasMany) {
|
|
312
|
+
return {
|
|
313
|
+
content: [
|
|
314
|
+
{
|
|
315
|
+
type: "text",
|
|
316
|
+
text: "Error: Provide file_name and/or file_names with at least one file to delete.",
|
|
317
|
+
},
|
|
318
|
+
],
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const body = {};
|
|
323
|
+
if (hasSingle) {
|
|
324
|
+
body.file_name = file_name.trim();
|
|
325
|
+
}
|
|
326
|
+
if (hasMany) {
|
|
327
|
+
body.file_names = file_names;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const data = await makeApiRequest(
|
|
331
|
+
"DELETE",
|
|
332
|
+
`${API_ENDPOINTS.namespaces}/${namespace_name}/delete-file`,
|
|
333
|
+
body
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
const resultText = `Delete file result for namespace "${namespace_name}":\n${JSON.stringify(data, null, 2)}`;
|
|
337
|
+
|
|
338
|
+
return {
|
|
339
|
+
content: [
|
|
340
|
+
{
|
|
341
|
+
type: "text",
|
|
342
|
+
text: resultText,
|
|
343
|
+
},
|
|
344
|
+
],
|
|
345
|
+
};
|
|
346
|
+
} catch (error) {
|
|
347
|
+
return {
|
|
348
|
+
content: [
|
|
349
|
+
{
|
|
350
|
+
type: "text",
|
|
351
|
+
text: `Error deleting file(s): ${error.message}`,
|
|
352
|
+
},
|
|
353
|
+
],
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
},
|
|
210
357
|
};
|