@ampeco/public-api-mcp 0.2.0 → 0.2.2

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 CHANGED
@@ -19,7 +19,7 @@ claude mcp add --transport stdio ampeco-api-dev \
19
19
  # One-liner to add production server
20
20
  claude mcp add --transport stdio ampeco-api \
21
21
  --env AMPECO_BEARER_TOKEN=your-token-here \
22
- -- npx -y @ampeco/public-api-mcp --stdio --hostname http://demo.charge.alex2.dev.ampeco.tech
22
+ -- npx -y @ampeco/public-api-mcp --stdio --hostname https://api.example.com
23
23
  ```
24
24
 
25
25
  ### HTTP Mode (Remote Server)
@@ -30,7 +30,7 @@ PORT=3001 npm run dev:http
30
30
 
31
31
  # Then add to Claude Code
32
32
  claude mcp add --transport http ampeco-api \
33
- http://localhost:3001/demo.charge.alex2.dev.ampeco.tech \
33
+ http://localhost:3001/api.example.com \
34
34
  --header "Authorization: Bearer your-token-here"
35
35
  ```
36
36
 
@@ -40,83 +40,6 @@ See [Setting Up with Claude Code](#setting-up-with-claude-code) for detailed ins
40
40
 
41
41
  This project transforms OpenAPI specifications into optimized, self-contained API definitions that can be served through the Model Context Protocol. It features a sophisticated build pipeline that processes OpenAPI specs at build time to minimize runtime overhead and reduce token usage.
42
42
 
43
- ## Phase 1: Build Pipeline Foundation ✅
44
-
45
- ### Completed Features
46
-
47
- #### 1. OpenAPI Parsing Module with Dereferencing
48
- - ✅ Loads and bundles OpenAPI 3 specifications (JSON/YAML)
49
- - ✅ Resolves external file references
50
- - ✅ Handles circular references automatically
51
- - ✅ Creates self-contained endpoint definitions
52
-
53
- **Location**: `src/build/parser.ts`
54
-
55
- #### 2. Schema Flattening
56
- - ✅ Flattens `allOf` compositions by merging properties
57
- - ✅ Resolves nested schemas to reduce complexity
58
- - ✅ Handles `anyOf`, `oneOf`, and complex schema constructs
59
- - ✅ Deep merging of object properties
60
-
61
- **Location**: `src/build/flattener.ts`
62
-
63
- #### 3. Security Embedding Logic
64
- - ✅ Embeds full security scheme details per endpoint
65
- - ✅ Includes authentication type, scheme, and usage instructions
66
- - ✅ Eliminates references to shared security components
67
- - ✅ Generates human-readable authentication descriptions
68
-
69
- **Location**: `src/build/security-embedder.ts`
70
-
71
- #### 4. Optimization and Minification
72
- - ✅ Removes redundant whitespace and empty keys
73
- - ✅ Optimizes schema definitions
74
- - ✅ **Achieved 22.39% size reduction** on target API
75
- - ✅ Calculates and reports optimization statistics
76
-
77
- **Location**: `src/build/optimizer.ts`
78
-
79
- #### 5. Zod Schema Generation
80
- - ✅ Converts OpenAPI schemas to Zod validation schemas
81
- - ✅ Supports complex types, enums, unions, and validation rules
82
- - ✅ Handles edge cases (null enums, single-element unions, number enums)
83
- - ✅ Generates TypeScript code for runtime validation
84
-
85
- **Location**: `src/build/zod-generator.ts`
86
-
87
- ### Build Statistics
88
-
89
- Successfully processed the AMPECO.CHARGE Public API (v3.96.4):
90
-
91
- ```
92
- Total Endpoints: 443
93
- Original Size: 809,161 bytes
94
- Optimized Size: 628,009 bytes
95
- Size Reduction: 22.39%
96
- Build Duration: ~1 second
97
- ```
98
-
99
- ### Generated Artifacts
100
-
101
- The build pipeline produces three files in `src/generated/`:
102
-
103
- 1. **`endpoints.json`** (1.2MB)
104
- - Optimized endpoint definitions
105
- - Fully dereferenced schemas
106
- - Embedded security requirements
107
- - API metadata and build statistics
108
-
109
- 2. **`schemas.ts`** (122KB)
110
- - Generated Zod validation schemas
111
- - Type-safe parameter validation
112
- - Request body schemas
113
- - Auto-generated from OpenAPI spec
114
-
115
- 3. **`build-stats.json`**
116
- - Build metrics
117
- - Optimization statistics
118
- - Performance data
119
-
120
43
  ## Usage
121
44
 
122
45
  ### Running the Build Pipeline
@@ -138,14 +61,13 @@ npm run dev
138
61
  ```
139
62
 
140
63
  The build script:
141
- 1. Parses the OpenAPI spec from the specified path (defaults to `../backend/main/docs/public.yaml`)
64
+ 1. Parses the OpenAPI spec from the specified path
142
65
  2. Processes all endpoints through the optimization pipeline
143
66
  3. Generates Zod schemas for runtime validation
144
67
  4. Outputs optimized artifacts to `src/generated/`
145
68
 
146
69
  **Configuration Options:**
147
70
  - **`OPENAPI_SPEC_PATH`**: Path to the OpenAPI YAML/JSON file (relative or absolute)
148
- - Default: `../backend/main/docs/public.yaml`
149
71
  - Can be set as an environment variable or passed directly to npm commands
150
72
  - Used by both `npm run build` and `npm run dev`
151
73
 
@@ -172,8 +94,6 @@ OpenAPI Spec
172
94
 
173
95
  [Flattener] Flatten Schemas (allOf, nested objects)
174
96
 
175
- [Security] Embed Authentication Details
176
-
177
97
  [Optimizer] Minify & Optimize
178
98
 
179
99
  [Zod Generator] Generate Validation Schemas
@@ -181,115 +101,16 @@ OpenAPI Spec
181
101
  Generated Artifacts (endpoints.json, schemas.ts)
182
102
  ```
183
103
 
184
- ### Module Structure
104
+ ### MCP Server
185
105
 
186
- ```
187
- src/
188
- ├── build/ # Build-time pipeline
189
- │ ├── index.ts # Pipeline orchestrator
190
- │ ├── parser.ts # OpenAPI parsing & bundling
191
- │ ├── flattener.ts # Schema flattening logic
192
- │ ├── security-embedder.ts # Security details embedding
193
- │ ├── optimizer.ts # Optimization & minification
194
- │ ├── zod-generator.ts # Zod schema generation
195
- │ └── types.ts # Build pipeline types
196
-
197
- ├── cli/ # CLI entry point
198
- │ └── index.ts # Argument parsing & mode selection
199
-
200
- ├── server/ # Runtime MCP server
201
- │ ├── factory.ts # Shared server creation logic
202
- │ ├── loader.ts # Endpoint loading module
203
- │ ├── prompts.ts # Workflow prompt handlers
204
- │ ├── stdio.ts # Stdio transport server
205
- │ ├── http.ts # HTTP transport server
206
- │ ├── index.ts # (Legacy - kept for reference)
207
- │ └── factory.test.ts # Unit tests
208
-
209
- └── generated/ # Build output (gitignored)
210
- ├── endpoints.json # Optimized endpoints (~1.2MB)
211
- ├── schemas.ts # Zod validation schemas (~122KB)
212
- └── build-stats.json # Build statistics
213
- ```
214
-
215
- ## Key Features
216
-
217
- ### Zero Runtime Overhead
218
- All OpenAPI processing happens at build time. The server loads pre-processed, optimized data instantly.
219
-
220
- ### Comprehensive Dereferencing
221
- Resolves all `$ref` pointers (external files, internal components) to create fully self-contained endpoint definitions.
222
-
223
- ### Intelligent Schema Flattening
224
- - Merges `allOf` compositions
225
- - Resolves nested complexity
226
- - Handles circular references
227
-
228
- ### Embedded Security Documentation
229
- Each endpoint includes complete authentication instructions:
230
- - Bearer token: "Include token in Authorization header as: Authorization: Bearer <token>"
231
- - API key, OAuth, and other schemes fully documented
232
-
233
- ### Token Optimization
234
- Aggressive optimization targeting 50-70% token reduction through:
235
- - Redundant data removal
236
- - Whitespace minimization
237
- - Essential-only field retention
238
-
239
- ### Type Safety
240
- - Generated Zod schemas for runtime validation
241
- - TypeScript types for compile-time safety
242
- - Validates parameters before API calls
243
-
244
- ## Phase 2: MCP Server Core ✅
245
-
246
- ### Completed Features
247
-
248
- #### 1. Streamable HTTP Transport Server
249
- - ✅ Express-based HTTP server with MCP transport
250
- - ✅ Stateless design (no session management)
251
- - ✅ CORS-enabled for browser clients
252
- - ✅ Health check endpoint at `/health`
253
- - ✅ MCP protocol endpoint at `/mcp`
254
-
255
- **Location**: `src/server/index.ts`
106
+ The server provides a complete MCP implementation for accessing your OpenAPI-defined API:
256
107
 
257
- #### 2. Dynamic Resource Handlers
258
- - **Resources List**: Exposes all 443 API endpoints as MCP resources
259
- - **Resources Read**: Returns complete endpoint details
260
- - Path, method, operationId, descriptions
261
- - Request/response schemas (flattened and optimized)
262
- - Embedded security information
263
- - Parameter definitions with validation rules
264
-
265
- #### 3. HTTP Request Tool
266
- - ✅ Fully typed `api_request` tool with Zod validation
267
- - ✅ Parameters:
268
- - `hostname`: API base URL
269
- - `bearer_token`: Authentication token
270
- - `endpoint`: API path with parameter substitution
271
- - `method`: HTTP method (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS)
272
- - `path_params`: Path parameter values
273
- - `query_params`: Query string parameters
274
- - `body`: Request payload
275
- - `headers`: Additional HTTP headers
276
- - ✅ Automatic Bearer token authentication
277
- - ✅ Structured responses (status, headers, body)
278
-
279
- #### 4. Error Handling & Logging
280
- - ✅ Request/response logging to console
281
- - ✅ Graceful error handling with JSON-RPC error responses
282
- - ✅ Connection cleanup on request close
283
-
284
- ### Server Features
285
-
286
- **Stateless Architecture**: No session state required - hostname and auth tokens provided per request
287
-
288
- **Zero Configuration**: No config files needed - all parameters passed at runtime
289
-
290
- **Fast Startup**: Pre-processed endpoint data loads instantly
291
-
292
- **MCP Protocol Compliance**: Fully implements MCP Streamable HTTP transport specification
108
+ - **Dual Transport Support**: Both Stdio (local) and HTTP (remote) transports
109
+ - **Dynamic Resources**: All API endpoints exposed as MCP resources with full schema details
110
+ - **API Request Tool**: Fully typed `api_request` tool with automatic authentication and parameter validation
111
+ - **Stateless Architecture**: No session state required - all parameters provided per request
112
+ - **Zero Configuration**: Pre-processed data loads instantly, no config files needed
113
+ - **MCP Protocol Compliance**: Full implementation of MCP Streamable HTTP transport specification
293
114
 
294
115
  ### Running the Server
295
116
 
@@ -318,7 +139,7 @@ The server uses a hostname-based routing structure where the target API hostname
318
139
  - `POST /api.example.com` → Routes to `https://api.example.com`
319
140
  - `POST /api.example.com/https` → Routes to `https://api.example.com`
320
141
  - `POST /api.example.com/http` → Routes to `http://api.example.com`
321
- - `POST /demo.charge.dev.ampeco.tech/http` → Routes to `http://demo.charge.dev.ampeco.tech`
142
+ - `POST /internal.api.company.com/http` → Routes to `http://internal.api.company.com`
322
143
 
323
144
  ## Setting Up with Claude Code
324
145
 
@@ -385,12 +206,12 @@ For production use without needing the source code:
385
206
  # Add production server with a single command
386
207
  claude mcp add --transport stdio ampeco-api \
387
208
  --env AMPECO_BEARER_TOKEN=your-token-here \
388
- -- npx -y @ampeco/public-api-mcp --stdio --hostname http://demo.charge.alex2.dev.ampeco.tech
209
+ -- npx -y @ampeco/public-api-mcp --stdio --hostname https://api.example.com
389
210
  ```
390
211
 
391
212
  **Replace**:
392
213
  - `your-token-here` with your API token
393
- - `http://demo.charge.alex2.dev.ampeco.tech` with your target API hostname
214
+ - `https://api.example.com` with your target API hostname
394
215
 
395
216
  **Features**:
396
217
  - NPX downloads and caches the package automatically
@@ -412,7 +233,7 @@ Create `.mcp.json` in your project or home directory:
412
233
  "@ampeco/public-api-mcp",
413
234
  "--stdio",
414
235
  "--hostname",
415
- "http://demo.charge.alex2.dev.ampeco.tech"
236
+ "https://api.example.com"
416
237
  ],
