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.
@@ -1,5 +1,5 @@
1
1
  // Tool configurations extracted from OpenAPI spec
2
- // Generated: 2025-12-30T23:36:57.080Z
2
+ // Generated: 2025-12-31T01:39:23.971Z
3
3
 
4
4
  export const toolConfigs = [
5
5
  {
@@ -15,7 +15,6 @@
15
15
 
16
16
  import fs from 'fs/promises';
17
17
  import path from 'path';
18
- import { fileURLToPath } from 'url';
19
18
 
20
19
  // ============================================================================
21
20
  // OpenAPI Spec Loading & Parsing
@@ -247,9 +246,9 @@ function generatePackageJson(serverName, tools, port) {
247
246
  dev: 'node --watch src/index.js',
248
247
  },
249
248
  dependencies: {
250
- 'mcp-use': '1.11.2',
249
+ 'mcp-use': '^1.11.2',
251
250
  'zod': '^3.23.0',
252
- 'dotenv': '^17.2.3',
251
+ 'dotenv': '^16.4.0',
253
252
  },
254
253
  engines: { node: '>=18.0.0' },
255
254
  }, null, 2);
@@ -439,35 +438,43 @@ export const toolConfigMap = new Map(toolConfigs.map(t => [t.name, t]));
439
438
  }
440
439
 
441
440
  function generateServerIndex(serverName, tools, baseUrl, port) {
442
- // Generate tool registration code
441
+ // Generate tool registration code using proper MCP format
443
442
  const toolRegistrations = tools.map(tool => {
444
443
  return `
445
444
  // ${tool.description}
446
- server.tool('${tool.name}', {
447
- description: '${tool.description.replace(/'/g, "\\'")}',
448
- parameters: ${tool.zodSchema},
449
- execute: async (params) => {
445
+ server.tool(
446
+ {
447
+ name: '${tool.name}',
448
+ description: '${tool.description.replace(/'/g, "\\'")}',
449
+ schema: ${tool.zodSchema},
450
+ },
451
+ async (params) => {
450
452
  const toolConfig = toolConfigMap.get('${tool.name}');
451
453
  const result = await executeRequest(toolConfig, params, apiConfig);
452
-
453
- if (result.ok) {
454
- return typeof result.data === 'string'
455
- ? result.data
456
- : JSON.stringify(result.data, null, 2);
457
- } else {
458
- throw new Error(\`API Error (\${result.status}): \${
459
- typeof result.data === 'string' ? result.data : JSON.stringify(result.data)
454
+
455
+ if (!result.ok) {
456
+ return text(\`Error: \${result.status} \${result.statusText}\\n\${
457
+ typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2)
460
458
  }\`);
461
459
  }
462
- },
463
- });`;
460
+
461
+ // Return MCP content based on response type
462
+ if (typeof result.data === 'string') {
463
+ return text(result.data);
464
+ } else if (typeof result.data === 'object' && result.data !== null) {
465
+ return object(result.data);
466
+ } else {
467
+ return text(String(result.data));
468
+ }
469
+ }
470
+ );`;
464
471
  }).join('\n');
465
472
 
466
473
  return `#!/usr/bin/env node
467
474
 
468
475
  /**
469
476
  * ${serverName} - MCP Server
470
- *
477
+ *
471
478
  * Features:
472
479
  * - ${tools.length} API tools available
473
480
  * - Built-in Inspector at http://localhost:${port}/inspector
@@ -475,6 +482,7 @@ server.tool('${tool.name}', {
475
482
 
476
483
  import 'dotenv/config';
477
484
  import { MCPServer } from 'mcp-use/server';
485
+ import { text, object } from 'mcp-use/server';
478
486
  import { z } from 'zod';
479
487
  import { executeRequest } from './http-client.js';
480
488
  import { toolConfigMap } from './tools-config.js';
@@ -644,9 +652,32 @@ ${serverName}/
644
652
  ├── package.json # Dependencies
645
653
  ├── README.md # This file
646
654
  └── src/
647
- ├── index.js # Main server with tool registrations
648
- ├── http-client.js # HTTP utilities for API calls
649
- └── tools-config.js # Tool configurations from OpenAPI
655
+ ├── index.js # Main server with MCP tool registrations
656
+ ├── http-client.js # HTTP utilities for API calls
657
+ └── tools-config.js # Tool configurations from OpenAPI spec
658
+ \`\`\`
659
+
660
+ ## How It Works
661
+
662
+ Each tool is registered using the proper MCP format:
663
+
664
+ \`\`\`javascript
665
+ server.tool(
666
+ {
667
+ name: 'getPetById',
668
+ description: 'Find pet by ID',
669
+ schema: z.object({
670
+ petId: z.number().int().describe('ID of pet to return'),
671
+ }),
672
+ },
673
+ async (params) => {
674
+ // Fetch data from the API
675
+ const result = await executeRequest(toolConfig, params, apiConfig);
676
+
677
+ // Return MCP content (text or object)
678
+ return result.ok ? object(result.data) : text(\`Error: \${result.status}\`);
679
+ }
680
+ );
650
681
  \`\`\`
651
682
 
652
683
  ## Production Deployment
@@ -776,7 +807,7 @@ Then open http://localhost:${port}/inspector to test your tools!
776
807
  export { generateMcpServer, extractTools, loadOpenApiSpec };
777
808
 
778
809
  // CLI entry point
779
- const isMainModule = process.argv[1] === fileURLToPath(import.meta.url);
810
+ const isMainModule = process.argv[1]?.includes('api2ai');
780
811
 
781
812
  if (isMainModule) {
782
813
  const args = process.argv.slice(2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api2ai",
3
- "version": "1.0.3",
3
+ "version": "1.0.6",
4
4
  "description": "Generate MCP servers from OpenAPI specs using the mcp-use framework",
5
5
  "type": "module",
6
6
  "main": "generate-mcp-use-server.js",
@@ -15,9 +15,6 @@
15
15
  "dependencies": {
16
16
  "js-yaml": "^4.1.0"
17
17
  },
18
- "devDependencies": {
19
- "js-yaml": "^4.1.0"
20
- },
21
18
  "engines": {
22
19
  "node": ">=18.0.0"
23
20
  },