@ampeco/public-api-mcp 0.2.0 → 0.3.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.
- package/README.md +258 -318
- package/dist/build/optimizer.d.ts.map +1 -1
- package/dist/build/optimizer.js +82 -21
- package/dist/build/optimizer.js.map +1 -1
- package/dist/build/parser.d.ts.map +1 -1
- package/dist/build/parser.js +74 -1
- package/dist/build/parser.js.map +1 -1
- package/dist/cli/index.js +25 -11
- package/dist/cli/index.js.map +1 -1
- package/dist/generated/build-stats.json +5 -5
- package/dist/generated/endpoints.json +29214 -20896
- package/dist/generated/schemas.d.ts +7530 -2789
- package/dist/generated/schemas.d.ts.map +1 -1
- package/dist/generated/schemas.js +1443 -590
- package/dist/generated/schemas.js.map +1 -1
- package/dist/generated/schemas.ts +1447 -596
- package/dist/server/factory.d.ts +2 -1
- package/dist/server/factory.d.ts.map +1 -1
- package/dist/server/factory.js +17 -206
- package/dist/server/factory.js.map +1 -1
- package/dist/server/factory.test.js +62 -4
- package/dist/server/factory.test.js.map +1 -1
- package/dist/server/http.d.ts +2 -1
- package/dist/server/http.d.ts.map +1 -1
- package/dist/server/http.js +8 -2
- package/dist/server/http.js.map +1 -1
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +9 -1388
- package/dist/server/index.js.map +1 -1
- package/dist/server/instructions.d.ts +13 -0
- package/dist/server/instructions.d.ts.map +1 -0
- package/dist/server/instructions.js +146 -0
- package/dist/server/instructions.js.map +1 -0
- package/dist/server/resources/handlers.d.ts +31 -0
- package/dist/server/resources/handlers.d.ts.map +1 -0
- package/dist/server/resources/handlers.js +113 -0
- package/dist/server/resources/handlers.js.map +1 -0
- package/dist/server/resources/handlers.test.d.ts +6 -0
- package/dist/server/resources/handlers.test.d.ts.map +1 -0
- package/dist/server/resources/handlers.test.js +203 -0
- package/dist/server/resources/handlers.test.js.map +1 -0
- package/dist/server/resources/native.d.ts +11 -0
- package/dist/server/resources/native.d.ts.map +1 -0
- package/dist/server/resources/native.js +31 -0
- package/dist/server/resources/native.js.map +1 -0
- package/dist/server/resources/tools.d.ts +11 -0
- package/dist/server/resources/tools.d.ts.map +1 -0
- package/dist/server/resources/tools.js +41 -0
- package/dist/server/resources/tools.js.map +1 -0
- package/dist/server/stdio.d.ts +2 -1
- package/dist/server/stdio.d.ts.map +1 -1
- package/dist/server/stdio.js +8 -2
- package/dist/server/stdio.js.map +1 -1
- package/dist/server/types.d.ts +36 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/server/types.js +6 -0
- package/dist/server/types.js.map +1 -0
- package/package.json +3 -2
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
|
|
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/
|
|
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
|
|
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,30 @@ OpenAPI Spec
|
|
|
181
101
|
Generated Artifacts (endpoints.json, schemas.ts)
|
|
182
102
|
```
|
|
183
103
|
|
|
184
|
-
###
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
|
104
|
+
### MCP Server
|
|
105
|
+
|
|
106
|
+
The server provides a complete MCP implementation for accessing your OpenAPI-defined API:
|
|
107
|
+
|
|
108
|
+
- **Dual Transport Support**: Both Stdio (local) and HTTP (remote) transports
|
|
109
|
+
- **Flexible Resource Mode**: Native MCP resources OR tool-based emulation for Claude Desktop compatibility
|
|
110
|
+
- **Dynamic Resources**: All API endpoints exposed as MCP resources with full schema details
|
|
111
|
+
- **API Request Tool**: Fully typed `api_request` tool with automatic authentication and parameter validation
|
|
112
|
+
- **Stateless Architecture**: No session state required - all parameters provided per request
|
|
113
|
+
- **Zero Configuration**: Pre-processed data loads instantly, no config files needed
|
|
114
|
+
- **MCP Protocol Compliance**: Full implementation of MCP Streamable HTTP transport specification
|
|
115
|
+
|
|
116
|
+
#### Resource Modes
|
|
117
|
+
|
|
118
|
+
The server supports two modes for exposing API endpoints:
|
|
119
|
+
|
|
120
|
+
1. **Native Resources Mode** (Default): Uses native MCP resources for endpoint discovery
|
|
121
|
+
- Best for: MCP clients that fully support the resources capability
|
|
122
|
+
- Features: Hierarchical 3-tier navigation (tags → endpoints → details)
|
|
123
|
+
|
|
124
|
+
2. **Tool Emulation Mode**: Exposes resources through tools (`list_resources`, `read_resource`)
|
|
125
|
+
- **Required for Claude Desktop** (does not support native MCP resources)
|
|
126
|
+
- Provides identical functionality through tool-based interface
|
|
127
|
+
- Enable with `--emulate-resources-via-tools` flag
|
|
293
128
|
|
|
294
129
|
### Running the Server
|
|
295
130
|
|
|
@@ -318,7 +153,161 @@ The server uses a hostname-based routing structure where the target API hostname
|
|
|
318
153
|
- `POST /api.example.com` → Routes to `https://api.example.com`
|
|
319
154
|
- `POST /api.example.com/https` → Routes to `https://api.example.com`
|
|
320
155
|
- `POST /api.example.com/http` → Routes to `http://api.example.com`
|
|
321
|
-
- `POST /
|
|
156
|
+
- `POST /internal.api.company.com/http` → Routes to `http://internal.api.company.com`
|
|
157
|
+
|
|
158
|
+
## Setting Up with Claude Desktop
|
|
159
|
+
|
|
160
|
+
**IMPORTANT**: Claude Desktop **does not support native MCP resources**. You **MUST** use the `--emulate-resources-via-tools` flag for Claude Desktop.
|
|
161
|
+
|
|
162
|
+
### Claude Desktop Configuration
|
|
163
|
+
|
|
164
|
+
Claude Desktop uses a configuration file called `claude_desktop_config.json` located at:
|
|
165
|
+
|
|
166
|
+
- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
167
|
+
- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
168
|
+
|
|
169
|
+
You can also access this file through Claude Desktop: **Settings** → **Developer** → **Edit Config**
|
|
170
|
+
|
|
171
|
+
### Configuration Example
|
|
172
|
+
|
|
173
|
+
Add this to your `claude_desktop_config.json`:
|
|
174
|
+
|
|
175
|
+
```json
|
|
176
|
+
{
|
|
177
|
+
"mcpServers": {
|
|
178
|
+
"ampeco-api": {
|
|
179
|
+
"command": "npx",
|
|
180
|
+
"args": [
|
|
181
|
+
"-y",
|
|
182
|
+
"@ampeco/public-api-mcp",
|
|
183
|
+
"--stdio",
|
|
184
|
+
"--hostname",
|
|
185
|
+
"https://api.example.com",
|
|
186
|
+
"--emulate-resources-via-tools"
|
|
187
|
+
],
|
|
188
|
+
"env": {
|
|
189
|
+
"AMPECO_BEARER_TOKEN": "your-token-here"
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
**Replace**:
|
|
197
|
+
- `https://api.example.com` with your actual API hostname
|
|
198
|
+
- `your-token-here` with your bearer token
|
|
199
|
+
|
|
200
|
+
**After editing the file**, restart Claude Desktop for changes to take effect
|
|
201
|
+
|
|
202
|
+
### What is Tool Emulation Mode?
|
|
203
|
+
|
|
204
|
+
When `--emulate-resources-via-tools` is enabled, the server provides two additional tools:
|
|
205
|
+
|
|
206
|
+
1. **`list_resources`**: Discover available API tags (e.g., Users, ChargingSessions)
|
|
207
|
+
- No parameters required
|
|
208
|
+
- Returns list of tags that group related endpoints
|
|
209
|
+
|
|
210
|
+
2. **`read_resource`**: Read endpoint definitions by URI
|
|
211
|
+
- Parameter: `uri` (e.g., `tag://Users` or `api://GET/users/{id}`)
|
|
212
|
+
- Returns full endpoint specification
|
|
213
|
+
|
|
214
|
+
These tools provide **identical functionality** to native MCP resources but work through the tools interface that Claude Desktop supports.
|
|
215
|
+
|
|
216
|
+
### Tool Schemas (Emulation Mode)
|
|
217
|
+
|
|
218
|
+
When `--emulate-resources-via-tools` is enabled, the following tools are available:
|
|
219
|
+
|
|
220
|
+
#### `list_resources` Tool
|
|
221
|
+
|
|
222
|
+
**Description**: List all available API tags. This emulates the native MCP resources/list functionality. Returns a list of tags that group related endpoints together (e.g., Users, ChargingSessions, Connectors). Each tag can then be read using the read_resource tool with tag:// URIs.
|
|
223
|
+
|
|
224
|
+
**Parameters**: None
|
|
225
|
+
|
|
226
|
+
**Returns**: JSON object with `resources` array containing:
|
|
227
|
+
```json
|
|
228
|
+
{
|
|
229
|
+
"resources": [
|
|
230
|
+
{
|
|
231
|
+
"uri": "tag://Users",
|
|
232
|
+
"name": "Users",
|
|
233
|
+
"description": "15 endpoints tagged with 'Users'",
|
|
234
|
+
"mimeType": "application/json"
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
"uri": "tag://ChargingSessions",
|
|
238
|
+
"name": "ChargingSessions",
|
|
239
|
+
"description": "8 endpoints tagged with 'ChargingSessions'",
|
|
240
|
+
"mimeType": "application/json"
|
|
241
|
+
}
|
|
242
|
+
]
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
**Example Usage**:
|
|
247
|
+
```
|
|
248
|
+
Call list_resources tool → Get list of all API tags
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
#### `read_resource` Tool
|
|
252
|
+
|
|
253
|
+
**Description**: Read a specific resource by URI. This emulates the native MCP resources/read functionality. Supports two URI formats: tag://{TagName} to read all endpoints within a tag, and api://{METHOD}{path} to read detailed endpoint specifications. You MUST use this tool to read endpoint definitions before calling api_request.
|
|
254
|
+
|
|
255
|
+
**Parameters**:
|
|
256
|
+
- `uri` (string, required): The resource URI to read
|
|
257
|
+
- Format: `tag://{TagName}` or `api://{METHOD}{path}`
|
|
258
|
+
- Examples: `"tag://Users"`, `"api://GET/users/{id}"`, `"api://POST/charging-sessions"`
|
|
259
|
+
|
|
260
|
+
**Returns** (for tag URIs):
|
|
261
|
+
```json
|
|
262
|
+
{
|
|
263
|
+
"tag": "Users",
|
|
264
|
+
"count": 15,
|
|
265
|
+
"endpoints": [
|
|
266
|
+
{
|
|
267
|
+
"uri": "api://GET/users/{id}",
|
|
268
|
+
"method": "GET",
|
|
269
|
+
"path": "/users/{id}",
|
|
270
|
+
"summary": "Get user by ID",
|
|
271
|
+
"operationId": "getUser"
|
|
272
|
+
}
|
|
273
|
+
]
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
**Returns** (for api URIs):
|
|
278
|
+
```json
|
|
279
|
+
{
|
|
280
|
+
"path": "/users/{id}",
|
|
281
|
+
"method": "GET",
|
|
282
|
+
"operationId": "getUser",
|
|
283
|
+
"summary": "Get user by ID",
|
|
284
|
+
"description": "Retrieves detailed information about a specific user",
|
|
285
|
+
"parameters": [...],
|
|
286
|
+
"requestBody": {...},
|
|
287
|
+
"responses": {...},
|
|
288
|
+
"security": "Include token in Authorization header as: Authorization: Bearer <token>"
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
**Example Usage**:
|
|
293
|
+
```
|
|
294
|
+
1. Call read_resource with uri="tag://Users" → Get all endpoints in Users tag
|
|
295
|
+
2. Call read_resource with uri="api://GET/users/{id}" → Get full endpoint specification
|
|
296
|
+
3. Call api_request with correct parameters → Make the actual API call
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### When to Use Each Mode
|
|
300
|
+
|
|
301
|
+
| Mode | Use For | Clients |
|
|
302
|
+
|------|---------|---------|
|
|
303
|
+
| **Native Resources** (default) | MCP clients that fully support resources | **Claude Code**, MCP Inspector |
|
|
304
|
+
| **Tool Emulation** (`--emulate-resources-via-tools`) | Clients without resource support | **Claude Desktop** |
|
|
305
|
+
|
|
306
|
+
**Important Distinction**:
|
|
307
|
+
- **Claude Code** (the CLI tool): Supports native MCP resources - use **default mode**
|
|
308
|
+
- **Claude Desktop** (the desktop app): Does NOT support resources - use **`--emulate-resources-via-tools`**
|
|
309
|
+
|
|
310
|
+
**Rule of thumb**: If you're using **Claude Desktop**, always add `--emulate-resources-via-tools`. If using **Claude Code**, use default mode.
|
|
322
311
|
|
|
323
312
|
## Setting Up with Claude Code
|
|
324
313
|
|
|
@@ -382,25 +371,32 @@ For production use without needing the source code:
|
|
|
382
371
|
#### Option 1: One-Liner (Recommended)
|
|
383
372
|
|
|
384
373
|
```bash
|
|
385
|
-
# Add production server with a single command
|
|
374
|
+
# Add production server with a single command (native resources)
|
|
386
375
|
claude mcp add --transport stdio ampeco-api \
|
|
387
376
|
--env AMPECO_BEARER_TOKEN=your-token-here \
|
|
388
|
-
-- npx -y @ampeco/public-api-mcp --stdio --hostname
|
|
377
|
+
-- npx -y @ampeco/public-api-mcp --stdio --hostname https://api.example.com
|
|
378
|
+
|
|
379
|
+
# With tool emulation mode (if client doesn't support resources)
|
|
380
|
+
claude mcp add --transport stdio ampeco-api \
|
|
381
|
+
--env AMPECO_BEARER_TOKEN=your-token-here \
|
|
382
|
+
-- npx -y @ampeco/public-api-mcp --stdio --hostname https://api.example.com --emulate-resources-via-tools
|
|
389
383
|
```
|
|
390
384
|
|
|
391
385
|
**Replace**:
|
|
392
386
|
- `your-token-here` with your API token
|
|
393
|
-
- `
|
|
387
|
+
- `https://api.example.com` with your target API hostname
|
|
394
388
|
|
|
395
389
|
**Features**:
|
|
396
390
|
- NPX downloads and caches the package automatically
|
|
397
391
|
- No source code or build required
|
|
398
392
|
- Works from any directory
|
|
393
|
+
- Add `--emulate-resources-via-tools` for Claude Desktop compatibility
|
|
399
394
|
|
|
400
395
|
#### Option 2: Manual Configuration
|
|
401
396
|
|
|
402
397
|
Create `.mcp.json` in your project or home directory:
|
|
403
398
|
|
|
399
|
+
**Native Resources Mode**:
|
|
404
400
|
```json
|
|
405
401
|
{
|
|
406
402
|
"mcpServers": {
|
|
@@ -412,7 +408,30 @@ Create `.mcp.json` in your project or home directory:
|
|
|
412
408
|
"@ampeco/public-api-mcp",
|
|
413
409
|
"--stdio",
|
|
414
410
|
"--hostname",
|
|
415
|
-
"
|
|
411
|
+
"https://api.example.com"
|
|
412
|
+
],
|
|
413
|
+
"env": {
|
|
414
|
+
"AMPECO_BEARER_TOKEN": "your-token-here"
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
**Tool Emulation Mode** (for Claude Desktop):
|
|
422
|
+
```json
|
|
423
|
+
{
|
|
424
|
+
"mcpServers": {
|
|
425
|
+
"ampeco-api": {
|
|
426
|
+
"type": "stdio",
|
|
427
|
+
"command": "npx",
|
|
428
|
+
"args": [
|
|
429
|
+
"-y",
|
|
430
|
+
"@ampeco/public-api-mcp",
|
|
431
|
+
"--stdio",
|
|
432
|
+
"--hostname",
|
|
433
|
+
"https://api.example.com",
|
|
434
|
+
"--emulate-resources-via-tools"
|
|
416
435
|
],
|
|
417
436
|
"env": {
|
|
418
437
|
"AMPECO_BEARER_TOKEN": "your-token-here"
|
|
@@ -442,20 +461,46 @@ npm install -g @ampeco/public-api-mcp
|
|
|
442
461
|
#### 2. Add to Claude Code (One-Liner)
|
|
443
462
|
|
|
444
463
|
```bash
|
|
445
|
-
# Add globally installed server
|
|
464
|
+
# Add globally installed server (native resources)
|
|
465
|
+
claude mcp add --transport stdio ampeco-api \
|
|
466
|
+
--env AMPECO_BEARER_TOKEN=your-token-here \
|
|
467
|
+
-- ampeco-api-mcp --stdio --hostname https://api.example.com
|
|
468
|
+
|
|
469
|
+
# With tool emulation mode (for Claude Desktop)
|
|
446
470
|
claude mcp add --transport stdio ampeco-api \
|
|
447
471
|
--env AMPECO_BEARER_TOKEN=your-token-here \
|
|
448
|
-
-- ampeco-api-mcp --stdio --hostname
|
|
472
|
+
-- ampeco-api-mcp --stdio --hostname https://api.example.com --emulate-resources-via-tools
|
|
449
473
|
```
|
|
450
474
|
|
|
451
475
|
**Or manual configuration** in `.mcp.json`:
|
|
476
|
+
|
|
477
|
+
**Native Resources Mode**:
|
|
452
478
|
```json
|
|
453
479
|
{
|
|
454
480
|
"mcpServers": {
|
|
455
481
|
"ampeco-api": {
|
|
456
482
|
"type": "stdio",
|
|
457
483
|
"command": "ampeco-api-mcp",
|
|
458
|
-
"args": ["--stdio", "--hostname", "
|
|
484
|
+
"args": ["--stdio", "--hostname", "https://api.example.com"],
|
|
485
|
+
"env": {"AMPECO_BEARER_TOKEN": "your-token-here"}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
**Tool Emulation Mode** (for Claude Desktop):
|
|
492
|
+
```json
|
|
493
|
+
{
|
|
494
|
+
"mcpServers": {
|
|
495
|
+
"ampeco-api": {
|
|
496
|
+
"type": "stdio",
|
|
497
|
+
"command": "ampeco-api-mcp",
|
|
498
|
+
"args": [
|
|
499
|
+
"--stdio",
|
|
500
|
+
"--hostname",
|
|
501
|
+
"https://api.example.com",
|
|
502
|
+
"--emulate-resources-via-tools"
|
|
503
|
+
],
|
|
459
504
|
"env": {"AMPECO_BEARER_TOKEN": "your-token-here"}
|
|
460
505
|
}
|
|
461
506
|
}
|
|
@@ -469,12 +514,19 @@ For shared server access or when multiple clients need to connect:
|
|
|
469
514
|
#### 1. Start the Server
|
|
470
515
|
|
|
471
516
|
```bash
|
|
472
|
-
# Development mode
|
|
517
|
+
# Development mode (native resources)
|
|
473
518
|
PORT=3001 npm run dev:http
|
|
474
519
|
|
|
475
|
-
#
|
|
520
|
+
# Development mode (tool emulation)
|
|
521
|
+
PORT=3001 npm start -- --http --port 3001 --emulate-resources-via-tools
|
|
522
|
+
|
|
523
|
+
# Production mode (native resources)
|
|
476
524
|
npm run build # First time only
|
|
477
525
|
PORT=3001 npm start -- --http --port 3001
|
|
526
|
+
|
|
527
|
+
# Production mode (tool emulation)
|
|
528
|
+
npm run build # First time only
|
|
529
|
+
PORT=3001 npm start -- --http --port 3001 --emulate-resources-via-tools
|
|
478
530
|
```
|
|
479
531
|
|
|
480
532
|
#### 2. Add to Claude Code (One-Liner)
|
|
@@ -482,14 +534,14 @@ PORT=3001 npm start -- --http --port 3001
|
|
|
482
534
|
```bash
|
|
483
535
|
# Add HTTP server with a single command
|
|
484
536
|
claude mcp add --transport http ampeco-api \
|
|
485
|
-
http://localhost:3001/
|
|
537
|
+
http://localhost:3001/api.example.com \
|
|
486
538
|
--header "Authorization: Bearer your-token-here"
|
|
487
539
|
```
|
|
488
540
|
|
|
489
541
|
**With protocol override** (use HTTP for target API instead of HTTPS):
|
|
490
542
|
```bash
|
|
491
543
|
claude mcp add --transport http ampeco-api \
|
|
492
|
-
http://localhost:3001/
|
|
544
|
+
http://localhost:3001/api.example.com/http \
|
|
493
545
|
--header "Authorization: Bearer your-token-here"
|
|
494
546
|
```
|
|
495
547
|
|
|
@@ -499,7 +551,7 @@ claude mcp add --transport http ampeco-api \
|
|
|
499
551
|
"mcpServers": {
|
|
500
552
|
"ampeco-api-http": {
|
|
501
553
|
"type": "http",
|
|
502
|
-
"url": "http://localhost:3001/
|
|
554
|
+
"url": "http://localhost:3001/api.example.com",
|
|
503
555
|
"headers": {"Authorization": "Bearer your-token-here"}
|
|
504
556
|
}
|
|
505
557
|
}
|
|
@@ -526,23 +578,6 @@ claude mcp add --transport http ampeco-api \
|
|
|
526
578
|
|
|
527
579
|
**Recommendation**: Use **stdio mode** for development and single-user production. Use **HTTP mode** for shared servers or when multiple clients need concurrent access.
|
|
528
580
|
|
|
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
581
|
### Troubleshooting
|
|
547
582
|
|
|
548
583
|
#### Stdio Mode Issues
|
|
@@ -614,104 +649,9 @@ npm run build
|
|
|
614
649
|
- Test the token directly with the API:
|
|
615
650
|
```bash
|
|
616
651
|
curl -H "Authorization: Bearer your-token" \
|
|
617
|
-
|
|
652
|
+
https://api.example.com/health
|
|
618
653
|
```
|
|
619
654
|
|
|
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
655
|
## Technology Stack
|
|
716
656
|
|
|
717
657
|
### Runtime
|