417
238
  "env": {
418
239
  "AMPECO_BEARER_TOKEN": "your-token-here"
@@ -445,7 +266,7 @@ npm install -g @ampeco/public-api-mcp
445
266
  # Add globally installed server
446
267
  claude mcp add --transport stdio ampeco-api \
447
268
  --env AMPECO_BEARER_TOKEN=your-token-here \
448
- -- ampeco-api-mcp --stdio --hostname http://demo.charge.alex2.dev.ampeco.tech
269
+ -- ampeco-api-mcp --stdio --hostname https://api.example.com
449
270
  ```
450
271
 
451
272
  **Or manual configuration** in `.mcp.json`:
@@ -455,7 +276,7 @@ claude mcp add --transport stdio ampeco-api \
455
276
  "ampeco-api": {
456
277
  "type": "stdio",
457
278
  "command": "ampeco-api-mcp",
458
- "args": ["--stdio", "--hostname", "http://demo.charge.alex2.dev.ampeco.tech"],
279
+ "args": ["--stdio", "--hostname", "https://api.example.com"],
459
280
  "env": {"AMPECO_BEARER_TOKEN": "your-token-here"}
460
281
  }
461
282
  }
@@ -482,14 +303,14 @@ PORT=3001 npm start -- --http --port 3001
482
303
  ```bash
483
304
  # Add HTTP server with a single command
484
305
  claude mcp add --transport http ampeco-api \
485
- http://localhost:3001/demo.charge.alex2.dev.ampeco.tech \
306
+ http://localhost:3001/api.example.com \
486
307
  --header "Authorization: Bearer your-token-here"
487
308
  ```
488
309
 
489
310
  **With protocol override** (use HTTP for target API instead of HTTPS):
490
311
  ```bash
491
312
  claude mcp add --transport http ampeco-api \
492
- http://localhost:3001/demo.charge.alex2.dev.ampeco.tech/http \
313
+ http://localhost:3001/api.example.com/http \
493
314
  --header "Authorization: Bearer your-token-here"
494
315
  ```
495
316
 
@@ -499,7 +320,7 @@ claude mcp add --transport http ampeco-api \
499
320
  "mcpServers": {
500
321
  "ampeco-api-http": {
501
322
  "type": "http",
502
- "url": "http://localhost:3001/demo.charge.alex2.dev.ampeco.tech",
323
+ "url": "http://localhost:3001/api.example.com",
503
324
  "headers": {"Authorization": "Bearer your-token-here"}
504
325
  }
505
326
  }
@@ -526,23 +347,6 @@ claude mcp add --transport http ampeco-api \
526
347
 
527
348
  **Recommendation**: Use **stdio mode** for development and single-user production. Use **HTTP mode** for shared servers or when multiple clients need concurrent access.
528
349
 
529
- ### Configuration File Locations
530
-
531
- MCP configuration files can be placed at different scopes:
532
-
533
- | Scope | Location | Priority | Use Case |
534
- |-------|----------|----------|----------|
535
- | **Project** | `.mcp.json` in project root | Highest | Project-specific servers |
536
- | **User** | `~/.mcp.json` | Medium | Personal cross-project servers |
537
- | **Claude Code** | Per OS (see below) | N/A | Claude Code-specific |
538
-
539
- **Claude Code Configuration Locations:**
540
- - macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
541
- - Windows: `%APPDATA%\Claude\claude_desktop_config.json`
542
- - Linux: `~/.config/Claude/claude_desktop_config.json`
543
-
544
- **Recommendation**: Use project `.mcp.json` for development, user `~/.mcp.json` for production.
545
-
546
350
  ### Troubleshooting
547
351
 
548
352
  #### Stdio Mode Issues
@@ -614,104 +418,9 @@ npm run build
614
418
  - Test the token directly with the API:
615
419
  ```bash
616
420
  curl -H "Authorization: Bearer your-token" \
617
- http://demo.charge.alex2.dev.ampeco.tech/health
421
+ https://api.example.com/health
618
422
  ```
619
423
 
620
- ### Other MCP Clients (Claude Desktop, etc.)
621
-
622
- For other MCP-enabled tools like Claude Desktop, the configuration is similar:
623
-
624
- #### Stdio Configuration
625
-
626
- **Location**:
627
- - macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
628
- - Windows: `%APPDATA%\Claude\claude_desktop_config.json`
629
- - Linux: `~/.config/Claude/claude_desktop_config.json`
630
-
631
- ```json
632
- {
633
- "mcpServers": {
634
- "ampeco-api": {
635
- "command": "npx",
636
- "args": [
637
- "-y",
638
- "@ampeco/public-api-mcp",
639
- "--stdio",
640
- "--hostname",
641
- "http://demo.charge.alex2.dev.ampeco.tech"
642
- ],
643
- "env": {
644
- "AMPECO_BEARER_TOKEN": "your-api-token-here"
645
- }
646
- }
647
- }
648
- }
649
- ```
650
-
651
- #### HTTP Configuration
652
-
653
- If your MCP client supports HTTP transport:
654
-
655
- ```json
656
- {
657
- "mcpServers": {
658
- "ampeco-api": {
659
- "type": "http",
660
- "url": "http://localhost:3001/demo.charge.alex2.dev.ampeco.tech",
661
- "headers": {
662
- "Authorization": "Bearer your-api-token-here"
663
- }
664
- }
665
- }
666
- }
667
- ```
668
-
669
- **Server URL Format**: `http://localhost:{port}/{api-hostname}/{protocol}`
670
- - `{api-hostname}`: Your target API's hostname
671
- - `{protocol}`: Optional - `http` or `https` (defaults to `https`)
672
-
673
- ### Testing the Server
674
-
675
- ```bash
676
- # Check server health
677
- curl http://localhost:3001/health
678
-
679
- # Test MCP connection with hostname routing
680
- curl -X POST http://localhost:3001/api.example.com \
681
- -H "Content-Type: application/json" \
682
- -H "Authorization: Bearer your-api-token" \
683
- -H "Accept: application/json, text/event-stream" \
684
- -d '{
685
- "jsonrpc": "2.0",
686
- "id": 1,
687
- "method": "initialize",
688
- "params": {
689
- "protocolVersion": "2025-06-18",
690
- "capabilities": {},
691
- "clientInfo": {
692
- "name": "test-client",
693
- "version": "1.0.0"
694
- }
695
- }
696
- }'
697
- ```
698
-
699
- ## Next Steps
700
-
701
- ### Phase 3: Optimization & Polish
702
- - [ ] Improve token optimization (target 50-70% reduction)
703
- - [ ] Enhanced description generation with examples
704
- - [ ] Performance testing and optimization
705
- - [ ] Comprehensive test suite
706
- - [ ] Documentation and usage examples
707
-
708
- ### Phase 4: Production Readiness
709
- - [ ] Observability and monitoring integration
710
- - [ ] Error handling refinement
711
- - [ ] Validation accuracy testing
712
- - [ ] Production deployment configuration
713
- - [ ] Performance benchmarking
714
-
715
424
  ## Technology Stack
716
425
 
717
426
  ### Runtime
@@ -3,5 +3,5 @@
3
3
  "originalSize": 815026,
4
4
  "optimizedSize": 537657,
5
5
  "reductionPercent": 34.03,
6
- "buildDuration": 584
6
+ "buildDuration": 599
7
7
  }
