api2ai 1.0.3 → 1.0.6

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.
@@ -2,17 +2,15 @@
2
2
 
3
3
  /**
4
4
  * petstore-api - MCP Server
5
- *
6
- * Auto-generated from OpenAPI specification using mcp-use framework.
7
- *
5
+ *
8
6
  * Features:
9
7
  * - 19 API tools available
10
8
  * - Built-in Inspector at http://localhost:3000/inspector
11
- * - Streamable HTTP transport
12
9
  */
13
10
 
14
11
  import 'dotenv/config';
15
12
  import { MCPServer } from 'mcp-use/server';
13
+ import { text, object } from 'mcp-use/server';
16
14
  import { z } from 'zod';
17
15
  import { executeRequest } from './http-client.js';
18
16
  import { toolConfigMap } from './tools-config.js';
@@ -52,7 +50,7 @@ const server = new MCPServer({
52
50
  version: '1.0.0',
53
51
  description: 'MCP server generated from OpenAPI specification',
54
52
  baseUrl: process.env.MCP_URL || `http://localhost:${PORT}`,
55
- allowedOrigins: isDev
53
+ allowedOrigins: isDev
56
54
  ? undefined // Development: allow all origins
57
55
  : process.env.ALLOWED_ORIGINS?.split(',').map(s => s.trim()) || [],
58
56
  });
