@node2flow/gemini-file-search-rag-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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAMnE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAIrD;;GAEG;AACH,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,CAuDvG;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,CAAC,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CA8DhE"}
package/dist/server.js ADDED
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Shared MCP Server creation logic
3
+ * Used by both Node.js entry (index.ts) and CF Worker entry (worker.ts)
4
+ */
5
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
6
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
7
+ import { GeminiRagClient } from './gemini-client.js';
8
+ import { TOOLS } from './tools.js';
9
+ /**
10
+ * Handle MCP tool calls by routing to GeminiRagClient methods
11
+ */
12
+ export async function handleToolCall(toolName, args, client) {
13
+ switch (toolName) {
14
+ // Store Operations
15
+ case 'gemini_create_store':
16
+ return client.createStore(args.display_name);
17
+ case 'gemini_list_stores':
18
+ return client.listStores(args.page_size, args.page_token);
19
+ case 'gemini_get_store':
20
+ return client.getStore(args.store_name);
21
+ case 'gemini_delete_store':
22
+ return client.deleteStore(args.store_name, args.force);
23
+ // Upload & Import
24
+ case 'gemini_upload_to_store':
25
+ return client.uploadToStore(args.store_name, {
26
+ mimeType: args.mime_type,
27
+ content: args.content,
28
+ displayName: args.display_name,
29
+ contentEncoding: args.content_encoding || 'text',
30
+ customMetadata: args.custom_metadata,
31
+ chunkingConfig: args.chunking_config,
32
+ });
33
+ case 'gemini_import_file_to_store':
34
+ return client.importFileToStore(args.store_name, {
35
+ fileName: args.file_name,
36
+ customMetadata: args.custom_metadata,
37
+ chunkingConfig: args.chunking_config,
38
+ });
39
+ // Operations
40
+ case 'gemini_get_operation':
41
+ return client.getOperation(args.operation_name);
42
+ case 'gemini_get_upload_operation':
43
+ return client.getUploadOperation(args.operation_name);
44
+ // Document Operations
45
+ case 'gemini_list_documents':
46
+ return client.listDocuments(args.store_name, args.page_size, args.page_token);
47
+ case 'gemini_get_document':
48
+ return client.getDocument(args.document_name);
49
+ case 'gemini_delete_document':
50
+ return client.deleteDocument(args.document_name, args.force);
51
+ // RAG Query
52
+ case 'gemini_rag_query':
53
+ return client.ragQuery({
54
+ query: args.query,
55
+ storeNames: args.store_names,
56
+ model: args.model,
57
+ metadataFilter: args.metadata_filter,
58
+ });
59
+ default:
60
+ throw new Error(`Unknown tool: ${toolName}`);
61
+ }
62
+ }
63
+ /**
64
+ * Create a configured MCP Server instance
65
+ * Config is optional — tools/list works without config, tool calls require it
66
+ */
67
+ export function createServer(config) {
68
+ const server = new Server({
69
+ name: 'gemini-rag-mcp',
70
+ version: '1.0.0',
71
+ }, {
72
+ capabilities: {
73
+ tools: {},
74
+ },
75
+ });
76
+ let client = null;
77
+ function getClient() {
78
+ if (!client) {
79
+ if (!config) {
80
+ throw new Error('Missing required configuration: GEMINI_API_KEY. ' +
81
+ 'Set it before using any tools.');
82
+ }
83
+ client = new GeminiRagClient(config);
84
+ }
85
+ return client;
86
+ }
87
+ // List available tools
88
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
89
+ return { tools: TOOLS };
90
+ });
91
+ // Handle tool calls
92
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
93
+ const { name, arguments: args } = request.params;
94
+ try {
95
+ const result = await handleToolCall(name, args || {}, getClient());
96
+ return {
97
+ content: [
98
+ {
99
+ type: 'text',
100
+ text: JSON.stringify(result, null, 2),
101
+ },
102
+ ],
103
+ };
104
+ }
105
+ catch (error) {
106
+ return {
107
+ content: [
108
+ {
109
+ type: 'text',
110
+ text: `Error: ${error.message}`,
111
+ },
112
+ ],
113
+ isError: true,
114
+ };
115
+ }
116
+ });
117
+ return server;
118
+ }
119
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGnC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,QAAgB,EAAE,IAAS,EAAE,MAAuB;IACvF,QAAQ,QAAQ,EAAE,CAAC;QACjB,mBAAmB;QACnB,KAAK,qBAAqB;YACxB,OAAO,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC/C,KAAK,oBAAoB;YACvB,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAC5D,KAAK,kBAAkB;YACrB,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC1C,KAAK,qBAAqB;YACxB,OAAO,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAEzD,kBAAkB;QAClB,KAAK,wBAAwB;YAC3B,OAAO,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,EAAE;gBAC3C,QAAQ,EAAE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AC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,UAAU,KAAK,CAAC,OAAO,EAAE;qBAChC;iBACF;gBACD,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,392 @@
1
+ /**
2
+ * Gemini RAG File Search - MCP Tool Definitions (12 tools)
3
+ */
4
+ export declare const TOOLS: ({
5
+ name: string;
6
+ description: string;
7
+ inputSchema: {
8
+ type: string;
9
+ properties: {
10
+ display_name: {
11
+ type: string;
12
+ description: string;
13
+ };
14
+ page_size?: undefined;
15
+ page_token?: undefined;
16
+ store_name?: undefined;
17
+ force?: undefined;
18
+ mime_type?: undefined;
19
+ content?: undefined;
20
+ content_encoding?: undefined;
21
+ custom_metadata?: undefined;
22
+ file_name?: undefined;
23
+ operation_name?: undefined;
24
+ document_name?: undefined;
25
+ query?: undefined;
26
+ store_names?: undefined;
27
+ model?: undefined;
28
+ metadata_filter?: undefined;
29
+ };
30
+ required: string[];
31
+ };
32
+ } | {
33
+ name: string;
34
+ description: string;
35
+ inputSchema: {
36
+ type: string;
37
+ properties: {
38
+ page_size: {
39
+ type: string;
40
+ description: string;
41
+ };
42
+ page_token: {
43
+ type: string;
44
+ description: string;
45
+ };
46
+ display_name?: undefined;
47
+ store_name?: undefined;
48
+ force?: undefined;
49
+ mime_type?: undefined;
50
+ content?: undefined;
51
+ content_encoding?: undefined;
52
+ custom_metadata?: undefined;
53
+ file_name?: undefined;
54
+ operation_name?: undefined;
55
+ document_name?: undefined;
56
+ query?: undefined;
57
+ store_names?: undefined;
58
+ model?: undefined;
59
+ metadata_filter?: undefined;
60
+ };
61
+ required?: undefined;
62
+ };
63
+ } | {
64
+ name: string;
65
+ description: string;
66
+ inputSchema: {
67
+ type: string;
68
+ properties: {
69
+ store_name: {
70
+ type: string;
71
+ description: string;
72
+ };
73
+ display_name?: undefined;
74
+ page_size?: undefined;
75
+ page_token?: undefined;
76
+ force?: undefined;
77
+ mime_type?: undefined;
78
+ content?: undefined;
79
+ content_encoding?: undefined;
80
+ custom_metadata?: undefined;
81
+ file_name?: undefined;
82
+ operation_name?: undefined;
83
+ document_name?: undefined;
84
+ query?: undefined;
85
+ store_names?: undefined;
86
+ model?: undefined;
87
+ metadata_filter?: undefined;
88
+ };
89
+ required: string[];
90
+ };
91
+ } | {
92
+ name: string;
93
+ description: string;
94
+ inputSchema: {
95
+ type: string;
96
+ properties: {
97
+ store_name: {
98
+ type: string;
99
+ description: string;
100
+ };
101
+ force: {
102
+ type: string;
103
+ description: string;
104
+ };
105
+ display_name?: undefined;
106
+ page_size?: undefined;
107
+ page_token?: undefined;
108
+ mime_type?: undefined;
109
+ content?: undefined;
110
+ content_encoding?: undefined;
111
+ custom_metadata?: undefined;
112
+ file_name?: undefined;
113
+ operation_name?: undefined;
114
+ document_name?: undefined;
115
+ query?: undefined;
116
+ store_names?: undefined;
117
+ model?: undefined;
118
+ metadata_filter?: undefined;
119
+ };
120
+ required: string[];
121
+ };
122
+ } | {
123
+ name: string;
124
+ description: string;
125
+ inputSchema: {
126
+ type: string;
127
+ properties: {
128
+ store_name: {
129
+ type: string;
130
+ description: string;
131
+ };
132
+ mime_type: {
133
+ type: string;
134
+ description: string;
135
+ };
136
+ content: {
137
+ type: string;
138
+ description: string;
139
+ };
140
+ display_name: {
141
+ type: string;
142
+ description: string;
143
+ };
144
+ content_encoding: {
145
+ type: string;
146
+ enum: string[];
147
+ description: string;
148
+ };
149
+ custom_metadata: {
150
+ type: string;
151
+ items: {
152
+ type: string;
153
+ properties: {
154
+ key: {
155
+ type: string;
156
+ };
157
+ stringValue: {
158
+ type: string;
159
+ };
160
+ numericValue: {
161
+ type: string;
162
+ };
163
+ };
164
+ required: string[];
165
+ };
166
+ description: string;
167
+ };
168
+ page_size?: undefined;
169
+ page_token?: undefined;
170
+ force?: undefined;
171
+ file_name?: undefined;
172
+ operation_name?: undefined;
173
+ document_name?: undefined;
174
+ query?: undefined;
175
+ store_names?: undefined;
176
+ model?: undefined;
177
+ metadata_filter?: undefined;
178
+ };
179
+ required: string[];
180
+ };
181
+ } | {
182
+ name: string;
183
+ description: string;
184
+ inputSchema: {
185
+ type: string;
186
+ properties: {
187
+ store_name: {
188
+ type: string;
189
+ description: string;
190
+ };
191
+ file_name: {
192
+ type: string;
193
+ description: string;
194
+ };
195
+ custom_metadata: {
196
+ type: string;
197
+ items: {
198
+ type: string;
199
+ properties: {
200
+ key: {
201
+ type: string;
202
+ };
203
+ stringValue: {
204
+ type: string;
205
+ };
206
+ numericValue: {
207
+ type: string;
208
+ };
209
+ };
210
+ required: string[];
211
+ };
212
+ description: string;
213
+ };
214
+ display_name?: undefined;
215
+ page_size?: undefined;
216
+ page_token?: undefined;
217
+ force?: undefined;
218
+ mime_type?: undefined;
219
+ content?: undefined;
220
+ content_encoding?: undefined;
221
+ operation_name?: undefined;
222
+ document_name?: undefined;
223
+ query?: undefined;
224
+ store_names?: undefined;
225
+ model?: undefined;
226
+ metadata_filter?: undefined;
227
+ };
228
+ required: string[];
229
+ };
230
+ } | {
231
+ name: string;
232
+ description: string;
233
+ inputSchema: {
234
+ type: string;
235
+ properties: {
236
+ operation_name: {
237
+ type: string;
238
+ description: string;
239
+ };
240
+ display_name?: undefined;
241
+ page_size?: undefined;
242
+ page_token?: undefined;
243
+ store_name?: undefined;
244
+ force?: undefined;
245
+ mime_type?: undefined;
246
+ content?: undefined;
247
+ content_encoding?: undefined;
248
+ custom_metadata?: undefined;
249
+ file_name?: undefined;
250
+ document_name?: undefined;
251
+ query?: undefined;
252
+ store_names?: undefined;
253
+ model?: undefined;
254
+ metadata_filter?: undefined;
255
+ };
256
+ required: string[];
257
+ };
258
+ } | {
259
+ name: string;
260
+ description: string;
261
+ inputSchema: {
262
+ type: string;
263
+ properties: {
264
+ store_name: {
265
+ type: string;
266
+ description: string;
267
+ };
268
+ page_size: {
269
+ type: string;
270
+ description: string;
271
+ };
272
+ page_token: {
273
+ type: string;
274
+ description: string;
275
+ };
276
+ display_name?: undefined;
277
+ force?: undefined;
278
+ mime_type?: undefined;
279
+ content?: undefined;
280
+ content_encoding?: undefined;
281
+ custom_metadata?: undefined;
282
+ file_name?: undefined;
283
+ operation_name?: undefined;
284
+ document_name?: undefined;
285
+ query?: undefined;
286
+ store_names?: undefined;
287
+ model?: undefined;
288
+ metadata_filter?: undefined;
289
+ };
290
+ required: string[];
291
+ };
292
+ } | {
293
+ name: string;
294
+ description: string;
295
+ inputSchema: {
296
+ type: string;
297
+ properties: {
298
+ document_name: {
299
+ type: string;
300
+ description: string;
301
+ };
302
+ display_name?: undefined;
303
+ page_size?: undefined;
304
+ page_token?: undefined;
305
+ store_name?: undefined;
306
+ force?: undefined;
307
+ mime_type?: undefined;
308
+ content?: undefined;
309
+ content_encoding?: undefined;
310
+ custom_metadata?: undefined;
311
+ file_name?: undefined;
312
+ operation_name?: undefined;
313
+ query?: undefined;
314
+ store_names?: undefined;
315
+ model?: undefined;
316
+ metadata_filter?: undefined;
317
+ };
318
+ required: string[];
319
+ };
320
+ } | {
321
+ name: string;
322
+ description: string;
323
+ inputSchema: {
324
+ type: string;
325
+ properties: {
326
+ document_name: {
327
+ type: string;
328
+ description: string;
329
+ };
330
+ force: {
331
+ type: string;
332
+ description: string;
333
+ };
334
+ display_name?: undefined;
335
+ page_size?: undefined;
336
+ page_token?: undefined;
337
+ store_name?: undefined;
338
+ mime_type?: undefined;
339
+ content?: undefined;
340
+ content_encoding?: undefined;
341
+ custom_metadata?: undefined;
342
+ file_name?: undefined;
343
+ operation_name?: undefined;
344
+ query?: undefined;
345
+ store_names?: undefined;
346
+ model?: undefined;
347
+ metadata_filter?: undefined;
348
+ };
349
+ required: string[];
350
+ };
351
+ } | {
352
+ name: string;
353
+ description: string;
354
+ inputSchema: {
355
+ type: string;
356
+ properties: {
357
+ query: {
358
+ type: string;
359
+ description: string;
360
+ };
361
+ store_names: {
362
+ type: string;
363
+ items: {
364
+ type: string;
365
+ };
366
+ description: string;
367
+ };
368
+ model: {
369
+ type: string;
370
+ description: string;
371
+ };
372
+ metadata_filter: {
373
+ type: string;
374
+ description: string;
375
+ };
376
+ display_name?: undefined;
377
+ page_size?: undefined;
378
+ page_token?: undefined;
379
+ store_name?: undefined;
380
+ force?: undefined;
381
+ mime_type?: undefined;
382
+ content?: undefined;
383
+ content_encoding?: undefined;
384
+ custom_metadata?: undefined;
385
+ file_name?: undefined;
386
+ operation_name?: undefined;
387
+ document_name?: undefined;
388
+ };
389
+ required: string[];
390
+ };
391
+ })[];
392
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA6QjB,CAAC"}