@@ -32156,7 +32156,7 @@
32156
32156
  ],
32157
32157
  "info": {
32158
32158
  "title": "AMPECO.CHARGE Public API",
32159
- "version": "3.97.2",
32159
+ "version": "3.97.3",
32160
32160
  "description": "AMPECO.CHARGE Public API provides you with the option to use AMPECO.CHARGE's backend in a server-to-server manner\n"
32161
32161
  },
32162
32162
  "servers": [
@@ -32170,12 +32170,12 @@
32170
32170
  }
32171
32171
  }
32172
32172
  ],
32173
- "buildTimestamp": "2025-10-10T12:09:54.932Z",
32173
+ "buildTimestamp": "2025-10-10T13:15:02.845Z",
32174
32174
  "stats": {
32175
32175
  "totalEndpoints": 445,
32176
32176
  "originalSize": 815026,
32177
32177
  "optimizedSize": 537657,
32178
32178
  "reductionPercent": 34.03,
32179
- "buildDuration": 584
32179
+ "buildDuration": 599
32180
32180
  }
32181
32181
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampeco/public-api-mcp",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "MCP server that dynamically exposes the AMPECO.CHARGE Public API defined by an OpenAPI 3 specification",
5
5
  "type": "module",
6
6
  "main": "dist/cli/index.js",