@@ -62,406 +60,577 @@ const server = new MCPServer({
62
60
  // ============================================================================
63
61
 
64
62
  // Add a new pet to the store.
65
- server.tool('addPet', {
66
- description: 'Add a new pet to the store.',
67
- parameters: z.object({
63
+ server.tool(
64
+ {
65
+ name: 'addPet',
66
+ description: 'Add a new pet to the store.',
67
+ schema: z.object({
68
68
  requestBody: z.unknown().describe('Create a new pet in the store')
69
69
  }),
70
- execute: async (params) => {
70
+ },
71
+ async (params) => {
71
72
  const toolConfig = toolConfigMap.get('addPet');
72
73
  const result = await executeRequest(toolConfig, params, apiConfig);
73
74
 
74
- if (result.ok) {
75
- return typeof result.data === 'string'
76
- ? result.data
77
- : JSON.stringify(result.data, null, 2);
75
+ if (!result.ok) {
76
+ return text(`Error: ${result.status} ${result.statusText}\n${
77
+ typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2)
78
+ }`);
79
+ }
80
+
81
+ // Return MCP content based on response type
82
+ if (typeof result.data === 'string') {
83
+ return text(result.data);
84
+ } else if (typeof result.data === 'object' && result.data !== null) {
85
+ return object(result.data);
78
86
  } else {
79
- throw new Error(`API Error (${result.status}): ${typeof result.data === 'string' ? result.data : JSON.stringify(result.data)
80
- }`);
87
+ return text(String(result.data));
81
88
  }
82
- },
83
- });
89
+ }
90
+ );
84
91
 
85
92
  // Update an existing pet.
86
- server.tool('updatePet', {
87
- description: 'Update an existing pet.',
88
- parameters: z.object({
93
+ server.tool(
94
+ {
95
+ name: 'updatePet',
96
+ description: 'Update an existing pet.',
97
+ schema: z.object({
89
98
  requestBody: z.unknown().describe('Update an existent pet in the store')
90
99
  }),
91
- execute: async (params) => {
100
+ },
101
+ async (params) => {
92
102
  const toolConfig = toolConfigMap.get('updatePet');
93
103
  const result = await executeRequest(toolConfig, params, apiConfig);
94
104
 
95
- if (result.ok) {
96
- return typeof result.data === 'string'
97
- ? result.data
98
- : JSON.stringify(result.data, null, 2);
105
+ if (!result.ok) {
106
+ return text(`Error: ${result.status} ${result.statusText}\n${
107
+ typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2)
108
+ }`);
109
+ }
110
+
111
+ // Return MCP content based on response type
112
+ if (typeof result.data === 'string') {
113
+ return text(result.data);
114
+ } else if (typeof result.data === 'object' && result.data !== null) {
115
+ return object(result.data);
99
116
  } else {
100
- throw new Error(`API Error (${result.status}): ${typeof result.data === 'string' ? result.data : JSON.stringify(result.data)
101
- }`);
117
+ return text(String(result.data));
102
118
  }
103
- },
104
- });
119
+ }
120
+ );
105
121
 
106
122
  // Finds Pets by status.
107
- server.tool('findPetsByStatus', {
108
- description: 'Finds Pets by status.',
109
- parameters: z.object({
123
+ server.tool(
124
+ {
125
+ name: 'findPetsByStatus',
126
+ description: 'Finds Pets by status.',
127
+ schema: z.object({
110
128
  status: z.enum(['available', 'pending', 'sold']).describe('Status values that need to be considered for filter')
111
129
  }),
112
- execute: async (params) => {
130
+ },
131
+ async (params) => {
113
132
  const toolConfig = toolConfigMap.get('findPetsByStatus');
114
133
  const result = await executeRequest(toolConfig, params, apiConfig);
115
134
 
116
- if (result.ok) {
117
- return typeof result.data === 'string'
118
- ? result.data
119
- : JSON.stringify(result.data, null, 2);
135
+ if (!result.ok) {
136
+ return text(`Error: ${result.status} ${result.statusText}\n${
137
+ typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2)
138
+ }`);
139
+ }
140
+
141
+ // Return MCP content based on response type
142
+ if (typeof result.data === 'string') {
143
+ return text(result.data);
144
+ } else if (typeof result.data === 'object' && result.data !== null) {
145
+ return object(result.data);
120
146
  } else {
121
- throw new Error(`API Error (${result.status}): ${typeof result.data === 'string' ? result.data : JSON.stringify(result.data)
122
- }`);
147
+ return text(String(result.data));
123
148
  }
124
- },
125
- });
149
+ }
150
+ );
126
151
 
127
152
  // Finds Pets by tags.
128
- server.tool('findPetsByTags', {
129
- description: 'Finds Pets by tags.',
130
- parameters: z.object({
153
+ server.tool(
154
+ {
155
+ name: 'findPetsByTags',
156
+ description: 'Finds Pets by tags.',
157
+ schema: z.object({
131
158
  tags: z.array(z.string()).describe('Tags to filter by')
132
159
  }),
133
- execute: async (params) => {
160
+ },
161
+ async (params) => {
134
162
  const toolConfig = toolConfigMap.get('findPetsByTags');
135
163
  const result = await executeRequest(toolConfig, params, apiConfig);
136
164
 
137
- if (result.ok) {
138
- return typeof result.data === 'string'
139
- ? result.data
140
- : JSON.stringify(result.data, null, 2);
165
+ if (!result.ok) {
166
+ return text(`Error: ${result.status} ${result.statusText}\n${
167
+ typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2)
168
+ }`);
169
+ }
170
+
171
+ // Return MCP content based on response type
172
+ if (typeof result.data === 'string') {
173
+ return text(result.data);
174
+ } else if (typeof result.data === 'object' && result.data !== null) {
175
+ return object(result.data);
141
176
  } else {
142
- throw new Error(`API Error (${result.status}): ${typeof result.data === 'string' ? result.data : JSON.stringify(result.data)
143
- }`);
177
+ return text(String(result.data));
144
178
  }
145
- },
146
- });
179
+ }
180
+ );
147
181
 
148
182
  // Find pet by ID.
149
- server.tool('getPetById', {
150
- description: 'Find pet by ID.',
151
- parameters: z.object({
183
+ server.tool(
184
+ {
185
+ name: 'getPetById',
186
+ description: 'Find pet by ID.',
187
+ schema: z.object({
152
188
  petId: z.number().int().describe('ID of pet to return')
153
189
  }),
154
- execute: async (params) => {
190
+ },
191
+ async (params) => {
155
192
  const toolConfig = toolConfigMap.get('getPetById');
156
193
  const result = await executeRequest(toolConfig, params, apiConfig);
157
194
 
158
- if (result.ok) {
159
- return typeof result.data === 'string'
160
- ? result.data
161
- : JSON.stringify(result.data, null, 2);
195
+ if (!result.ok) {
196
+ return text(`Error: ${result.status} ${result.statusText}\n${
197
+ typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2)
198
+ }`);
199
+ }
200
+
201
+ // Return MCP content based on response type
202
+ if (typeof result.data === 'string') {
203
+ return text(result.data);
204
+ } else if (typeof result.data === 'object' && result.data !== null) {
205
+ return object(result.data);
162
206
  } else {
163
- throw new Error(`API Error (${result.status}): ${typeof result.data === 'string' ? result.data : JSON.stringify(result.data)
164
- }`);
207
+ return text(String(result.data));
165
208
  }
166
- },
167
- });
209
+ }
210
+ );
168
211
 
169
212
  // Updates a pet in the store with form data.
170
- server.tool('updatePetWithForm', {
171
- description: 'Updates a pet in the store with form data.',
172
- parameters: z.object({
213
+ server.tool(
214
+ {
215
+ name: 'updatePetWithForm',
216
+ description: 'Updates a pet in the store with form data.',
217
+ schema: z.object({
173
218
  petId: z.number().int().describe('ID of pet that needs to be updated'),
174
219
  name: z.string().optional().describe('Name of pet that needs to be updated'),
175
220
  status: z.string().optional().describe('Status of pet that needs to be updated')
176
221
  }),
177
- execute: async (params) => {
222
+ },
223
+ async (params) => {
178
224
  const toolConfig = toolConfigMap.get('updatePetWithForm');
179
225
  const result = await executeRequest(toolConfig, params, apiConfig);
180
226
 
181
- if (result.ok) {
182
- return typeof result.data === 'string'
183
- ? result.data
184
- : JSON.stringify(result.data, null, 2);
227
+ if (!result.ok) {
228
+ return text(`Error: ${result.status} ${result.statusText}\n${
229
+ typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2)
230
+ }`);
231
+ }
232
+
233
+ // Return MCP content based on response type
234
+ if (typeof result.data === 'string') {
235
+ return text(result.data);
236
+ } else if (typeof result.data === 'object' && result.data !== null) {
237
+ return object(result.data);
185
238
  } else {
186
- throw new Error(`API Error (${result.status}): ${typeof result.data === 'string' ? result.data : JSON.stringify(result.data)
187
- }`);
239
+ return text(String(result.data));
188
240
  }
189
- },
190
- });
241
+ }
242
+ );
191
243
 
192
244
  // Deletes a pet.
193
- server.tool('deletePet', {
194
- description: 'Deletes a pet.',
195
- parameters: z.object({
245
+ server.tool(
246
+ {
247
+ name: 'deletePet',
248
+ description: 'Deletes a pet.',
249
+ schema: z.object({
196
250
  api_key: z.string().optional(),
197
251
  petId: z.number().int().describe('Pet id to delete')
198
252
  }),
199
- execute: async (params) => {
253
+ },
254
+ async (params) => {
200
255
  const toolConfig = toolConfigMap.get('deletePet');
201
256
  const result = await executeRequest(toolConfig, params, apiConfig);
202
257
 
203
- if (result.ok) {
204
- return typeof result.data === 'string'
205
- ? result.data
206
- : JSON.stringify(result.data, null, 2);
258
+ if (!result.ok) {
259
+ return text(`Error: ${result.status} ${result.statusText}\n${
260
+ typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2)
261
+ }`);
262
+ }
263
+
264
+ // Return MCP content based on response type
265
+ if (typeof result.data === 'string') {
266
+ return text(result.data);
267
+ } else if (typeof result.data === 'object' && result.data !== null) {
268
+ return object(result.data);
207
269
  } else {
208
- throw new Error(`API Error (${result.status}): ${typeof result.data === 'string' ? result.data : JSON.stringify(result.data)
209
- }`);
270
+ return text(String(result.data));
210
271
  }
211
- },
212
- });
272
+ }
273
+ );
213
274
 
214
275
  // Uploads an image.
215
- server.tool('uploadFile', {
216
- description: 'Uploads an image.',
217
- parameters: z.object({
276
+ server.tool(
277
+ {
278
+ name: 'uploadFile',
279
+ description: 'Uploads an image.',
280
+ schema: z.object({
218
281
  petId: z.number().int().describe('ID of pet to update'),
219
282
  additionalMetadata: z.string().optional().describe('Additional Metadata'),
220
283
  requestBody: z.string().optional().describe('Request body')
221
284
  }),
222
- execute: async (params) => {
285
+ },
286
+ async (params) => {
223
287
  const toolConfig = toolConfigMap.get('uploadFile');
224
288
  const result = await executeRequest(toolConfig, params, apiConfig);
225
289
 
226
- if (result.ok) {
227
- return typeof result.data === 'string'
228
- ? result.data
229
- : JSON.stringify(result.data, null, 2);
290
+ if (!result.ok) {
291
+ return text(`Error: ${result.status} ${result.statusText}\n${
292
+ typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2)
293
+ }`);
294
+ }
295
+
296
+ // Return MCP content based on response type
297
+ if (typeof result.data === 'string') {
298
+ return text(result.data);
299
+ } else if (typeof result.data === 'object' && result.data !== null) {
300
+ return object(result.data);
230
301
  } else {
231
- throw new Error(`API Error (${result.status}): ${typeof result.data === 'string' ? result.data : JSON.stringify(result.data)
232
- }`);
302
+ return text(String(result.data));
233
303
  }
234
- },
235
- });
304
+ }
305
+ );
236
306
 
237
307
  // Returns pet inventories by status.
238
- server.tool('getInventory', {
239
- description: 'Returns pet inventories by status.',
240
- parameters: z.object({}),
241
- execute: async (params) => {
308
+ server.tool(
309
+ {
310
+ name: 'getInventory',
311
+ description: 'Returns pet inventories by status.',
312
+ schema: z.object({}),
313
+ },
314
+ async (params) => {
242
315
  const toolConfig = toolConfigMap.get('getInventory');
243
316
  const result = await executeRequest(toolConfig, params, apiConfig);
244
317
 
245
- if (result.ok) {
246
- return typeof result.data === 'string'
247
- ? result.data
248
- : JSON.stringify(result.data, null, 2);
318
+ if (!result.ok) {
319
+ return text(`Error: ${result.status} ${result.statusText}\n${
320
+ typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2)
321
+ }`);
322
+ }
323
+
324
+ // Return MCP content based on response type
325
+ if (typeof result.data === 'string') {
326
+ return text(result.data);
327
+ } else if (typeof result.data === 'object' && result.data !== null) {
328
+ return object(result.data);
249
329
  } else {
250
- throw new Error(`API Error (${result.status}): ${typeof result.data === 'string' ? result.data : JSON.stringify(result.data)
251
- }`);
330
+ return text(String(result.data));
252
331
  }
253
- },
254
- });
332
+ }
333
+ );
255
334
 
256
335
  // Place an order for a pet.
257
- server.tool('placeOrder', {
258
- description: 'Place an order for a pet.',
259
- parameters: z.object({
336
+ server.tool(
337
+ {
338
+ name: 'placeOrder',
339
+ description: 'Place an order for a pet.',
340
+ schema: z.object({
260
341
  requestBody: z.unknown().optional().describe('Request body')
261
342
  }),
262
- execute: async (params) => {
343
+ },
344
+ async (params) => {
263
345
  const toolConfig = toolConfigMap.get('placeOrder');
264
346
  const result = await executeRequest(toolConfig, params, apiConfig);
265
347
 
266
- if (result.ok) {
267
- return typeof result.data === 'string'
268
- ? result.data
269
- : JSON.stringify(result.data, null, 2);
348
+ if (!result.ok) {
349
+ return text(`Error: ${result.status} ${result.statusText}\n${
350
+ typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2)
351
+ }`);
352
+ }
353
+
354
+ // Return MCP content based on response type
355
+ if (typeof result.data === 'string') {
356
+ return text(result.data);
357
+ } else if (typeof result.data === 'object' && result.data !== null) {
358
+ return object(result.data);
270
359
  } else {
271
- throw new Error(`API Error (${result.status}): ${typeof result.data === 'string' ? result.data : JSON.stringify(result.data)
272
- }`);
360
+ return text(String(result.data));
273
361
  }
274
- },
275
- });
362
+ }
363
+ );
276
364
 
277
365
  // Find purchase order by ID.
278
- server.tool('getOrderById', {
279
- description: 'Find purchase order by ID.',
280
- parameters: z.object({
366
+ server.tool(
367
+ {
368
+ name: 'getOrderById',
369
+ description: 'Find purchase order by ID.',
370
+ schema: z.object({
281
371
  orderId: z.number().int().describe('ID of order that needs to be fetched')
282
372
  }),
283
- execute: async (params) => {
373
+ },
374
+ async (params) => {
284
375
  const toolConfig = toolConfigMap.get('getOrderById');
285
376
  const result = await executeRequest(toolConfig, params, apiConfig);
286
377
 
287
- if (result.ok) {
288
- return typeof result.data === 'string'
289
- ? result.data
290
- : JSON.stringify(result.data, null, 2);
378
+ if (!result.ok) {
379
+ return text(`Error: ${result.status} ${result.statusText}\n${
380
+ typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2)
381
+ }`);
382
+ }
383
+
384
+ // Return MCP content based on response type
385
+ if (typeof result.data === 'string') {
386
+ return text(result.data);
387
+ } else if (typeof result.data === 'object' && result.data !== null) {
388
+ return object(result.data);
291
389
  } else {
292
- throw new Error(`API Error (${result.status}): ${typeof result.data === 'string' ? result.data : JSON.stringify(result.data)
293
- }`);
390
+ return text(String(result.data));
294
391
  }
295
- },
296
- });
392
+ }
393
+ );
297
394
 
298
395
  // Delete purchase order by identifier.
299
- server.tool('deleteOrder', {
300
- description: 'Delete purchase order by identifier.',
301
- parameters: z.object({
396
+ server.tool(
397
+ {
398
+ name: 'deleteOrder',
399
+ description: 'Delete purchase order by identifier.',
400
+ schema: z.object({
302
401
  orderId: z.number().int().describe('ID of the order that needs to be deleted')
303
402
  }),
304
- execute: async (params) => {
403
+ },
404
+ async (params) => {
305
405
  const toolConfig = toolConfigMap.get('deleteOrder');
306
406
  const result = await executeRequest(toolConfig, params, apiConfig);
307
407
 
308
- if (result.ok) {
309
- return typeof result.data === 'string'
310
- ? result.data
311
- : JSON.stringify(result.data, null, 2);
408
+ if (!result.ok) {
409
+ return text(`Error: ${result.status} ${result.statusText}\n${
410
+ typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2)
411
+ }`);
412
+ }
413
+
414
+ // Return MCP content based on response type
415
+ if (typeof result.data === 'string') {
416
+ return text(result.data);
417
+ } else if (typeof result.data === 'object' && result.data !== null) {
418
+ return object(result.data);
312
419
  } else {
313
- throw new Error(`API Error (${result.status}): ${typeof result.data === 'string' ? result.data : JSON.stringify(result.data)
314
- }`);
420
+ return text(String(result.data));
315
421
  }
316
- },
317
- });
422
+ }
423
+ );
318
424
 
319
425
  // Create user.
320
- server.tool('createUser', {
321
- description: 'Create user.',
322
- parameters: z.object({
426
+ server.tool(
427
+ {
428
+ name: 'createUser',
429
+ description: 'Create user.',
430
+ schema: z.object({
323
431
  requestBody: z.unknown().optional().describe('Created user object')
324
432
  }),
325
- execute: async (params) => {
433
+ },
434
+ async (params) => {
326
435
  const toolConfig = toolConfigMap.get('createUser');
327
436
  const result = await executeRequest(toolConfig, params, apiConfig);
328
437
 
329
- if (result.ok) {
330
- return typeof result.data === 'string'
331
- ? result.data
332
- : JSON.stringify(result.data, null, 2);
438
+ if (!result.ok) {
439
+ return text(`Error: ${result.status} ${result.statusText}\n${
440
+ typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2)
441
+ }`);
442
+ }
443
+
444
+ // Return MCP content based on response type
445
+ if (typeof result.data === 'string') {
446
+ return text(result.data);
447
+ } else if (typeof result.data === 'object' && result.data !== null) {
448
+ return object(result.data);
333
449
  } else {
334
- throw new Error(`API Error (${result.status}): ${typeof result.data === 'string' ? result.data : JSON.stringify(result.data)
335
- }`);
450
+ return text(String(result.data));
336
451
  }
337
- },
338
- });
452
+ }
453
+ );
339
454
 
340
455
  // Creates list of users with given input array.
341
- server.tool('createUsersWithListInput', {
342
- description: 'Creates list of users with given input array.',
343
- parameters: z.object({
456
+ server.tool(
457
+ {
458
+ name: 'createUsersWithListInput',
459
+ description: 'Creates list of users with given input array.',
460
+ schema: z.object({
344
461
  requestBody: z.array(z.unknown()).optional().describe('Request body')
345
462
  }),
346
- execute: async (params) => {
463
+ },
464
+ async (params) => {
347
465
  const toolConfig = toolConfigMap.get('createUsersWithListInput');
348
466
  const result = await executeRequest(toolConfig, params, apiConfig);
349
467
 
350
- if (result.ok) {
351
- return typeof result.data === 'string'
352
- ? result.data
353
- : JSON.stringify(result.data, null, 2);
468
+ if (!result.ok) {
469
+ return text(`Error: ${result.status} ${result.statusText}\n${
470
+ typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2)
471
+ }`);
472
+ }
473
+
474
+ // Return MCP content based on response type
475
+ if (typeof result.data === 'string') {
476
+ return text(result.data);
477
+ } else if (typeof result.data === 'object' && result.data !== null) {
478
+ return object(result.data);
354
479
  } else {
355
- throw new Error(`API Error (${result.status}): ${typeof result.data === 'string' ? result.data : JSON.stringify(result.data)
356
- }`);
480
+ return text(String(result.data));
357
481
  }
358
- },
359
- });
482
+ }
483
+ );
360
484
 
361
485
  // Logs user into the system.
362
- server.tool('loginUser', {
363
- description: 'Logs user into the system.',
364
- parameters: z.object({
486
+ server.tool(
487
+ {
488
+ name: 'loginUser',
489
+ description: 'Logs user into the system.',
490
+ schema: z.object({
365
491
  username: z.string().optional().describe('The user name for login'),
366
492
  password: z.string().optional().describe('The password for login in clear text')
367
493
  }),
368
- execute: async (params) => {
494
+ },
495
+ async (params) => {
369
496
  const toolConfig = toolConfigMap.get('loginUser');
370
497
  const result = await executeRequest(toolConfig, params, apiConfig);
371
498
 
372
- if (result.ok) {
373
- return typeof result.data === 'string'
374
- ? result.data
375
- : JSON.stringify(result.data, null, 2);
499
+ if (!result.ok) {
500
+ return text(`Error: ${result.status} ${result.statusText}\n${
501
+ typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2)
502
+ }`);
503
+ }
504
+
505
+ // Return MCP content based on response type
506
+ if (typeof result.data === 'string') {
507
+ return text(result.data);
508
+ } else if (typeof result.data === 'object' && result.data !== null) {
509
+ return object(result.data);
376
510
  } else {
377
- throw new Error(`API Error (${result.status}): ${typeof result.data === 'string' ? result.data : JSON.stringify(result.data)
378
- }`);
511
+ return text(String(result.data));
379
512
  }
380
- },
381
- });
513
+ }
514
+ );
382
515
 
383
516
  // Logs out current logged in user session.
384
- server.tool('logoutUser', {
385
- description: 'Logs out current logged in user session.',
386
- parameters: z.object({}),
387
- execute: async (params) => {
517
+ server.tool(
518
+ {
519
+ name: 'logoutUser',
520
+ description: 'Logs out current logged in user session.',
521
+ schema: z.object({}),
522
+ },
523
+ async (params) => {
388
524
  const toolConfig = toolConfigMap.get('logoutUser');
389
525
  const result = await executeRequest(toolConfig, params, apiConfig);
390
526
 
391
- if (result.ok) {
392
- return typeof result.data === 'string'
393
- ? result.data
394
- : JSON.stringify(result.data, null, 2);
527
+ if (!result.ok) {
528
+ return text(`Error: ${result.status} ${result.statusText}\n${
529
+ typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2)
530
+ }`);
531
+ }
532
+
533
+ // Return MCP content based on response type
534
+ if (typeof result.data === 'string') {
535
+ return text(result.data);
536
+ } else if (typeof result.data === 'object' && result.data !== null) {
537
+ return object(result.data);
395
538
  } else {
396
- throw new Error(`API Error (${result.status}): ${typeof result.data === 'string' ? result.data : JSON.stringify(result.data)
397
- }`);
539
+ return text(String(result.data));
398
540
  }
399
- },
400
- });
541
+ }
542
+ );
401
543
 
402
544
  // Get user by user name.
403
- server.tool('getUserByName', {
404
- description: 'Get user by user name.',
405
- parameters: z.object({
545
+ server.tool(
546
+ {
547
+ name: 'getUserByName',
548
+ description: 'Get user by user name.',
549
+ schema: z.object({
406
550
  username: z.string().describe('The name that needs to be fetched. Use user1 for testing')
407
551
  }),
408
- execute: async (params) => {
552
+ },
553
+ async (params) => {
409
554
  const toolConfig = toolConfigMap.get('getUserByName');
410
555
  const result = await executeRequest(toolConfig, params, apiConfig);
411
556
 
412
- if (result.ok) {
413
- return typeof result.data === 'string'
414
- ? result.data
415
- : JSON.stringify(result.data, null, 2);
557
+ if (!result.ok) {
558
+ return text(`Error: ${result.status} ${result.statusText}\n${
559
+ typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2)
560
+ }`);
561
+ }
562
+
563
+ // Return MCP content based on response type
564
+ if (typeof result.data === 'string') {
565
+ return text(result.data);
566
+ } else if (typeof result.data === 'object' && result.data !== null) {
567
+ return object(result.data);
416
568
  } else {
417
- throw new Error(`API Error (${result.status}): ${typeof result.data === 'string' ? result.data : JSON.stringify(result.data)
418
- }`);
569
+ return text(String(result.data));
419
570
  }
420
- },
421
- });
571
+ }
572
+ );
422
573
 
423
574
  // Update user resource.
424
- server.tool('updateUser', {
425
- description: 'Update user resource.',
426
- parameters: z.object({
575
+ server.tool(
576
+ {
577
+ name: 'updateUser',
578
+ description: 'Update user resource.',
579
+ schema: z.object({
427
580
  username: z.string().describe('name that need to be deleted'),
428
581
  requestBody: z.unknown().optional().describe('Update an existent user in the store')
429
582
  }),
430
- execute: async (params) => {
583
+ },
584
+ async (params) => {
431
585
  const toolConfig = toolConfigMap.get('updateUser');
432
586
  const result = await executeRequest(toolConfig, params, apiConfig);
433
587
 
434
- if (result.ok) {
435
- return typeof result.data === 'string'
436
- ? result.data
437
- : JSON.stringify(result.data, null, 2);
588
+ if (!result.ok) {
589
+ return text(`Error: ${result.status} ${result.statusText}\n${
590
+ typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2)
591
+ }`);
592
+ }
593
+
594
+ // Return MCP content based on response type
595
+ if (typeof result.data === 'string') {
596
+ return text(result.data);
597
+ } else if (typeof result.data === 'object' && result.data !== null) {
598
+ return object(result.data);
438
599
  } else {
439
- throw new Error(`API Error (${result.status}): ${typeof result.data === 'string' ? result.data : JSON.stringify(result.data)
440
- }`);
600
+ return text(String(result.data));
441
601
  }
442
- },
443
- });
602
+ }
603
+ );
444
604
 
445
605
  // Delete user resource.
446
- server.tool('deleteUser', {
447
- description: 'Delete user resource.',
448
- parameters: z.object({
606
+ server.tool(
607
+ {
608
+ name: 'deleteUser',
609
+ description: 'Delete user resource.',
610
+ schema: z.object({
449
611
  username: z.string().describe('The name that needs to be deleted')
450
612
  }),
451
- execute: async (params) => {
613
+ },
614
+ async (params) => {
452
615
  const toolConfig = toolConfigMap.get('deleteUser');
453
616
  const result = await executeRequest(toolConfig, params, apiConfig);
454
617
 
455
- if (result.ok) {
456
- return typeof result.data === 'string'
457
- ? result.data
458
- : JSON.stringify(result.data, null, 2);
618
+ if (!result.ok) {
619
+ return text(`Error: ${result.status} ${result.statusText}\n${
620
+ typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2)
621
+ }`);
622
+ }
623
+
624
+ // Return MCP content based on response type
625
+ if (typeof result.data === 'string') {
626
+ return text(result.data);
627
+ } else if (typeof result.data === 'object' && result.data !== null) {
628
+ return object(result.data);
459
629
  } else {
460
- throw new Error(`API Error (${result.status}): ${typeof result.data === 'string' ? result.data : JSON.stringify(result.data)
461
- }`);
630
+ return text(String(result.data));
462
631
  }
463
- },
464
- });
632
+ }
633
+ );
465
634
 
466
635
  // ============================================================================
467
636
  // Start Server
@@ -470,10 +639,10 @@ server.tool('deleteUser', {
470
639
  server.listen(PORT);
471
640
 
472
641
  console.log(`
473
- 🚀 petstore-api MCP Server Started!
642
+ 🚀 petstore-api MCP Server Started
474
643
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
475
644
 
476
- 📍 Server: http://localMCP Server Starthost:${PORT}
645
+ 📍 Server: http://localhost:${PORT}
477
646
  🔍 Inspector: http://localhost:${PORT}/inspector
478
647
  📡 MCP: http://localhost:${PORT}/mcp
479
648
  🔄 SSE: http://localhost:${PORT}/sse
@@ -485,9 +654,6 @@ console.log(`
485
654
  • findPetsByTags
486
655
  • getPetById
487
656
  ... and 14 more
488
-
489
657
  Environment: ${isDev ? 'Development' : 'Production'}
490
658
  API Base: ${apiConfig.baseUrl || 'Not configured'}
491
-
492
- Press Ctrl+C to stop the server.
493
659
  `);