mrapids 0.1.31

Your OpenAPI, but executable
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
# Managing Multiple APIs with MCP Agent

When you have many API specs (Stripe, GitHub, Calendar, Internal APIs, etc.), here are the best approaches:

## Approach 1: Separate Agents (Recommended for 2-10 APIs)

Each API gets its own agent instance on different ports:

### Directory Structure
```
~/.mrapids-apis/
├── github/
│   ├── mcp-server.toml
│   ├── api.yaml
│   └── policy.yaml
├── stripe/
│   ├── mcp-server.toml
│   ├── api.yaml
│   └── policy.yaml
├── calendar/
│   ├── mcp-server.toml
│   ├── api.yaml
│   └── policy.yaml
└── internal/
    ├── mcp-server.toml
    ├── api.yaml
    └── policy.yaml
```

### Claude Configuration
```json
{
  "mcpServers": {
    "github": {
      "command": "mrapids-agent",
      "args": ["start", "--port", "8080", "--config-dir", "~/.mrapids-apis/github"],
      "env": { "GITHUB_TOKEN": "${GITHUB_TOKEN}" }
    },
    "stripe": {
      "command": "mrapids-agent",
      "args": ["start", "--port", "8081", "--config-dir", "~/.mrapids-apis/stripe"],
      "env": { "STRIPE_API_KEY": "${STRIPE_API_KEY}" }
    },
    "calendar": {
      "command": "mrapids-agent",
      "args": ["start", "--port", "8082", "--config-dir", "~/.mrapids-apis/calendar"],
      "env": { "CALENDAR_API_KEY": "${CALENDAR_API_KEY}" }
    },
    "internal": {
      "command": "mrapids-agent",
      "args": ["start", "--port", "8083", "--config-dir", "~/.mrapids-apis/internal"],
      "env": { "INTERNAL_API_KEY": "${INTERNAL_API_KEY}" }
    }
  }
}
```

**Pros**: 
- Isolated policies per API
- Independent scaling
- Clear separation

**Cons**:
- Multiple processes
- More ports to manage

## Approach 2: Unified Spec (Future Feature)

Combine multiple OpenAPI specs into one mega-spec:

### Directory Structure
```
~/.mrapids-unified/
├── mcp-server.toml
├── unified-api.yaml    # Combined spec
├── policy.yaml         # Unified policies
└── specs/              # Original specs
    ├── github.yaml
    ├── stripe.yaml
    ├── calendar.yaml
    └── internal.yaml
```

### Generate Unified Spec
```bash
# Future command
mrapids-agent merge-specs \
  --input specs/*.yaml \
  --output unified-api.yaml \
  --prefix-operations
```

### Result in unified-api.yaml
```yaml
openapi: "3.0.0"
info:
  title: "Unified API Gateway"
paths:
  # GitHub paths
  /github/repos/{owner}/{repo}:
    get:
      operationId: github_getRepository
      
  # Stripe paths  
  /stripe/customers/{id}:
    get:
      operationId: stripe_getCustomer
      
  # Calendar paths
  /calendar/events:
    get:
      operationId: calendar_listEvents
```

### Claude Configuration
```json
{
  "mcpServers": {
    "unified-apis": {
      "command": "mrapids-agent",
      "args": ["start", "--port", "8080", "--config-dir", "~/.mrapids-unified"],
      "env": {
        "GITHUB_TOKEN": "${GITHUB_TOKEN}",
        "STRIPE_API_KEY": "${STRIPE_API_KEY}",
        "CALENDAR_API_KEY": "${CALENDAR_API_KEY}"
      }
    }
  }
}
```

## Approach 3: Dynamic API Loading (Enterprise)

For many APIs, use dynamic configuration:

### Directory Structure
```
~/.mrapids-dynamic/
├── mcp-server.toml
├── apis/
│   ├── github/
│   │   ├── spec.yaml
│   │   ├── policy.yaml
│   │   └── auth.toml
│   ├── stripe/
│   │   ├── spec.yaml
│   │   ├── policy.yaml
│   │   └── auth.toml
│   └── .../
└── registry.yaml
```

### Registry Configuration
```yaml
# registry.yaml
apis:
  - id: github
    name: "GitHub API"
    spec: apis/github/spec.yaml
    policy: apis/github/policy.yaml
    auth: apis/github/auth.toml
    tags: ["vcs", "development"]
    
  - id: stripe  
    name: "Stripe API"
    spec: apis/stripe/spec.yaml
    policy: apis/stripe/policy.yaml
    auth: apis/stripe/auth.toml
    tags: ["payment", "billing"]
    
  - id: calendar
    name: "Calendar API"
    spec: apis/calendar/spec.yaml
    policy: apis/calendar/policy.yaml
    auth: apis/calendar/auth.toml
    tags: ["productivity", "scheduling"]
```

### Enhanced MCP Server Config
```toml
# mcp-server.toml
[server]
mode = "dynamic"
registry = "registry.yaml"

[discovery]
enable_search = true
enable_tags = true
```

## Approach 4: API Gateway Pattern

Use MicroRapid as an API gateway with namespace routing:

