api2ai 1.0.6 → 1.0.8
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 +159 -54
- package/package.json +238 -20
- package/.claude/settings.local.json +0 -7
- package/bun.lock +0 -17
- package/example-petstore/.env.example +0 -14
- package/example-petstore/README.md +0 -168
- package/example-petstore/bun.lock +0 -1127
- package/example-petstore/package.json +0 -19
- package/example-petstore/src/http-client.js +0 -120
- package/example-petstore/src/index.js +0 -659
- package/example-petstore/src/tools-config.js +0 -247
- package/example.js +0 -164
- package/generate-mcp-use-server.js +0 -864
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "petstore-api",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "MCP server generated from OpenAPI spec (19 tools)",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "src/index.js",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"start": "node src/index.js",
|
|
9
|
-
"dev": "node --watch src/index.js"
|
|
10
|
-
},
|
|
11
|
-
"dependencies": {
|
|
12
|
-
"mcp-use": "^1.11.2",
|
|
13
|
-
"zod": "^3.23.0",
|
|
14
|
-
"dotenv": "^16.4.0"
|
|
15
|
-
},
|
|
16
|
-
"engines": {
|
|
17
|
-
"node": ">=18.0.0"
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
// HTTP client for API requests
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Build URL with path parameters substituted
|
|
5
|
-
*/
|
|
6
|
-
export function buildUrl(baseUrl, pathTemplate, pathParams = {}) {
|
|
7
|
-
let url = pathTemplate;
|
|
8
|
-
for (const [key, value] of Object.entries(pathParams)) {
|
|
9
|
-
url = url.replace(`{${key}}`, encodeURIComponent(String(value)));
|
|
10
|
-
}
|
|
11
|
-
return new URL(url, baseUrl).toString();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Build query string from parameters
|
|
16
|
-
*/
|
|
17
|
-
export function buildQueryString(queryParams = {}) {
|
|
18
|
-
const params = new URLSearchParams();
|
|
19
|
-
for (const [key, value] of Object.entries(queryParams)) {
|
|
20
|
-
if (value !== undefined && value !== null) {
|
|
21
|
-
if (Array.isArray(value)) {
|
|
22
|
-
value.forEach(v => params.append(key, String(v)));
|
|
23
|
-
} else {
|
|
24
|
-
params.append(key, String(value));
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return params.toString();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Execute HTTP request for a tool
|
|
33
|
-
*/
|
|
34
|
-
export async function executeRequest(toolConfig, args, config = {}) {
|
|
35
|
-
const { baseUrl: configBaseUrl, headers: configHeaders = {} } = config;
|
|
36
|
-
const baseUrl = configBaseUrl || toolConfig.baseUrl;
|
|
37
|
-
|
|
38
|
-
if (!baseUrl) {
|
|
39
|
-
throw new Error(`No base URL configured for tool: ${toolConfig.name}`);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Separate parameters by location
|
|
43
|
-
const pathParams = {};
|
|
44
|
-
const queryParams = {};
|
|
45
|
-
const headerParams = {};
|
|
46
|
-
let body;
|
|
47
|
-
|
|
48
|
-
for (const param of toolConfig.executionParameters || []) {
|
|
49
|
-
const value = args[param.name];
|
|
50
|
-
if (value === undefined) continue;
|
|
51
|
-
|
|
52
|
-
switch (param.in) {
|
|
53
|
-
case 'path':
|
|
54
|
-
pathParams[param.name] = value;
|
|
55
|
-
break;
|
|
56
|
-
case 'query':
|
|
57
|
-
queryParams[param.name] = value;
|
|
58
|
-
break;
|
|
59
|
-
case 'header':
|
|
60
|
-
headerParams[param.name] = value;
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Handle request body
|
|
66
|
-
if (args.requestBody !== undefined) {
|
|
67
|
-
body = args.requestBody;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Build URL
|
|
71
|
-
let url = buildUrl(baseUrl, toolConfig.pathTemplate, pathParams);
|
|
72
|
-
|
|
73
|
-
// Add query parameters
|
|
74
|
-
const queryString = buildQueryString(queryParams);
|
|
75
|
-
if (queryString) {
|
|
76
|
-
url += (url.includes('?') ? '&' : '?') + queryString;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Build headers
|
|
80
|
-
const headers = {
|
|
81
|
-
'Accept': 'application/json',
|
|
82
|
-
...configHeaders,
|
|
83
|
-
...headerParams,
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
// Set content type for request body
|
|
87
|
-
if (body !== undefined) {
|
|
88
|
-
headers['Content-Type'] = toolConfig.requestBodyContentType || 'application/json';
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Build request options
|
|
92
|
-
const requestOptions = {
|
|
93
|
-
method: toolConfig.method.toUpperCase(),
|
|
94
|
-
headers,
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
if (body !== undefined && ['POST', 'PUT', 'PATCH'].includes(requestOptions.method)) {
|
|
98
|
-
requestOptions.body = typeof body === 'string' ? body : JSON.stringify(body);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Execute request
|
|
102
|
-
const response = await fetch(url, requestOptions);
|
|
103
|
-
|
|
104
|
-
// Parse response
|
|
105
|
-
const contentType = response.headers.get('content-type') || '';
|
|
106
|
-
let data;
|
|
107
|
-
|
|
108
|
-
if (contentType.includes('application/json')) {
|
|
109
|
-
data = await response.json();
|
|
110
|
-
} else {
|
|
111
|
-
data = await response.text();
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return {
|
|
115
|
-
status: response.status,
|
|
116
|
-
statusText: response.statusText,
|
|
117
|
-
data,
|
|
118
|
-
ok: response.ok,
|
|
119
|
-
};
|
|
120
|
-
}
|