@ampeco/public-api-mcp 0.2.0

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.
Files changed (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +734 -0
  3. package/dist/build/flattener.d.ts +39 -0
  4. package/dist/build/flattener.d.ts.map +1 -0
  5. package/dist/build/flattener.js +193 -0
  6. package/dist/build/flattener.js.map +1 -0
  7. package/dist/build/index.d.ts +13 -0
  8. package/dist/build/index.d.ts.map +1 -0
  9. package/dist/build/index.js +175 -0
  10. package/dist/build/index.js.map +1 -0
  11. package/dist/build/optimizer.d.ts +32 -0
  12. package/dist/build/optimizer.d.ts.map +1 -0
  13. package/dist/build/optimizer.js +222 -0
  14. package/dist/build/optimizer.js.map +1 -0
  15. package/dist/build/parser.d.ts +35 -0
  16. package/dist/build/parser.d.ts.map +1 -0
  17. package/dist/build/parser.js +83 -0
  18. package/dist/build/parser.js.map +1 -0
  19. package/dist/build/types.d.ts +91 -0
  20. package/dist/build/types.d.ts.map +1 -0
  21. package/dist/build/types.js +5 -0
  22. package/dist/build/types.js.map +1 -0
  23. package/dist/build/zod-generator.d.ts +34 -0
  24. package/dist/build/zod-generator.d.ts.map +1 -0
  25. package/dist/build/zod-generator.js +317 -0
  26. package/dist/build/zod-generator.js.map +1 -0
  27. package/dist/cli/index.d.ts +7 -0
  28. package/dist/cli/index.d.ts.map +1 -0
  29. package/dist/cli/index.js +99 -0
  30. package/dist/cli/index.js.map +1 -0
  31. package/dist/generated/build-stats.json +7 -0
  32. package/dist/generated/endpoints.json +32181 -0
  33. package/dist/generated/schemas.d.ts +8157 -0
  34. package/dist/generated/schemas.d.ts.map +1 -0
  35. package/dist/generated/schemas.js +2726 -0
  36. package/dist/generated/schemas.js.map +1 -0
  37. package/dist/generated/schemas.ts +3171 -0
  38. package/dist/server/factory.d.ts +11 -0
  39. package/dist/server/factory.d.ts.map +1 -0
  40. package/dist/server/factory.js +450 -0
  41. package/dist/server/factory.js.map +1 -0
  42. package/dist/server/factory.test.d.ts +5 -0
  43. package/dist/server/factory.test.d.ts.map +1 -0
  44. package/dist/server/factory.test.js +77 -0
  45. package/dist/server/factory.test.js.map +1 -0
  46. package/dist/server/http.d.ts +10 -0
  47. package/dist/server/http.d.ts.map +1 -0
  48. package/dist/server/http.js +110 -0
  49. package/dist/server/http.js.map +1 -0
  50. package/dist/server/index.d.ts +8 -0
  51. package/dist/server/index.d.ts.map +1 -0
  52. package/dist/server/index.js +1502 -0
  53. package/dist/server/index.js.map +1 -0
  54. package/dist/server/loader.d.ts +10 -0
  55. package/dist/server/loader.d.ts.map +1 -0
  56. package/dist/server/loader.js +19 -0
  57. package/dist/server/loader.js.map +1 -0
  58. package/dist/server/prompts.d.ts +6 -0
  59. package/dist/server/prompts.d.ts.map +1 -0
  60. package/dist/server/prompts.js +462 -0
  61. package/dist/server/prompts.js.map +1 -0
  62. package/dist/server/stdio.d.ts +10 -0
  63. package/dist/server/stdio.d.ts.map +1 -0
  64. package/dist/server/stdio.js +25 -0
  65. package/dist/server/stdio.js.map +1 -0
  66. package/package.json +60 -0
@@ -0,0 +1,110 @@
1
+ /**
2
+ * HTTP MCP Server
3
+ * Runs MCP server with HTTP Streamable transport for remote access
4
+ */
5
+ import express from 'express';
6
+ import cors from 'cors';
7
+ import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
8
+ import { createServer } from './factory.js';
9
+ import { loadEndpoints } from './loader.js';
10
+ /**
11
+ * Start MCP server in HTTP mode
12
+ * Creates Express server listening on specified port
13
+ */
14
+ export async function startHttpServer(port) {
15
+ console.log('[HTTP Mode] Starting MCP server...');
16
+ const endpoints = loadEndpoints();
17
+ console.log(`[HTTP Mode] Loaded ${endpoints.endpoints.length} endpoints from ${endpoints.info.title} v${endpoints.info.version}`);
18
+ console.log(`[HTTP Mode] Optimization: ${endpoints.stats.reductionPercent.toFixed(2)}% size reduction`);
19
+ // Create Express app
20
+ const app = express();
21
+ app.use(express.json());
22
+ // Configure CORS to allow access from any domain
23
+ app.use(cors({
24
+ origin: true, // Allow all origins (more permissive than '*' for credentials)
25
+ methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'],
26
+ allowedHeaders: '*', // Allow all headers
27
+ exposedHeaders: ['*'], // Expose all headers
28
+ credentials: true, // Allow credentials
29
+ preflightContinue: false,
30
+ optionsSuccessStatus: 204,
31
+ }));
32
+ // Health check endpoint
33
+ app.get('/health', (_req, res) => {
34
+ res.json({
35
+ status: 'healthy',
36
+ server: 'public-api-mcp',
37
+ version: '0.1.0',
38
+ endpoints: endpoints.endpoints.length,
39
+ api: {
40
+ title: endpoints.info.title,
41
+ version: endpoints.info.version,
42
+ },
43
+ });
44
+ });
45
+ // MCP endpoint - hostname is extracted from the path
46
+ // Example: POST /api.example.com or POST /api.example.com/http or POST /api.example.com/https
47
+ app.post('/*', async (req, res) => {
48
+ // Extract Bearer token from Authorization header
49
+ const authHeader = req.headers.authorization;
50
+ const bearerToken = authHeader?.startsWith('Bearer ') ? authHeader.substring(7) : '';
51
+ // Extract hostname and optional protocol from path
52
+ const fullPath = req.params[0]; // Wildcard capture
53
+ // Check if path ends with /http or /https
54
+ let protocol = 'https'; // Default to https
55
+ let hostnameWithoutSuffix = fullPath;
56
+ if (fullPath.endsWith('/http')) {
57
+ protocol = 'http';
58
+ hostnameWithoutSuffix = fullPath.slice(0, -5); // Remove '/http'
59
+ }
60
+ else if (fullPath.endsWith('/https')) {
61
+ protocol = 'https';
62
+ hostnameWithoutSuffix = fullPath.slice(0, -6); // Remove '/https'
63
+ }
64
+ const hostname = `${protocol}://${hostnameWithoutSuffix}`;
65
+ console.log(`[MCP Request] Target API: ${hostname}, Method: ${req.body?.method || 'unknown'}`);
66
+ // Create server instance with the bearer token and hostname
67
+ const server = createServer(endpoints, bearerToken, hostname);
68
+ try {
69
+ // Create stateless transport (no session management)
70
+ const transport = new StreamableHTTPServerTransport({
71
+ sessionIdGenerator: undefined,
72
+ });
73
+ // Connect server to transport
74
+ await server.connect(transport);
75
+ // Handle the request
76
+ await transport.handleRequest(req, res, req.body);
77
+ // Clean up when request closes
78
+ res.on('close', () => {
79
+ transport.close();
80
+ server.close();
81
+ });
82
+ }
83
+ catch (error) {
84
+ console.error('Error handling MCP request:', error);
85
+ if (!res.headersSent) {
86
+ res.status(500).json({
87
+ jsonrpc: '2.0',
88
+ error: {
89
+ code: -32603,
90
+ message: 'Internal server error',
91
+ data: error instanceof Error ? error.message : String(error),
92
+ },
93
+ });
94
+ }
95
+ }
96
+ });
97
+ // Start server
98
+ app.listen(port, () => {
99
+ console.log(`\n🚀 MCP Server started successfully!`);
100
+ console.log(` Port: ${port}`);
101
+ console.log(` Health: http://localhost:${port}/health`);
102
+ console.log(` MCP Endpoint Pattern: http://localhost:${port}/{hostname}[/{protocol}]`);
103
+ console.log(` Examples:`);
104
+ console.log(` - http://localhost:${port}/api.example.com (defaults to https)`);
105
+ console.log(` - http://localhost:${port}/api.example.com/https (explicit https)`);
106
+ console.log(` - http://localhost:${port}/api.example.com/http (explicit http)`);
107
+ console.log(`\nReady to accept MCP requests.\n`);
108
+ });
109
+ }
110
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/server/http.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,IAAY;IAChD,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;IAElD,MAAM,SAAS,GAAG,aAAa,EAAE,CAAC;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AA0B,CAAC,CAAC;QACzF,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAC5B,OAAO,CAAC,GAAG,CAAC,2BAA2B,IAAI,sCAAsC,CAAC,CAAC;QACnF,OAAO,CAAC,GAAG,CAAC,2BAA2B,IAAI,yCAAyC,CAAC,CAAC;QACtF,OAAO,CAAC,GAAG,CAAC,2BAA2B,IAAI,uCAAuC,CAAC,CAAC;QACpF,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * MCP Server for OpenAPI-defined APIs
3
+ *
4
+ * This server exposes pre-processed OpenAPI endpoints as MCP resources and provides
5
+ * a tool for making authenticated HTTP requests to any endpoint.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}