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.
- package/.claude/settings.local.json +7 -0
- package/README.md +33 -3
- package/example-petstore/README.md +27 -4
- package/example-petstore/bun.lock +789 -49
- package/example-petstore/package.json +1 -1
- package/example-petstore/src/index.js +404 -238
- package/example-petstore/src/tools-config.js +1 -1
- package/generate-mcp-use-server.js +54 -23
- package/package.json +1 -4
|
@@ -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(
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
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
|
|
76
|
-
? result.data
|
|
77
|
-
|
|
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
|
-
|
|
80
|
-
}`);
|
|
87
|
+
return text(String(result.data));
|
|
81
88
|
}
|
|
82
|
-
}
|
|
83
|
-
|
|
89
|
+
}
|
|
90
|
+
);
|
|
84
91
|
|
|
85
92
|
// Update an existing pet.
|
|
86
|
-
server.tool(
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
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
|
|
97
|
-
? result.data
|
|
98
|
-
|
|
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
|
-
|
|
101
|
-
}`);
|
|
117
|
+
return text(String(result.data));
|
|
102
118
|
}
|
|
103
|
-
}
|
|
104
|
-
|
|
119
|
+
}
|
|
120
|
+
);
|
|
105
121
|
|
|
106
122
|
// Finds Pets by status.
|
|
107
|
-
server.tool(
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
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
|
|
118
|
-
? result.data
|
|
119
|
-
|
|
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
|
-
|
|
122
|
-
}`);
|
|
147
|
+
return text(String(result.data));
|
|
123
148
|
}
|
|
124
|
-
}
|
|
125
|
-
|
|
149
|
+
}
|
|
150
|
+
);
|
|
126
151
|
|
|
127
152
|
// Finds Pets by tags.
|
|
128
|
-
server.tool(
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
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
|
|
139
|
-
? result.data
|
|
140
|
-
|
|
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
|
-
|
|
143
|
-
}`);
|
|
177
|
+
return text(String(result.data));
|
|
144
178
|
}
|
|
145
|
-
}
|
|
146
|
-
|
|
179
|
+
}
|
|
180
|
+
);
|
|
147
181
|
|
|
148
182
|
// Find pet by ID.
|
|
149
|
-
server.tool(
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
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
|
|
160
|
-
? result.data
|
|
161
|
-
|
|
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
|
-
|
|
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(
|
|
171
|
-
|
|
172
|
-
|
|
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
|
-
|
|
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
|
|
183
|
-
? result.data
|
|
184
|
-
|
|
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
|
-
|
|
187
|
-
}`);
|
|
239
|
+
return text(String(result.data));
|
|
188
240
|
}
|
|
189
|
-
}
|
|
190
|
-
|
|
241
|
+
}
|
|
242
|
+
);
|
|
191
243
|
|
|
192
244
|
// Deletes a pet.
|
|
193
|
-
server.tool(
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
|
|
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
|
|
205
|
-
? result.data
|
|
206
|
-
|
|
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
|
-
|
|
209
|
-
}`);
|
|
270
|
+
return text(String(result.data));
|
|
210
271
|
}
|
|
211
|
-
}
|
|
212
|
-
|
|
272
|
+
}
|
|
273
|
+
);
|
|
213
274
|
|
|
214
275
|
// Uploads an image.
|
|
215
|
-
server.tool(
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
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
|
|
228
|
-
? result.data
|
|
229
|
-
|
|
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
|
-
|
|
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(
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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
|
|
247
|
-
? result.data
|
|
248
|
-
|
|
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
|
-
|
|
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(
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
|
|
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
|
|
268
|
-
? result.data
|
|
269
|
-
|
|
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
|
-
|
|
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(
|
|
279
|
-
|
|
280
|
-
|
|
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
|
-
|
|
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
|
|
289
|
-
? result.data
|
|
290
|
-
|
|
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
|
-
|
|
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(
|
|
300
|
-
|
|
301
|
-
|
|
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
|
-
|
|
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
|
|
310
|
-
? result.data
|
|
311
|
-
|
|
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
|
-
|
|
314
|
-
}`);
|
|
420
|
+
return text(String(result.data));
|
|
315
421
|
}
|
|
316
|
-
}
|
|
317
|
-
|
|
422
|
+
}
|
|
423
|
+
);
|
|
318
424
|
|
|
319
425
|
// Create user.
|
|
320
|
-
server.tool(
|
|
321
|
-
|
|
322
|
-
|
|
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
|
-
|
|
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
|
|
331
|
-
? result.data
|
|
332
|
-
|
|
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
|
-
|
|
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(
|
|
342
|
-
|
|
343
|
-
|
|
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
|
-
|
|
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
|
|
352
|
-
? result.data
|
|
353
|
-
|
|
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
|
-
|
|
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(
|
|
363
|
-
|
|
364
|
-
|
|
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
|
-
|
|
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
|
|
374
|
-
? result.data
|
|
375
|
-
|
|
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
|
-
|
|
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(
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
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
|
|
393
|
-
? result.data
|
|
394
|
-
|
|
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
|
-
|
|
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(
|
|
404
|
-
|
|
405
|
-
|
|
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
|
-
|
|
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
|
|
414
|
-
? result.data
|
|
415
|
-
|
|
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
|
-
|
|
418
|
-
}`);
|
|
569
|
+
return text(String(result.data));
|
|
419
570
|
}
|
|
420
|
-
}
|
|
421
|
-
|
|
571
|
+
}
|
|
572
|
+
);
|
|
422
573
|
|
|
423
574
|
// Update user resource.
|
|
424
|
-
server.tool(
|
|
425
|
-
|
|
426
|
-
|
|
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
|
-
|
|
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
|
|
436
|
-
? result.data
|
|
437
|
-
|
|
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
|
-
|
|
440
|
-
}`);
|
|
600
|
+
return text(String(result.data));
|
|
441
601
|
}
|
|
442
|
-
}
|
|
443
|
-
|
|
602
|
+
}
|
|
603
|
+
);
|
|
444
604
|
|
|
445
605
|
// Delete user resource.
|
|
446
|
-
server.tool(
|
|
447
|
-
|
|
448
|
-
|
|
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
|
-
|
|
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
|
|
457
|
-
? result.data
|
|
458
|
-
|
|
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
|
-
|
|
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://
|
|
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
|
`);
|