@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
package/README.md ADDED
@@ -0,0 +1,734 @@
1
+ # Public API MCP Server
2
+
3
+ An MCP (Model Context Protocol) server that dynamically exposes a public API defined by an OpenAPI 3 specification.
4
+
5
+ ## Quick Start
6
+
7
+ ### Development (Stdio Mode)
8
+
9
+ ```bash
10
+ # One-liner to add dev server (with hot reload)
11
+ claude mcp add --transport stdio ampeco-api-dev \
12
+ --env AMPECO_BEARER_TOKEN=your-token-here \
13
+ -- bash -c "cd /absolute/path/to/public-api-mcp && npm run dev:stdio"
14
+ ```
15
+
16
+ ### Production (via NPX)
17
+
18
+ ```bash
19
+ # One-liner to add production server
20
+ claude mcp add --transport stdio ampeco-api \
21
+ --env AMPECO_BEARER_TOKEN=your-token-here \
22
+ -- npx -y @ampeco/public-api-mcp --stdio --hostname http://demo.charge.alex2.dev.ampeco.tech
23
+ ```
24
+
25
+ ### HTTP Mode (Remote Server)
26
+
27
+ ```bash
28
+ # Start the server first
29
+ PORT=3001 npm run dev:http
30
+
31
+ # Then add to Claude Code
32
+ claude mcp add --transport http ampeco-api \
33
+ http://localhost:3001/demo.charge.alex2.dev.ampeco.tech \
34
+ --header "Authorization: Bearer your-token-here"
35
+ ```
36
+
37
+ See [Setting Up with Claude Code](#setting-up-with-claude-code) for detailed instructions and troubleshooting.
38
+
39
+ ## Overview
40
+
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
+
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
+ ## Usage
121
+
122
+ ### Running the Build Pipeline
123
+
124
+ ```bash
125
+ # Install dependencies
126
+ npm install
127
+
128
+ # Run the build pipeline with default path
129
+ npm run build
130
+
131
+ # Run the build pipeline with custom OpenAPI spec path
132
+ OPENAPI_SPEC_PATH=/path/to/your/openapi.yaml npm run build
133
+
134
+ # Or set it as an environment variable for multiple commands
135
+ export OPENAPI_SPEC_PATH=/path/to/your/openapi.yaml
136
+ npm run build
137
+ npm run dev
138
+ ```
139
+
140
+ The build script:
141
+ 1. Parses the OpenAPI spec from the specified path (defaults to `../backend/main/docs/public.yaml`)
142
+ 2. Processes all endpoints through the optimization pipeline
143
+ 3. Generates Zod schemas for runtime validation
144
+ 4. Outputs optimized artifacts to `src/generated/`
145
+
146
+ **Configuration Options:**
147
+ - **`OPENAPI_SPEC_PATH`**: Path to the OpenAPI YAML/JSON file (relative or absolute)
148
+ - Default: `../backend/main/docs/public.yaml`
149
+ - Can be set as an environment variable or passed directly to npm commands
150
+ - Used by both `npm run build` and `npm run dev`
151
+
152
+ ### Development
153
+
154
+ ```bash
155
+ # Type check without building
156
+ npm run type-check
157
+
158
+ # Run in development mode (build + start server)
159
+ npm run dev
160
+ ```
161
+
162
+ ## Architecture
163
+
164
+ ### Build-Time Pipeline
165
+
166
+ ```
167
+ OpenAPI Spec
168
+
169
+ [Parser] Bundle & Resolve References
170
+
171
+ [Extractor] Extract Endpoints & Security
172
+
173
+ [Flattener] Flatten Schemas (allOf, nested objects)
174
+
175
+ [Security] Embed Authentication Details
176
+
177
+ [Optimizer] Minify & Optimize
178
+
179
+ [Zod Generator] Generate Validation Schemas
180
+
181
+ Generated Artifacts (endpoints.json, schemas.ts)
182
+ ```
183
+
184
+ ### Module Structure
185
+
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`
256
+
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
293
+
294
+ ### Running the Server
295
+
296
+ ```bash
297
+ # Development mode (rebuild + start server)
298
+ npm run dev
299
+
300
+ # Production mode
301
+ npm run build # First time only
302
+ npm start
303
+
304
+ # Custom port
305
+ PORT=3001 npm run dev
306
+ ```
307
+
308
+ ### Server Endpoints
309
+
310
+ The server uses a hostname-based routing structure where the target API hostname is embedded in the URL path:
311
+
312
+ - **`GET /health`**: Health check and server statistics
313
+ - **`POST /{hostname}[/{protocol}]`**: MCP protocol endpoint with hostname routing
314
+ - `{hostname}`: Target API hostname (e.g., `api.example.com`)
315
+ - `{protocol}`: Optional protocol (`http` or `https`, defaults to `https`)
316
+
317
+ **Examples:**
318
+ - `POST /api.example.com` → Routes to `https://api.example.com`
319
+ - `POST /api.example.com/https` → Routes to `https://api.example.com`
320
+ - `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`
322
+
323
+ ## Setting Up with Claude Code
324
+
325
+ The MCP server supports two transport modes:
326
+
327
+ 1. **Stdio Mode (Recommended)**: Direct process communication for local development and production
328
+ 2. **HTTP Mode**: Remote server access via HTTP transport
329
+
330
+ ### Stdio Mode (Local Development)
331
+
332
+ For development with hot reloading and build integration:
333
+
334
+ #### Option 1: One-Liner (Recommended)
335
+
336
+ ```bash
337
+ # Add dev server with a single command
338
+ claude mcp add --transport stdio ampeco-api-dev \
339
+ --env AMPECO_BEARER_TOKEN=your-token-here \
340
+ -- bash -c "cd /absolute/path/to/public-api-mcp && npm run dev:stdio"
341
+ ```
342
+
343
+ **Replace**:
344
+ - `/absolute/path/to/public-api-mcp` with your actual project path
345
+ - `your-token-here` with your API token
346
+
347
+ **Features**:
348
+ - Automatically creates `.mcp.json` configuration
349
+ - Rebuilds on each start for hot reloading
350
+ - All build output redirected to stderr (clean protocol)
351
+
352
+ #### Option 2: Manual Configuration
353
+
354
+ If you prefer to manually edit configuration files:
355
+
356
+ 1. **Set environment variable** (optional, for substitution):
357
+ ```bash
358
+ export AMPECO_BEARER_TOKEN="your-token-here"
359
+ source ~/.bashrc # or ~/.zshrc
360
+ ```
361
+
362
+ 2. **Create `.mcp.json` in project root**:
363
+ ```json
364
+ {
365
+ "mcpServers": {
366
+ "ampeco-api-dev": {
367
+ "type": "stdio",
368
+ "command": "bash",
369
+ "args": ["-c", "cd /absolute/path/to/public-api-mcp && npm run dev:stdio"],
370
+ "env": {"AMPECO_BEARER_TOKEN": "${AMPECO_BEARER_TOKEN}"}
371
+ }
372
+ }
373
+ }
374
+ ```
375
+
376
+ 3. **Reload**: Claude Code will auto-detect the configuration
377
+
378
+ ### Stdio Mode (Production via NPX)
379
+
380
+ For production use without needing the source code:
381
+
382
+ #### Option 1: One-Liner (Recommended)
383
+
384
+ ```bash
385
+ # Add production server with a single command
386
+ claude mcp add --transport stdio ampeco-api \
387
+ --env AMPECO_BEARER_TOKEN=your-token-here \
388
+ -- npx -y @ampeco/public-api-mcp --stdio --hostname http://demo.charge.alex2.dev.ampeco.tech
389
+ ```
390
+
391
+ **Replace**:
392
+ - `your-token-here` with your API token
393
+ - `http://demo.charge.alex2.dev.ampeco.tech` with your target API hostname
394
+
395
+ **Features**:
396
+ - NPX downloads and caches the package automatically
397
+ - No source code or build required
398
+ - Works from any directory
399
+
400
+ #### Option 2: Manual Configuration
401
+
402
+ Create `.mcp.json` in your project or home directory:
403
+
404
+ ```json
405
+ {
406
+ "mcpServers": {
407
+ "ampeco-api": {
408
+ "type": "stdio",
409
+ "command": "npx",
410
+ "args": [
411
+ "-y",
412
+ "@ampeco/public-api-mcp",
413
+ "--stdio",
414
+ "--hostname",
415
+ "http://demo.charge.alex2.dev.ampeco.tech"
416
+ ],
417
+ "env": {
418
+ "AMPECO_BEARER_TOKEN": "your-token-here"
419
+ }
420
+ }
421
+ }
422
+ }
423
+ ```
424
+
425
+ **Using environment variables** (more secure):
426
+ ```bash
427
+ export AMPECO_BEARER_TOKEN="your-token-here"
428
+ ```
429
+
430
+ Then use `"${AMPECO_BEARER_TOKEN}"` in the JSON config.
431
+
432
+ ### Stdio Mode (Production via Global Install)
433
+
434
+ For faster startup without NPX overhead:
435
+
436
+ #### 1. Install Globally
437
+
438
+ ```bash
439
+ npm install -g @ampeco/public-api-mcp
440
+ ```
441
+
442
+ #### 2. Add to Claude Code (One-Liner)
443
+
444
+ ```bash
445
+ # Add globally installed server
446
+ claude mcp add --transport stdio ampeco-api \
447
+ --env AMPECO_BEARER_TOKEN=your-token-here \
448
+ -- ampeco-api-mcp --stdio --hostname http://demo.charge.alex2.dev.ampeco.tech
449
+ ```
450
+
451
+ **Or manual configuration** in `.mcp.json`:
452
+ ```json
453
+ {
454
+ "mcpServers": {
455
+ "ampeco-api": {
456
+ "type": "stdio",
457
+ "command": "ampeco-api-mcp",
458
+ "args": ["--stdio", "--hostname", "http://demo.charge.alex2.dev.ampeco.tech"],
459
+ "env": {"AMPECO_BEARER_TOKEN": "your-token-here"}
460
+ }
461
+ }
462
+ }
463
+ ```
464
+
465
+ ### HTTP Mode (Remote Server)
466
+
467
+ For shared server access or when multiple clients need to connect:
468
+
469
+ #### 1. Start the Server
470
+
471
+ ```bash
472
+ # Development mode
473
+ PORT=3001 npm run dev:http
474
+
475
+ # Production mode
476
+ npm run build # First time only
477
+ PORT=3001 npm start -- --http --port 3001
478
+ ```
479
+
480
+ #### 2. Add to Claude Code (One-Liner)
481
+
482
+ ```bash
483
+ # Add HTTP server with a single command
484
+ claude mcp add --transport http ampeco-api \
485
+ http://localhost:3001/demo.charge.alex2.dev.ampeco.tech \
486
+ --header "Authorization: Bearer your-token-here"
487
+ ```
488
+
489
+ **With protocol override** (use HTTP for target API instead of HTTPS):
490
+ ```bash
491
+ claude mcp add --transport http ampeco-api \
492
+ http://localhost:3001/demo.charge.alex2.dev.ampeco.tech/http \
493
+ --header "Authorization: Bearer your-token-here"
494
+ ```
495
+
496
+ **Or manual configuration** in `.mcp.json`:
497
+ ```json
498
+ {
499
+ "mcpServers": {
500
+ "ampeco-api-http": {
501
+ "type": "http",
502
+ "url": "http://localhost:3001/demo.charge.alex2.dev.ampeco.tech",
503
+ "headers": {"Authorization": "Bearer your-token-here"}
504
+ }
505
+ }
506
+ }
507
+ ```
508
+
509
+ **Notes:**
510
+ - Server must be running before connecting
511
+ - Target API hostname is in the URL path
512
+ - Optional `/http` or `/https` suffix controls target API protocol
513
+ - Defaults to HTTPS if not specified
514
+
515
+ ### Comparison: Stdio vs HTTP Mode
516
+
517
+ | Feature | Stdio Mode | HTTP Mode |
518
+ |---------|-----------|-----------|
519
+ | **Use Case** | Local development, single user | Remote access, multiple clients |
520
+ | **Setup Complexity** | Simple (just config file) | Requires running server |
521
+ | **Performance** | Faster (no HTTP overhead) | Slightly slower (HTTP latency) |
522
+ | **Security** | More secure (local only) | Network exposure (use HTTPS in prod) |
523
+ | **Hot Reload** | Yes (dev mode) | Requires server restart |
524
+ | **Multi-Client** | No (one client at a time) | Yes (concurrent clients) |
525
+ | **Memory Usage** | Lower (~30MB per instance) | Higher (~50MB + per-request) |
526
+
527
+ **Recommendation**: Use **stdio mode** for development and single-user production. Use **HTTP mode** for shared servers or when multiple clients need concurrent access.
528
+
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
+ ### Troubleshooting
547
+
548
+ #### Stdio Mode Issues
549
+
550
+ **Problem**: Server not starting or connection fails
551
+ ```bash
552
+ # List configured MCP servers
553
+ claude mcp list
554
+
555
+ # Check status
556
+ claude mcp status ampeco-api-dev
557
+
558
+ # Remove and re-add the server
559
+ claude mcp remove ampeco-api-dev
560
+ claude mcp add --transport stdio ampeco-api-dev \
561
+ --env AMPECO_BEARER_TOKEN=your-token \
562
+ -- bash -c "cd /path/to/public-api-mcp && npm run dev:stdio"
563
+
564
+ # Verify the command works standalone
565
+ cd /path/to/public-api-mcp
566
+ AMPECO_BEARER_TOKEN=your-token npm run dev:stdio
567
+ ```
568
+
569
+ **Problem**: Build output interfering with protocol
570
+ - This is fixed in `dev:stdio` script which redirects build output to stderr
571
+ - For production, run `npm run build` first, then use the compiled CLI
572
+
573
+ **Problem**: Environment variables not loading
574
+ ```bash
575
+ # Verify environment variable is set
576
+ echo $AMPECO_BEARER_TOKEN
577
+
578
+ # Reload shell configuration
579
+ source ~/.bashrc # or ~/.zshrc
580
+ ```
581
+
582
+ #### HTTP Mode Issues
583
+
584
+ **Problem**: Server not accessible
585
+ ```bash
586
+ # Test server health
587
+ curl http://localhost:3001/health
588
+
589
+ # Check if port is in use
590
+ lsof -i :3001
591
+
592
+ # Try a different port
593
+ PORT=3002 npm run dev:http
594
+ ```
595
+
596
+ **Problem**: CORS errors
597
+ - The server has CORS enabled for all origins
598
+ - Check browser console for specific error messages
599
+
600
+ #### General Issues
601
+
602
+ **Problem**: Endpoints not loading
603
+ ```bash
604
+ # Verify build artifacts exist
605
+ ls -la src/generated/
606
+
607
+ # Rebuild if needed
608
+ npm run build
609
+ ```
610
+
611
+ **Problem**: Authentication errors
612
+ - Verify your `AMPECO_BEARER_TOKEN` is correct
613
+ - Check the token has proper permissions for the API
614
+ - Test the token directly with the API:
615
+ ```bash
616
+ curl -H "Authorization: Bearer your-token" \
617
+ http://demo.charge.alex2.dev.ampeco.tech/health
618
+ ```
619
+
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
+ ## Technology Stack
716
+
717
+ ### Runtime
718
+ - **Language**: TypeScript / Node.js (ES2022 modules)
719
+ - **Server**: Express
720
+ - **MCP SDK**: `@modelcontextprotocol/sdk`
721
+ - **HTTP Client**: `node-fetch`
722
+ - **Validation**: `zod`
723
+
724
+ ### Build-Time
725
+ - **OpenAPI Parser**: `@readme/openapi-parser`
726
+ - **Build Tools**: tsx, TypeScript compiler
727
+
728
+ ### Development
729
+ - **Type Checking**: TypeScript (strict mode)
730
+ - **Testing**: Vitest (planned)
731
+
732
+ ## License
733
+
734
+ MIT