code-engine-mcp-server 1.0.4 → 1.0.6

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.
@@ -1,594 +0,0 @@
1
- # Code Engine API Call Scenarios
2
-
3
- **Author:** Markus van Kempen | markus.van.kempen@gmail.com
4
- **Research | Floor 7½ 🏢🤏**
5
-
6
- This document provides specific API call scenarios that Bob can execute through MCP tools. Each scenario includes the exact curl commands and expected responses.
7
-
8
- ---
9
-
10
- ## Scenario 1: Deploy Application to Toronto
11
-
12
- **Goal:** Deploy MarkusAppV2 to Toronto region with public image
13
-
14
- ### Step 1: Get IAM Token
15
-
16
- ```bash
17
- curl -X POST https://iam.cloud.ibm.com/identity/token \
18
- -H "Content-Type: application/x-www-form-urlencoded" \
19
- -d "grant_type=urn:ibm:params:oauth:grant-type:apikey&apikey=$IBMCLOUD_API_KEY"
20
- ```
21
-
22
- **Expected Response:**
23
- ```json
24
- {
25
- "access_token": "eyJhbGc...",
26
- "expires_in": 3600
27
- }
28
- ```
29
-
30
- **Store:** `TOKEN=<access_token>`
31
-
32
- ### Step 2: List Projects in Toronto
33
-
34
- ```bash
35
- curl -X GET https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects \
36
- -H "Authorization: Bearer $TOKEN"
37
- ```
38
-
39
- **Expected Response:**
40
- ```json
41
- {
42
- "projects": [
43
- {
44
- "id": "7e131e87-e967-4e7f-a2f1-480957244eac",
45
- "name": "markus-app-v2-toronto",
46
- "status": "active"
47
- }
48
- ]
49
- }
50
- ```
51
-
52
- **Store:** `PROJECT_ID=<id>`
53
-
54
- ### Step 3: Create Application
55
-
56
- ```bash
57
- curl -X POST https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects/$PROJECT_ID/apps \
58
- -H "Authorization: Bearer $TOKEN" \
59
- -H "Content-Type: application/json" \
60
- -d '{
61
- "name": "markus-app-v2",
62
- "image_reference": "icr.io/codeengine/helloworld",
63
- "image_port": 8080,
64
- "scale_min_instances": 0,
65
- "scale_max_instances": 1,
66
- "scale_cpu_limit": "0.25",
67
- "scale_memory_limit": "0.5G",
68
- "run_env_variables": [
69
- {
70
- "type": "literal",
71
- "name": "TARGET",
72
- "value": "Toronto - Research Floor 7½"
73
- }
74
- ]
75
- }'
76
- ```
77
-
78
- **Expected Response:**
79
- ```json
80
- {
81
- "name": "markus-app-v2",
82
- "status": "deploying",
83
- "image_reference": "icr.io/codeengine/helloworld",
84
- "endpoint": "markus-app-v2.xxx.ca-tor.codeengine.appdomain.cloud"
85
- }
86
- ```
87
-
88
- ### Step 4: Check Application Status
89
-
90
- ```bash
91
- curl -X GET https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects/$PROJECT_ID/apps/markus-app-v2 \
92
- -H "Authorization: Bearer $TOKEN"
93
- ```
94
-
95
- **Expected Response:**
96
- ```json
97
- {
98
- "name": "markus-app-v2",
99
- "status": "ready",
100
- "endpoint": "markus-app-v2.xxx.ca-tor.codeengine.appdomain.cloud"
101
- }
102
- ```
103
-
104
- **Result:** Application URL: `https://<endpoint>`
105
-
106
- ---
107
-
108
- ## Scenario 2: Update Application Image
109
-
110
- **Goal:** Update existing application with new image
111
-
112
- ### Step 1: Get IAM Token (same as Scenario 1)
113
-
114
- ### Step 2: Get Project ID (same as Scenario 1)
115
-
116
- ### Step 3: Update Application
117
-
118
- ```bash
119
- curl -X PATCH https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects/$PROJECT_ID/apps/markus-app-v2 \
120
- -H "Authorization: Bearer $TOKEN" \
121
- -H "Content-Type: application/merge-patch+json" \
122
- -d '{
123
- "image_reference": "icr.io/namespace/markus-app-v2:v2.0"
124
- }'
125
- ```
126
-
127
- **Expected Response:**
128
- ```json
129
- {
130
- "name": "markus-app-v2",
131
- "status": "updating",
132
- "image_reference": "icr.io/namespace/markus-app-v2:v2.0"
133
- }
134
- ```
135
-
136
- ---
137
-
138
- ## Scenario 3: Scale Application
139
-
140
- **Goal:** Adjust application scaling parameters
141
-
142
- ### Update Scaling
143
-
144
- ```bash
145
- curl -X PATCH https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects/$PROJECT_ID/apps/markus-app-v2 \
146
- -H "Authorization: Bearer $TOKEN" \
147
- -H "Content-Type: application/merge-patch+json" \
148
- -d '{
149
- "scale_min_instances": 1,
150
- "scale_max_instances": 5,
151
- "scale_cpu_limit": "1",
152
- "scale_memory_limit": "2G"
153
- }'
154
- ```
155
-
156
- ---
157
-
158
- ## Scenario 4: Build from Source
159
-
160
- **Goal:** Build container image from source code and deploy
161
-
162
- ### Step 1-2: Get Token and Project ID (same as Scenario 1)
163
-
164
- ### Step 3: Create Build Configuration
165
-
166
- ```bash
167
- curl -X POST https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects/$PROJECT_ID/builds \
168
- -H "Authorization: Bearer $TOKEN" \
169
- -H "Content-Type: application/json" \
170
- -d '{
171
- "name": "markus-app-v2-build",
172
- "output_image": "private.ca-tor.icr.io/'$PROJECT_ID'/markus-app-v2",
173
- "output_secret": "ce-auto-icr-private-ca-tor",
174
- "source_type": "local",
175
- "strategy_type": "dockerfile",
176
- "strategy_spec_file": "Dockerfile",
177
- "strategy_size": "medium"
178
- }'
179
- ```
180
-
181
- **Expected Response:**
182
- ```json
183
- {
184
- "name": "markus-app-v2-build",
185
- "status": "ready",
186
- "output_image": "private.ca-tor.icr.io/project-id/markus-app-v2"
187
- }
188
- ```
189
-
190
- ### Step 4: Create Build Run
191
-
192
- ```bash
193
- curl -X POST https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects/$PROJECT_ID/build_runs \
194
- -H "Authorization: Bearer $TOKEN" \
195
- -H "Content-Type: application/json" \
196
- -d '{
197
- "build_name": "markus-app-v2-build",
198
- "name": "markus-app-v2-build-run-'$(date +%s)'"
199
- }'
200
- ```
201
-
202
- **Expected Response:**
203
- ```json
204
- {
205
- "name": "markus-app-v2-build-run-1234567890",
206
- "status": "pending",
207
- "build_name": "markus-app-v2-build"
208
- }
209
- ```
210
-
211
- **Store:** `BUILD_RUN_NAME=<name>`
212
-
213
- ### Step 5: Upload Source Code
214
-
215
- ```bash
216
- # First create ZIP of source code
217
- cd markus-app-v2
218
- zip -r ../markus-app-v2-source.zip .
219
- cd ..
220
-
221
- # Upload
222
- curl -X PUT https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects/$PROJECT_ID/build_runs/$BUILD_RUN_NAME/source \
223
- -H "Authorization: Bearer $TOKEN" \
224
- -F "file=@markus-app-v2-source.zip"
225
- ```
226
-
227
- ### Step 6: Monitor Build Status
228
-
229
- ```bash
230
- # Poll every 5 seconds
231
- while true; do
232
- STATUS=$(curl -s -X GET https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects/$PROJECT_ID/build_runs/$BUILD_RUN_NAME \
233
- -H "Authorization: Bearer $TOKEN" | jq -r '.status')
234
-
235
- echo "Build status: $STATUS"
236
-
237
- if [ "$STATUS" = "succeeded" ]; then
238
- break
239
- elif [ "$STATUS" = "failed" ]; then
240
- echo "Build failed"
241
- exit 1
242
- fi
243
-
244
- sleep 5
245
- done
246
- ```
247
-
248
- ### Step 7: Deploy with Built Image
249
-
250
- ```bash
251
- # Get the built image reference
252
- IMAGE=$(curl -s -X GET https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects/$PROJECT_ID/build_runs/$BUILD_RUN_NAME \
253
- -H "Authorization: Bearer $TOKEN" | jq -r '.output_image')
254
-
255
- # Create/update application
256
- curl -X POST https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects/$PROJECT_ID/apps \
257
- -H "Authorization: Bearer $TOKEN" \
258
- -H "Content-Type: application/json" \
259
- -d '{
260
- "name": "markus-app-v2",
261
- "image_reference": "'$IMAGE'",
262
- "image_port": 8080,
263
- "scale_min_instances": 0,
264
- "scale_max_instances": 1
265
- }'
266
- ```
267
-
268
- ---
269
-
270
- ## Scenario 5: Create New Project
271
-
272
- **Goal:** Create a new Code Engine project in a region
273
-
274
- ### Step 1: Get IAM Token (same as Scenario 1)
275
-
276
- ### Step 2: Create Project
277
-
278
- ```bash
279
- curl -X POST https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects \
280
- -H "Authorization: Bearer $TOKEN" \
281
- -H "Content-Type: application/json" \
282
- -d '{
283
- "name": "my-new-project"
284
- }'
285
- ```
286
-
287
- **Expected Response:**
288
- ```json
289
- {
290
- "id": "new-project-id",
291
- "name": "my-new-project",
292
- "region": "ca-tor",
293
- "status": "creating"
294
- }
295
- ```
296
-
297
- ### Step 3: Wait for Project to be Active
298
-
299
- ```bash
300
- while true; do
301
- STATUS=$(curl -s -X GET https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects/new-project-id \
302
- -H "Authorization: Bearer $TOKEN" | jq -r '.status')
303
-
304
- echo "Project status: $STATUS"
305
-
306
- if [ "$STATUS" = "active" ]; then
307
- break
308
- fi
309
-
310
- sleep 5
311
- done
312
- ```
313
-
314
- ---
315
-
316
- ## Scenario 6: Manage Secrets
317
-
318
- **Goal:** Create and use secrets for sensitive data
319
-
320
- ### Create Secret
321
-
322
- ```bash
323
- # Base64 encode values
324
- API_KEY_B64=$(echo -n "my-api-key" | base64)
325
- PASSWORD_B64=$(echo -n "my-password" | base64)
326
-
327
- curl -X POST https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects/$PROJECT_ID/secrets \
328
- -H "Authorization: Bearer $TOKEN" \
329
- -H "Content-Type: application/json" \
330
- -d '{
331
- "name": "my-secrets",
332
- "format": "generic",
333
- "data": {
334
- "api_key": "'$API_KEY_B64'",
335
- "password": "'$PASSWORD_B64'"
336
- }
337
- }'
338
- ```
339
-
340
- ### Use Secret in Application
341
-
342
- ```bash
343
- curl -X POST https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects/$PROJECT_ID/apps \
344
- -H "Authorization: Bearer $TOKEN" \
345
- -H "Content-Type: application/json" \
346
- -d '{
347
- "name": "my-app",
348
- "image_reference": "icr.io/namespace/image:tag",
349
- "run_env_variables": [
350
- {
351
- "type": "secret_key_reference",
352
- "name": "API_KEY",
353
- "reference": "my-secrets.api_key"
354
- }
355
- ]
356
- }'
357
- ```
358
-
359
- ---
360
-
361
- ## Scenario 7: Delete Resources
362
-
363
- **Goal:** Clean up Code Engine resources
364
-
365
- ### Delete Application
366
-
367
- ```bash
368
- curl -X DELETE https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects/$PROJECT_ID/apps/markus-app-v2 \
369
- -H "Authorization: Bearer $TOKEN"
370
- ```
371
-
372
- **Expected Response:** HTTP 204 No Content
373
-
374
- ### Delete Build Configuration
375
-
376
- ```bash
377
- curl -X DELETE https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects/$PROJECT_ID/builds/markus-app-v2-build \
378
- -H "Authorization: Bearer $TOKEN"
379
- ```
380
-
381
- ### Delete Project
382
-
383
- ```bash
384
- curl -X DELETE https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects/$PROJECT_ID \
385
- -H "Authorization: Bearer $TOKEN"
386
- ```
387
-
388
- ---
389
-
390
- ## Scenario 8: Multi-Region Deployment
391
-
392
- **Goal:** Deploy same application to multiple regions
393
-
394
- ### Deploy to Multiple Regions
395
-
396
- ```bash
397
- REGIONS=("us-south" "eu-de" "ca-tor")
398
-
399
- for REGION in "${REGIONS[@]}"; do
400
- echo "Deploying to $REGION..."
401
-
402
- # Get token (reuse if not expired)
403
- TOKEN=$(curl -s -X POST https://iam.cloud.ibm.com/identity/token \
404
- -H "Content-Type: application/x-www-form-urlencoded" \
405
- -d "grant_type=urn:ibm:params:oauth:grant-type:apikey&apikey=$IBMCLOUD_API_KEY" \
406
- | jq -r '.access_token')
407
-
408
- # Get or create project
409
- PROJECT_ID=$(curl -s -X GET https://api.$REGION.codeengine.cloud.ibm.com/v2/projects \
410
- -H "Authorization: Bearer $TOKEN" \
411
- | jq -r '.projects[0].id')
412
-
413
- # Deploy application
414
- curl -X POST https://api.$REGION.codeengine.cloud.ibm.com/v2/projects/$PROJECT_ID/apps \
415
- -H "Authorization: Bearer $TOKEN" \
416
- -H "Content-Type: application/json" \
417
- -d '{
418
- "name": "markus-app-v2",
419
- "image_reference": "icr.io/codeengine/helloworld",
420
- "image_port": 8080
421
- }'
422
-
423
- echo "Deployed to $REGION"
424
- done
425
- ```
426
-
427
- ---
428
-
429
- ## Scenario 9: Run Job
430
-
431
- **Goal:** Execute a batch job
432
-
433
- ### Create Job Definition
434
-
435
- ```bash
436
- curl -X POST https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects/$PROJECT_ID/jobs \
437
- -H "Authorization: Bearer $TOKEN" \
438
- -H "Content-Type: application/json" \
439
- -d '{
440
- "name": "data-processor",
441
- "image_reference": "icr.io/namespace/processor:latest",
442
- "run_mode": "task",
443
- "scale_array_spec": "1-10",
444
- "scale_cpu_limit": "1",
445
- "scale_memory_limit": "4G"
446
- }'
447
- ```
448
-
449
- ### Submit Job Run
450
-
451
- ```bash
452
- curl -X POST https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects/$PROJECT_ID/job_runs \
453
- -H "Authorization: Bearer $TOKEN" \
454
- -H "Content-Type: application/json" \
455
- -d '{
456
- "job_name": "data-processor",
457
- "name": "data-processor-run-'$(date +%s)'"
458
- }'
459
- ```
460
-
461
- ---
462
-
463
- ## MCP Tool Integration
464
-
465
- ### How Bob Uses These Scenarios
466
-
467
- 1. **User Request:** "Deploy MarkusAppV2 to Toronto"
468
-
469
- 2. **Bob Identifies Scenario:** Scenario 1 - Deploy Application to Toronto
470
-
471
- 3. **Bob Executes via MCP:**
472
- ```
473
- execute_command: curl -X POST https://iam.cloud.ibm.com/...
474
- execute_command: curl -X GET https://api.ca-tor.codeengine.cloud.ibm.com/...
475
- execute_command: curl -X POST https://api.ca-tor.codeengine.cloud.ibm.com/...
476
- ```
477
-
478
- 4. **Bob Monitors Progress:**
479
- - Checks response codes
480
- - Parses JSON responses
481
- - Waits for status changes
482
- - Reports results to user
483
-
484
- 5. **No Scripts Created:** All operations done through direct API calls
485
-
486
- ### Benefits
487
-
488
- - ✅ No standalone scripts to maintain
489
- - ✅ Direct API execution through MCP
490
- - ✅ Real-time feedback and error handling
491
- - ✅ Flexible and adaptable to user needs
492
- - ✅ Knowledge embedded in skill documentation
493
-
494
- ---
495
-
496
- ## Error Handling Examples
497
-
498
- ### Handle 401 Unauthorized
499
-
500
- ```bash
501
- RESPONSE=$(curl -s -w "\n%{http_code}" -X GET https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects \
502
- -H "Authorization: Bearer $TOKEN")
503
-
504
- HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
505
-
506
- if [ "$HTTP_CODE" = "401" ]; then
507
- echo "Token expired, refreshing..."
508
- TOKEN=$(curl -s -X POST https://iam.cloud.ibm.com/identity/token \
509
- -H "Content-Type: application/x-www-form-urlencoded" \
510
- -d "grant_type=urn:ibm:params:oauth:grant-type:apikey&apikey=$IBMCLOUD_API_KEY" \
511
- | jq -r '.access_token')
512
- # Retry request
513
- fi
514
- ```
515
-
516
- ### Handle 404 Not Found
517
-
518
- ```bash
519
- RESPONSE=$(curl -s -w "\n%{http_code}" -X GET https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects/$PROJECT_ID/apps/my-app \
520
- -H "Authorization: Bearer $TOKEN")
521
-
522
- HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
523
-
524
- if [ "$HTTP_CODE" = "404" ]; then
525
- echo "Application not found, creating new..."
526
- # Create application
527
- fi
528
- ```
529
-
530
- ### Handle 409 Conflict
531
-
532
- ```bash
533
- RESPONSE=$(curl -s -w "\n%{http_code}" -X POST https://api.ca-tor.codeengine.cloud.ibm.com/v2/projects/$PROJECT_ID/apps \
534
- -H "Authorization: Bearer $TOKEN" \
535
- -H "Content-Type: application/json" \
536
- -d '{"name": "my-app", ...}')
537
-
538
- HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
539
-
540
- if [ "$HTTP_CODE" = "409" ]; then
541
- echo "Application exists, updating instead..."
542
- # Use PATCH instead
543
- fi
544
- ```
545
-
546
- ---
547
-
548
- ## Quick Reference
549
-
550
- ### Common Variables
551
-
552
- ```bash
553
- IBMCLOUD_API_KEY="your-api-key"
554
- TOKEN="eyJhbGc..."
555
- PROJECT_ID="7e131e87-e967-4e7f-a2f1-480957244eac"
556
- REGION="ca-tor"
557
- APP_NAME="markus-app-v2"
558
- ```
559
-
560
- ### Common Endpoints
561
-
562
- ```bash
563
- # IAM
564
- https://iam.cloud.ibm.com/identity/token
565
-
566
- # Code Engine (replace {region})
567
- https://api.{region}.codeengine.cloud.ibm.com/v2/projects
568
- https://api.{region}.codeengine.cloud.ibm.com/v2/projects/{project_id}/apps
569
- https://api.{region}.codeengine.cloud.ibm.com/v2/projects/{project_id}/builds
570
- https://api.{region}.codeengine.cloud.ibm.com/v2/projects/{project_id}/build_runs
571
- ```
572
-
573
- ### Useful jq Queries
574
-
575
- ```bash
576
- # Extract access token
577
- jq -r '.access_token'
578
-
579
- # Extract project ID
580
- jq -r '.projects[0].id'
581
-
582
- # Extract application endpoint
583
- jq -r '.endpoint'
584
-
585
- # Extract build status
586
- jq -r '.status'
587
-
588
- # Check if app exists
589
- jq -r '.apps[] | select(.name=="markus-app-v2") | .name'
590
- ```
591
-
592
- ---
593
-
594
- This documentation enables Bob to execute any Code Engine operation through MCP tools without creating standalone scripts. The skill orchestrates the API calls based on user requests.