@@ -9,13 +9,18 @@ import {
99} from '@modelcontextprotocol/sdk/types.js' ;
1010
1111import dotenv from 'dotenv' ;
12- import { Configuration , ExtractionApi , FilesApi , PipelinesApi } from '@vectorize-io/vectorize-client' ;
12+ import {
13+ Configuration ,
14+ ExtractionApi ,
15+ FilesApi ,
16+ PipelinesApi ,
17+ } from '@vectorize-io/vectorize-client' ;
1318
1419dotenv . config ( ) ;
1520
1621const RETRIEVAL_TOOL : Tool = {
1722 name : 'retrieve' ,
18- description : 'Retrieve documents from a Vectorize pipeline.' ,
23+ description : 'Retrieve documents from the configured pipeline.' ,
1924 inputSchema : {
2025 type : 'object' ,
2126 properties : {
@@ -26,16 +31,16 @@ const RETRIEVAL_TOOL: Tool = {
2631 k : {
2732 type : 'number' ,
2833 description : 'The number of documents to retrieve.' ,
34+ default : 4 ,
2935 } ,
3036 } ,
31- required : [ 'question' , 'k' ]
37+ required : [ 'question' ] ,
3238 } ,
3339} ;
3440
35-
3641const DEEP_RESEARCH_TOOL : Tool = {
3742 name : 'deep-research' ,
38- description : 'Generate a deep research on a Vectorize pipeline.' ,
43+ description : 'Generate a deep research on the configured pipeline.' ,
3944 inputSchema : {
4045 type : 'object' ,
4146 properties : {
@@ -48,7 +53,7 @@ const DEEP_RESEARCH_TOOL: Tool = {
4853 description : 'Whether to perform a web search.' ,
4954 } ,
5055 } ,
51- required : [ 'query' , 'webSearch' ]
56+ required : [ 'query' , 'webSearch' ] ,
5257 } ,
5358} ;
5459
@@ -66,7 +71,6 @@ const EXTRACTION_TOOL: Tool = {
6671 type : 'string' ,
6772 description : 'Document content type.' ,
6873 } ,
69-
7074 } ,
7175 required : [ 'base64Document' , 'contentType' ] ,
7276 } ,
@@ -125,7 +129,6 @@ async function performRetrieval(
125129 } ;
126130}
127131
128-
129132async function performExtraction (
130133 orgId : string ,
131134 base64Document : string ,
@@ -135,17 +138,17 @@ async function performExtraction(
135138 const startResponse = await filesApi . startFileUpload ( {
136139 organization : orgId ,
137140 startFileUploadRequest : {
138- name : " My File" ,
139- contentType
140- }
141+ name : ' My File' ,
142+ contentType,
143+ } ,
141144 } ) ;
142145
143146 const fileBuffer = Buffer . from ( base64Document , 'base64' ) ;
144147 const fetchResponse = await fetch ( startResponse . uploadUrl , {
145148 method : 'PUT' ,
146149 body : fileBuffer ,
147150 headers : {
148- 'Content-Type' : contentType
151+ 'Content-Type' : contentType ,
149152 } ,
150153 } ) ;
151154 if ( ! fetchResponse . ok ) {
@@ -158,21 +161,21 @@ async function performExtraction(
158161 startExtractionRequest : {
159162 fileId : startResponse . fileId ,
160163 chunkSize : 512 ,
161- }
162- } )
164+ } ,
165+ } ) ;
163166 const extractionId = response . extractionId ;
164167 // eslint-disable-next-line no-constant-condition
165168 while ( true ) {
166169 const result = await extractionApi . getExtractionResult ( {
167170 organization : orgId ,
168171 extractionId : extractionId ,
169- } )
172+ } ) ;
170173 if ( result . ready ) {
171174 if ( result . data ?. success ) {
172175 return {
173176 content : [ { type : 'text' , text : JSON . stringify ( result . data ) } ] ,
174177 isError : false ,
175- }
178+ } ;
176179 } else {
177180 throw new Error ( `Extraction failed: ${ result . data ?. error } ` ) ;
178181 }
@@ -182,8 +185,6 @@ async function performExtraction(
182185 }
183186}
184187
185-
186-
187188async function performDeepResearch (
188189 orgId : string ,
189190 pipelineId : string ,
@@ -196,34 +197,33 @@ async function performDeepResearch(
196197 pipeline : pipelineId ,
197198 startDeepResearchRequest : {
198199 query,
199- webSearch
200- }
200+ webSearch,
201+ } ,
201202 } ) ;
202203 const researchId = response . researchId ;
203204 // eslint-disable-next-line no-constant-condition
204205 while ( true ) {
205206 const result = await pipelinesApi . getDeepResearchResult ( {
206207 organization : orgId ,
207208 pipeline : pipelineId ,
208- researchId : researchId
209- } )
209+ researchId : researchId ,
210+ } ) ;
210211 if ( result . ready ) {
211212 if ( result . data ?. success ) {
212213 return {
213214 content : [ { type : 'text' , text : result . data . markdown } ] ,
214215 isError : false ,
215- }
216+ } ;
216217 } else {
217218 throw new Error ( `Deep research failed: ${ result . data ?. error } ` ) ;
218219 }
219- break
220+ break ;
220221 } else {
221222 await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
222223 }
223224 }
224225}
225226
226-
227227server . setRequestHandler ( CallToolRequestSchema , async ( request ) => {
228228 try {
229229 const { name, arguments : args } = request . params ;
@@ -279,7 +279,9 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
279279 } ,
280280 } ) ;
281281 return {
282- content : [ { type : 'text' , text : JSON . stringify ( { error : errorMessage } ) } ] ,
282+ content : [
283+ { type : 'text' , text : JSON . stringify ( { error : errorMessage } ) } ,
284+ ] ,
283285 isError : true ,
284286 } ;
285287 }
@@ -300,8 +302,6 @@ async function runServer() {
300302 level : 'info' ,
301303 data : `Configuration: Organization ID: ${ VECTORIZE_ORG_ID } with Pipeline ID: ${ VECTORIZE_PIPELINE_ID } ` ,
302304 } ) ;
303-
304- console . info ( 'Vectorize MCP Server running' ) ;
305305}
306306
307307runServer ( ) . catch ( ( error ) => {
0 commit comments