@democratize-quality/mcp-server 1.0.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/LICENSE +15 -0
- package/README.md +423 -0
- package/browserControl.js +113 -0
- package/cli.js +187 -0
- package/docs/api/tool-reference.md +317 -0
- package/docs/api_tools_usage.md +477 -0
- package/docs/development/adding-tools.md +274 -0
- package/docs/development/configuration.md +332 -0
- package/docs/examples/authentication.md +124 -0
- package/docs/examples/basic-automation.md +105 -0
- package/docs/getting-started.md +214 -0
- package/docs/index.md +61 -0
- package/mcpServer.js +280 -0
- package/package.json +83 -0
- package/run-server.js +140 -0
- package/src/config/environments/api-only.js +53 -0
- package/src/config/environments/development.js +54 -0
- package/src/config/environments/production.js +69 -0
- package/src/config/index.js +341 -0
- package/src/config/server.js +41 -0
- package/src/config/tools/api.js +67 -0
- package/src/config/tools/browser.js +90 -0
- package/src/config/tools/default.js +32 -0
- package/src/services/browserService.js +325 -0
- package/src/tools/api/api-request.js +641 -0
- package/src/tools/api/api-session-report.js +1262 -0
- package/src/tools/api/api-session-status.js +395 -0
- package/src/tools/base/ToolBase.js +230 -0
- package/src/tools/base/ToolRegistry.js +269 -0
- package/src/tools/browser/advanced/browser-console.js +384 -0
- package/src/tools/browser/advanced/browser-dialog.js +319 -0
- package/src/tools/browser/advanced/browser-evaluate.js +337 -0
- package/src/tools/browser/advanced/browser-file.js +480 -0
- package/src/tools/browser/advanced/browser-keyboard.js +343 -0
- package/src/tools/browser/advanced/browser-mouse.js +332 -0
- package/src/tools/browser/advanced/browser-network.js +421 -0
- package/src/tools/browser/advanced/browser-pdf.js +407 -0
- package/src/tools/browser/advanced/browser-tabs.js +497 -0
- package/src/tools/browser/advanced/browser-wait.js +378 -0
- package/src/tools/browser/click.js +168 -0
- package/src/tools/browser/close.js +60 -0
- package/src/tools/browser/dom.js +70 -0
- package/src/tools/browser/launch.js +67 -0
- package/src/tools/browser/navigate.js +270 -0
- package/src/tools/browser/screenshot.js +351 -0
- package/src/tools/browser/type.js +174 -0
- package/src/tools/index.js +95 -0
- package/src/utils/browserHelpers.js +83 -0
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
---
|
|
2
|
+
|
|
3
|
+
## Playwright MCP API Tool Usage in
|
|
4
|
+
|
|
5
|
+
This guide shows how to use the API testing tool you added to the Playwright MCP server from , with real-world API endpoints and prompt examples for all HTTP methods and advanced validation.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 1. Tool Overview
|
|
10
|
+
- **Tool Name:** `api_request`
|
|
11
|
+
- **Description:** Perform an HTTP API request (GET, POST, PUT, PATCH, DELETE, etc.) and validate the response.
|
|
12
|
+
- **Config Requirement:** `"api_request"` must be present in your MCP config `capabilities`.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 2. General Prompt Pattern
|
|
17
|
+
|
|
18
|
+
> **Prompt:**
|
|
19
|
+
> "Call the `api_request` tool to make a [METHOD] request to `[URL]` with [optional headers/data]."
|
|
20
|
+
|
|
21
|
+
You can specify method, headers, data, and expected status/content-type/body.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 3. Basic Example Prompts and Payloads
|
|
26
|
+
|
|
27
|
+
### A. GET Request (Public API)
|
|
28
|
+
**Prompt:**
|
|
29
|
+
```
|
|
30
|
+
Call the `api_request` tool to make a GET request to `https://jsonplaceholder.typicode.com/posts/1`.
|
|
31
|
+
```
|
|
32
|
+
**Payload:**
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"method": "GET",
|
|
36
|
+
"url": "https://jsonplaceholder.typicode.com/posts/1"
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### B. POST Request (JSON)
|
|
41
|
+
**Prompt:**
|
|
42
|
+
```
|
|
43
|
+
Call the `api_request` tool to make a POST request to `https://jsonplaceholder.typicode.com/posts` with JSON body `{ "title": "foo", "body": "bar", "userId": 1 }`.
|
|
44
|
+
```
|
|
45
|
+
**Payload:**
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"method": "POST",
|
|
49
|
+
"url": "https://jsonplaceholder.typicode.com/posts",
|
|
50
|
+
"headers": { "Content-Type": "application/json" },
|
|
51
|
+
"data": { "title": "foo", "body": "bar", "userId": 1 }
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### C. PUT Request
|
|
56
|
+
**Prompt:**
|
|
57
|
+
```
|
|
58
|
+
Call the `api_request` tool to make a PUT request to `https://jsonplaceholder.typicode.com/posts/1` with JSON body `{ "id": 1, "title": "updated", "body": "baz", "userId": 1 }`.
|
|
59
|
+
```
|
|
60
|
+
**Payload:**
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"method": "PUT",
|
|
64
|
+
"url": "https://jsonplaceholder.typicode.com/posts/1",
|
|
65
|
+
"headers": { "Content-Type": "application/json" },
|
|
66
|
+
"data": { "id": 1, "title": "updated", "body": "baz", "userId": 1 }
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### D. PATCH Request
|
|
71
|
+
**Prompt:**
|
|
72
|
+
```
|
|
73
|
+
Call the `api_request` tool to make a PATCH request to `https://jsonplaceholder.typicode.com/posts/1` with JSON `{ "title": "patched" }`.
|
|
74
|
+
```
|
|
75
|
+
**Payload:**
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"method": "PATCH",
|
|
79
|
+
"url": "https://jsonplaceholder.typicode.com/posts/1",
|
|
80
|
+
"headers": { "Content-Type": "application/json" },
|
|
81
|
+
"data": { "title": "patched" }
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### E. DELETE Request
|
|
86
|
+
**Prompt:**
|
|
87
|
+
```
|
|
88
|
+
Call the `api_request` tool to make a DELETE request to `https://jsonplaceholder.typicode.com/posts/1`.
|
|
89
|
+
```
|
|
90
|
+
**Payload:**
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"method": "DELETE",
|
|
94
|
+
"url": "https://jsonplaceholder.typicode.com/posts/1"
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## 4. Advanced: Adding Expectations
|
|
101
|
+
You can add `expect` for status, content-type, and advanced body validation:
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"method": "GET",
|
|
105
|
+
"url": "https://jsonplaceholder.typicode.com/posts/1",
|
|
106
|
+
"expect": {
|
|
107
|
+
"status": 200,
|
|
108
|
+
"contentType": "application/json"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## 5. Response Body Validation: Example Scenarios
|
|
116
|
+
|
|
117
|
+
### A. Partial/Exact JSON Body Match
|
|
118
|
+
**Prompt:**
|
|
119
|
+
```
|
|
120
|
+
Call the `api_request` tool to make a GET request to `https://jsonplaceholder.typicode.com/posts/1` and validate that the response contains `"userId": 1` and `"id": 1`.
|
|
121
|
+
```
|
|
122
|
+
**Payload:**
|
|
123
|
+
```json
|
|
124
|
+
{
|
|
125
|
+
"method": "GET",
|
|
126
|
+
"url": "https://jsonplaceholder.typicode.com/posts/1",
|
|
127
|
+
"expect": {
|
|
128
|
+
"body": { "userId": 1, "id": 1 }
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### B. Regex Body Match
|
|
134
|
+
**Prompt:**
|
|
135
|
+
```
|
|
136
|
+
Call the `api_request` tool to make a GET request to `https://jsonplaceholder.typicode.com/posts/1` and check if the response contains the word `"sunt"`.
|
|
137
|
+
```
|
|
138
|
+
**Payload:**
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"method": "GET",
|
|
142
|
+
"url": "https://jsonplaceholder.typicode.com/posts/1",
|
|
143
|
+
"expect": {
|
|
144
|
+
"bodyRegex": "sunt"
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### C. Failing Case Example
|
|
150
|
+
**Prompt:**
|
|
151
|
+
```
|
|
152
|
+
Call the `api_request` tool to make a GET request to `https://jsonplaceholder.typicode.com/posts/1` and validate that the response contains `"userId": 999`.
|
|
153
|
+
```
|
|
154
|
+
**Payload:**
|
|
155
|
+
```json
|
|
156
|
+
{
|
|
157
|
+
"method": "GET",
|
|
158
|
+
"url": "https://jsonplaceholder.typicode.com/posts/1",
|
|
159
|
+
"expect": {
|
|
160
|
+
"body": { "userId": 999 }
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
**Expected:**
|
|
165
|
+
- The validation should fail, and the output will include a `bodyValidation` object with `matched: false` and a reason.
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## 6. Real-World API Examples: Custom Headers & Authentication
|
|
170
|
+
|
|
171
|
+
### Example 1: Using Custom Headers
|
|
172
|
+
**Scenario:** Send a GET request to the [httpbin.org/headers](https://httpbin.org/headers) endpoint with a custom header.
|
|
173
|
+
|
|
174
|
+
**Prompt:**
|
|
175
|
+
```
|
|
176
|
+
Call the `api_request` tool to make a GET request to `https://httpbin.org/headers` with custom header `X-Custom-Header: Test`.
|
|
177
|
+
```
|
|
178
|
+
**Payload:**
|
|
179
|
+
```json
|
|
180
|
+
{
|
|
181
|
+
"method": "GET",
|
|
182
|
+
"url": "https://httpbin.org/headers",
|
|
183
|
+
"headers": {
|
|
184
|
+
"X-Custom-Header": "Test"
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
- **What to expect:** The response will echo your custom header in the response body.
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
### Example 2: Authentication (Bearer Token)
|
|
193
|
+
**Scenario:** Access a protected endpoint using Bearer token authentication. We'll use [reqres.in](https://reqres.in/) which simulates a real login and protected resource.
|
|
194
|
+
|
|
195
|
+
**Step 1: Obtain a Token**
|
|
196
|
+
|
|
197
|
+
**Prompt:**
|
|
198
|
+
```
|
|
199
|
+
Call the `api_request` tool to make a POST request to `https://reqres.in/api/login` with JSON `{ "email": "eve.holt@reqres.in", "password": "cityslicka" }`.
|
|
200
|
+
```
|
|
201
|
+
**Payload:**
|
|
202
|
+
```json
|
|
203
|
+
{
|
|
204
|
+
"method": "POST",
|
|
205
|
+
"url": "https://reqres.in/api/login",
|
|
206
|
+
"headers": { "Content-Type": "application/json" },
|
|
207
|
+
"data": {
|
|
208
|
+
"email": "eve.holt@reqres.in",
|
|
209
|
+
"password": "cityslicka"
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
- **The response will include a `token`.**
|
|
214
|
+
|
|
215
|
+
**Step 2: Use the Token in an Authenticated Request**
|
|
216
|
+
|
|
217
|
+
**Prompt:**
|
|
218
|
+
```
|
|
219
|
+
Call the `api_request` tool to make a GET request to `https://reqres.in/api/users/2` with Bearer token authentication.
|
|
220
|
+
```
|
|
221
|
+
**Payload:**
|
|
222
|
+
```
|
|
223
|
+
{
|
|
224
|
+
"method": "GET",
|
|
225
|
+
"url": "https://reqres.in/api/users/2",
|
|
226
|
+
"headers": {
|
|
227
|
+
"Authorization": "Bearer YOUR_TOKEN_HERE"
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
- **Replace `YOUR_TOKEN_HERE` with the token received from the login step.**
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
These examples can be copied directly into prompts or used as templates for your own API testing scenarios.
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## 7. Using sessionId for API Test Sessions
|
|
240
|
+
|
|
241
|
+
You can explicitly set a session ID for your API test workflow, or let the tool auto-generate one. This helps you group related API calls for reporting and debugging.
|
|
242
|
+
|
|
243
|
+
### Example 1: Provide a Custom sessionId
|
|
244
|
+
|
|
245
|
+
** Prompt Example:**
|
|
246
|
+
```
|
|
247
|
+
Call the `api_request` tool to make a POST request to `https://jsonplaceholder.typicode.com/posts` with session ID `demo-session-1`.
|
|
248
|
+
```
|
|
249
|
+
**Payload:**
|
|
250
|
+
```json
|
|
251
|
+
{
|
|
252
|
+
"sessionId": "demo-session-1",
|
|
253
|
+
"method": "POST",
|
|
254
|
+
"url": "https://jsonplaceholder.typicode.com/posts",
|
|
255
|
+
"headers": { "Content-Type": "application/json" },
|
|
256
|
+
"data": { "title": "foo", "body": "bar", "userId": 1 }
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Example 2: Use sessionId in Chaining
|
|
261
|
+
|
|
262
|
+
** Prompt Example:**
|
|
263
|
+
```
|
|
264
|
+
Call the `api_request` tool to chain a login and authenticated GET using session ID `login-chain-demo`.
|
|
265
|
+
```
|
|
266
|
+
**Payload:**
|
|
267
|
+
```json
|
|
268
|
+
{
|
|
269
|
+
"sessionId": "login-chain-demo",
|
|
270
|
+
"chain": [
|
|
271
|
+
{
|
|
272
|
+
"name": "login",
|
|
273
|
+
"method": "POST",
|
|
274
|
+
"url": "https://reqres.in/api/login",
|
|
275
|
+
"headers": { "Content-Type": "application/json" },
|
|
276
|
+
"data": { "email": "eve.holt@reqres.in", "password": "cityslicka" },
|
|
277
|
+
"extract": { "token": "token" }
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
"name": "getUser",
|
|
281
|
+
"method": "GET",
|
|
282
|
+
"url": "https://reqres.in/api/users/2",
|
|
283
|
+
"headers": { "Authorization": "Bearer {{login.token}}" }
|
|
284
|
+
}
|
|
285
|
+
]
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Example 3: Omit sessionId for Auto-Generated Sessions
|
|
290
|
+
|
|
291
|
+
** Prompt Example:**
|
|
292
|
+
```
|
|
293
|
+
Call the `api_request` tool to make a GET request to `https://jsonplaceholder.typicode.com/posts/1` and let the tool auto-generate the session ID.
|
|
294
|
+
```
|
|
295
|
+
**Payload:**
|
|
296
|
+
```json
|
|
297
|
+
{
|
|
298
|
+
"method": "GET",
|
|
299
|
+
"url": "https://jsonplaceholder.typicode.com/posts/1"
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
The tool result will always include the sessionId used, so you can reference it for later queries or reporting.
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## 8. Querying API Session Status
|
|
308
|
+
|
|
309
|
+
You can retrieve the status, logs, and results for any API test session using the `api_session_status` tool and a sessionId.
|
|
310
|
+
|
|
311
|
+
### Example 1: Query a Known Session
|
|
312
|
+
|
|
313
|
+
** Prompt Example:**
|
|
314
|
+
```
|
|
315
|
+
Call the `api_session_status` tool to show the logs and results for session ID `login-chain-demo`.
|
|
316
|
+
```
|
|
317
|
+
**Payload:**
|
|
318
|
+
```json
|
|
319
|
+
{
|
|
320
|
+
"sessionId": "login-chain-demo"
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### Example 2: Query an Auto-Generated Session
|
|
325
|
+
|
|
326
|
+
If you did not provide a sessionId, copy the sessionId from the previous API tool result and use it here.
|
|
327
|
+
|
|
328
|
+
** Prompt Example:**
|
|
329
|
+
```
|
|
330
|
+
Call the `api_session_status` tool to show the results for session ID `session-abc123xyz`.
|
|
331
|
+
```
|
|
332
|
+
**Payload:**
|
|
333
|
+
```json
|
|
334
|
+
{
|
|
335
|
+
"sessionId": "session-abc123xyz"
|
|
336
|
+
}
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
The output will include all requests, responses, validation results, and timestamps for the session.
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
343
|
+
## 9. Generating an HTML Report for a Session
|
|
344
|
+
|
|
345
|
+
You can generate and retrieve a detailed HTML report for any API test session using the `api_session_report` tool and a sessionId.
|
|
346
|
+
|
|
347
|
+
### Example 1: Generate a Report for a Known Session
|
|
348
|
+
|
|
349
|
+
** Prompt Example:**
|
|
350
|
+
```
|
|
351
|
+
Call the `api_session_report` tool to generate an HTML report for session ID `login-chain-demo`.
|
|
352
|
+
```
|
|
353
|
+
**Payload:**
|
|
354
|
+
```json
|
|
355
|
+
{
|
|
356
|
+
"sessionId": "login-chain-demo"
|
|
357
|
+
}
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
### Example 2: Generate a Report for an Auto-Generated Session
|
|
361
|
+
|
|
362
|
+
If you did not provide a sessionId, copy the sessionId from the previous API tool result and use it here.
|
|
363
|
+
|
|
364
|
+
** Prompt Example:**
|
|
365
|
+
```
|
|
366
|
+
Call the `api_session_report` tool to generate an HTML report for session ID `session-abc123xyz`.
|
|
367
|
+
```
|
|
368
|
+
**Payload:**
|
|
369
|
+
```json
|
|
370
|
+
{
|
|
371
|
+
"sessionId": "session-abc123xyz"
|
|
372
|
+
}
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
The output will show the file path to the generated HTML report (e.g., `reports/session-login-chain-demo.html`). Open this file in your browser to view the full report.
|
|
376
|
+
|
|
377
|
+
---
|
|
378
|
+
|
|
379
|
+
## 10. API Chaining: Multi-Step Requests & Variable Passing
|
|
380
|
+
|
|
381
|
+
You can execute a sequence of API requests where outputs from one step can be used in subsequent steps. This enables scenarios like login and token usage, resource creation and retrieval, etc.
|
|
382
|
+
|
|
383
|
+
### Input Schema for Chaining
|
|
384
|
+
|
|
385
|
+
** Prompt Example:**
|
|
386
|
+
```
|
|
387
|
+
Call the `api_request` tool to execute a chain of two API requests. First, POST to `https://api.example.com/login` with username and password, extract the token, then GET `https://api.example.com/data` using `Bearer {{step1.token}}` in the Authorization header.
|
|
388
|
+
```
|
|
389
|
+
```json
|
|
390
|
+
{
|
|
391
|
+
"chain": [
|
|
392
|
+
{
|
|
393
|
+
"name": "step1",
|
|
394
|
+
"method": "POST",
|
|
395
|
+
"url": "https://api.example.com/login",
|
|
396
|
+
"headers": { "Content-Type": "application/json" },
|
|
397
|
+
"data": { "username": "user", "password": "pass" },
|
|
398
|
+
"extract": { "token": "token" }
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
"name": "step2",
|
|
402
|
+
"method": "GET",
|
|
403
|
+
"url": "https://api.example.com/data",
|
|
404
|
+
"headers": { "Authorization": "Bearer {{step1.token}}" }
|
|
405
|
+
}
|
|
406
|
+
]
|
|
407
|
+
}
|
|
408
|
+
```
|
|
409
|
+
- Each step must have a unique `name`.
|
|
410
|
+
- Use `extract` to pull fields from the response JSON (dot notation supported).
|
|
411
|
+
- Use `{{stepName.field}}` in later steps to reference extracted values.
|
|
412
|
+
|
|
413
|
+
---
|
|
414
|
+
|
|
415
|
+
### Real-World Example: Login and Authenticated Request (reqres.in)
|
|
416
|
+
|
|
417
|
+
** Prompt Example:**
|
|
418
|
+
```
|
|
419
|
+
Call the `api_request` tool to chain a login to `https://reqres.in/api/login` (extract the token) and then GET `https://reqres.in/api/users/2` with Bearer token from the login step.
|
|
420
|
+
```
|
|
421
|
+
**Payload:**
|
|
422
|
+
```json
|
|
423
|
+
{
|
|
424
|
+
"chain": [
|
|
425
|
+
{
|
|
426
|
+
"name": "login",
|
|
427
|
+
"method": "POST",
|
|
428
|
+
"url": "https://reqres.in/api/login",
|
|
429
|
+
"headers": { "Content-Type": "application/json" },
|
|
430
|
+
"data": { "email": "eve.holt@reqres.in", "password": "cityslicka" },
|
|
431
|
+
"extract": { "token": "token" }
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
"name": "getUser",
|
|
435
|
+
"method": "GET",
|
|
436
|
+
"url": "https://reqres.in/api/users/2",
|
|
437
|
+
"headers": { "Authorization": "Bearer {{login.token}}" }
|
|
438
|
+
}
|
|
439
|
+
]
|
|
440
|
+
}
|
|
441
|
+
```
|
|
442
|
+
- The first step logs in and extracts the `token`.
|
|
443
|
+
- The second step uses `{{login.token}}` in the Authorization header.
|
|
444
|
+
- The tool output will include results for both steps, including extracted variables and validation.
|
|
445
|
+
|
|
446
|
+
---
|
|
447
|
+
|
|
448
|
+
### Chaining with Validation
|
|
449
|
+
|
|
450
|
+
** Prompt Example:**
|
|
451
|
+
```
|
|
452
|
+
Call the `api_request` tool to chain a login to `https://reqres.in/api/login` (extract the token, expect status 200) and then GET `https://reqres.in/api/users/2` with Bearer token from the login step, expecting status 200 and user id 2 in the body.
|
|
453
|
+
```
|
|
454
|
+
```json
|
|
455
|
+
{
|
|
456
|
+
"chain": [
|
|
457
|
+
{
|
|
458
|
+
"name": "login",
|
|
459
|
+
"method": "POST",
|
|
460
|
+
"url": "https://reqres.in/api/login",
|
|
461
|
+
"headers": { "Content-Type": "application/json" },
|
|
462
|
+
"data": { "email": "eve.holt@reqres.in", "password": "cityslicka" },
|
|
463
|
+
"extract": { "token": "token" },
|
|
464
|
+
"expect": { "status": 200 }
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
"name": "getUser",
|
|
468
|
+
"method": "GET",
|
|
469
|
+
"url": "https://reqres.in/api/users/2",
|
|
470
|
+
"headers": { "Authorization": "Bearer {{login.token}}" },
|
|
471
|
+
"expect": { "status": 200, "body": { "data": { "id": 2 } } }
|
|
472
|
+
}
|
|
473
|
+
]
|
|
474
|
+
}
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
---
|