### Setup Script
```bash
#!/bin/bash
# setup-multi-api.sh

# Create base directory
mkdir -p ~/.mrapids-gateway

# Create gateway configuration
cat > ~/.mrapids-gateway/gateway.yaml << EOF
version: "1.0"
routes:
  - prefix: /github
    spec: specs/github.yaml
    auth: github
    
  - prefix: /stripe
    spec: specs/stripe.yaml
    auth: stripe
    
  - prefix: /calendar
    spec: specs/calendar.yaml
    auth: calendar
EOF

# Start gateway agent
mrapids-agent start --mode gateway --config ~/.mrapids-gateway
```

## Best Practices for Multiple APIs

### 1. Naming Conventions
```
Operation IDs: {api}_{operation}
- github_listRepos
- stripe_createCustomer
- calendar_getEvents
```

### 2. Unified Policy Structure
```yaml
# policy.yaml
rules:
  # Global rules
  - name: "deny-all-deletes"
    pattern: "*"
    deny:
      methods: ["DELETE"]
      
  # API-specific rules
  - name: "github-readonly"
    pattern: "/github/*"
    allow:
      methods: ["GET"]
      
  - name: "stripe-limited"
    pattern: "/stripe/*"
    allow:
      operations: ["stripe_listCustomers", "stripe_getCustomer"]
```

### 3. Centralized Auth Management
```bash
# Create auth profile manager
~/.mrapids-auth/
├── profiles/
│   ├── github.toml
│   ├── stripe.toml
│   └── calendar.toml
└── vault.encrypted  # Future: encrypted storage
```

### 4. Batch Operations Script
```bash
#!/bin/bash
# manage-all-agents.sh

APIS="github stripe calendar internal"
BASE_PORT=8080

case "$1" in
  start)
    for api in $APIS; do
      echo "Starting $api agent on port $BASE_PORT"
      mrapids-agent start \
        --port $BASE_PORT \
        --config-dir ~/.mrapids-apis/$api \
        --daemon
      ((BASE_PORT++))
    done
    ;;
    
  stop)
    for api in $APIS; do
      mrapids-agent stop --config-dir ~/.mrapids-apis/$api
    done
    ;;
    
  status)
    for api in $APIS; do
      echo -n "$api: "
      mrapids-agent status --config-dir ~/.mrapids-apis/$api
    done
    ;;
esac
```

## Scaling Considerations

### For 2-5 APIs
- Use separate agents (Approach 1)
- Simple and isolated
- Easy to debug

### For 5-20 APIs  
- Consider unified spec (Approach 2)
- Or use dynamic loading (Approach 3)
- Better resource usage

### For 20+ APIs
- Implement gateway pattern (Approach 4)
- Consider service mesh
- Add caching layer

## Example: Complete Setup for 5 APIs

```bash
#!/bin/bash
# setup-my-apis.sh

# Create directory structure
mkdir -p ~/.mrapids-apis/{github,stripe,calendar,slack,jira}

# Initialize each API
for api in github stripe calendar slack jira; do
  cd ~/.mrapids-apis/$api
  
  # Download or copy spec
  case $api in
    github)
      curl -o api.yaml https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.yaml
      ;;
    stripe)
      curl -o api.yaml https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.yaml
      ;;
    *)
      echo "Add your $api spec to ~/.mrapids-apis/$api/api.yaml"
      ;;
  esac
  
  # Create config
  cat > mcp-server.toml << EOF
[server]
name = "$api"

[defaults]
spec_path = "api.yaml"
policy_file = "policy.yaml"
auth_profile = "$api"
EOF

  # Create policy
  cat > policy.yaml << EOF
version: "1.0"
metadata:
  api: "$api"
  
rules:
  - name: "allow-${api}-reads"
    pattern: "*"
    allow:
      methods: ["GET"]
EOF
done

# Create unified Claude config
cat > ~/claude-mcp-config.json << EOF
{
  "mcpServers": {
EOF

PORT=8080
for api in github stripe calendar slack jira; do
  cat >> ~/claude-mcp-config.json << EOF
    "$api": {
      "command": "mrapids-agent",
      "args": ["start", "--port", "$PORT", "--config-dir", "$HOME/.mrapids-apis/$api"],
      "env": {
        "$(echo $api | tr '[:lower:]' '[:upper:]')_TOKEN": "\${$(echo $api | tr '[:lower:]' '[:upper:]')_TOKEN}"
      }
    },
EOF
  ((PORT++))
done

# Close JSON
echo '  }' >> ~/claude-mcp-config.json
echo '}' >> ~/claude-mcp-config.json

echo "Setup complete! Copy ~/claude-mcp-config.json to Claude's config location"
```

## Future Enhancements

1. **API Discovery Service**
   ```bash
   mrapids-agent discover --scan ~/.apis/
   ```

2. **Unified Dashboard**
   ```bash
   mrapids-agent dashboard --port 9000
   ```

3. **Smart Routing**
   - Auto-detect which API to use based on request
   - Load balance between similar APIs

4. **API Composition**
   - Combine multiple API calls
   - Create virtual endpoints

This gives users flexibility to scale from a few APIs to dozens, with appropriate patterns for each scale.