Skip to content

Commit 2ed2478

Browse files
authored
UI updates for 1258 (IBM#1269)
Signed-off-by: Mihai Criveti <[email protected]>
1 parent 2912750 commit 2ed2478

File tree

13 files changed

+1562
-1
lines changed

13 files changed

+1562
-1
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# report issues (linters). Modified files will need to be staged again.
1919
# -----------------------------------------------------------------------------
2020

21-
exclude: '(^|/)(\.pre-commit-config\.yaml|normalize_special_characters\.py|test_input_validation\.py|ai_artifacts_normalizer\.py)$|(^|/)mcp-servers/templates/|.*\.(jinja|j2)$' # ignore these files, all templates, and jinja files
21+
exclude: '(^|/)(\.pre-commit-config\.yaml|normalize_special_characters\.py|test_input_validation\.py|ai_artifacts_normalizer\.py)$|(^|/)mcp-servers/templates/|(^|/)tests/load/|.*\.(jinja|j2)$' # ignore these files, all templates, load tests, and jinja files
2222

2323
repos:
2424
# -----------------------------------------------------------------------------
Lines changed: 326 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,326 @@
1+
# Testing Output Schema with curl
2+
3+
Quick reference for testing the output_schema implementation using curl.
4+
5+
## Setup
6+
7+
First, generate a JWT token and export it:
8+
9+
```bash
10+
export TOKEN=$(python3 -m mcpgateway.utils.create_jwt_token --username [email protected] --exp 0 --secret changeme123)
11+
```
12+
13+
Or use an existing token:
14+
```bash
15+
export TOKEN="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluQGV4YW1wbGUuY29tIiwiaWF0IjoxNzYwNjQzNTU1LCJpc3MiOiJtY3BnYXRld2F5IiwiYXVkIjoibWNwZ2F0ZXdheS1hcGkiLCJzdWIiOiJhZG1pbkBleGFtcGxlLmNvbSJ9.4qSaXA5D3jEEJNh9VTDvPbQP7CflF9wU_x9EAoXVB8I"
16+
```
17+
18+
## Quick Test Commands
19+
20+
### 1. List All Tools (Check for outputSchema field)
21+
22+
```bash
23+
curl -s -H "Authorization: Bearer $TOKEN" \
24+
http://localhost:4444/tools | jq '.'
25+
```
26+
27+
### 2. Find a Specific Tool (e.g., add_numbers)
28+
29+
```bash
30+
curl -s -H "Authorization: Bearer $TOKEN" \
31+
http://localhost:4444/tools | jq '.[] | select(.name == "add_numbers")'
32+
```
33+
34+
### 3. Check outputSchema Field Specifically
35+
36+
```bash
37+
curl -s -H "Authorization: Bearer $TOKEN" \
38+
http://localhost:4444/tools | \
39+
jq '.[] | select(.name == "add_numbers") | {name, inputSchema, outputSchema}'
40+
```
41+
42+
**Expected Output**:
43+
```json
44+
{
45+
"name": "add_numbers",
46+
"inputSchema": {
47+
"properties": {
48+
"a": {
49+
"description": "First number",
50+
"title": "A",
51+
"type": "number"
52+
},
53+
"b": {
54+
"description": "Second number",
55+
"title": "B",
56+
"type": "number"
57+
}
58+
},
59+
"required": ["a", "b"],
60+
"title": "add_numbers",
61+
"type": "object"
62+
},
63+
"outputSchema": {
64+
"properties": {
65+
"result": {
66+
"description": "The calculated result",
67+
"title": "Result",
68+
"type": "number"
69+
},
70+
"operation": {
71+
"description": "The operation performed",
72+
"title": "Operation",
73+
"type": "string"
74+
},
75+
"operands": {
76+
"description": "The operands used",
77+
"items": {
78+
"type": "number"
79+
},
80+
"title": "Operands",
81+
"type": "array"
82+
},
83+
"success": {
84+
"default": true,
85+
"description": "Whether the calculation succeeded",
86+
"title": "Success",
87+
"type": "boolean"
88+
}
89+
},
90+
"required": ["result", "operation", "operands"],
91+
"title": "CalculationResult",
92+
"type": "object"
93+
}
94+
}
95+
```
96+
97+
### 4. Check All Tools for outputSchema Presence
98+
99+
```bash
100+
curl -s -H "Authorization: Bearer $TOKEN" \
101+
http://localhost:4444/tools | \
102+
jq '.[] | select(.name | contains("_numbers") or contains("create_user") or contains("validate_email") or . == "echo") | {name, has_output_schema: (.outputSchema != null)}'
103+
```
104+
105+
**Expected Output**:
106+
```json
107+
{"name": "add_numbers", "has_output_schema": true}
108+
{"name": "multiply_numbers", "has_output_schema": true}
109+
{"name": "divide_numbers", "has_output_schema": true}
110+
{"name": "create_user", "has_output_schema": true}
111+
{"name": "validate_email", "has_output_schema": true}
112+
{"name": "echo", "has_output_schema": false}
113+
```
114+
115+
### 5. Invoke a Tool
116+
117+
```bash
118+
curl -s -X POST -H "Authorization: Bearer $TOKEN" \
119+
-H "Content-Type: application/json" \
120+
http://localhost:4444/tools/invoke \
121+
-d '{
122+
"name": "add_numbers",
123+
"arguments": {"a": 10, "b": 5}
124+
}' | jq '.'
125+
```
126+
127+
**Expected Output**:
128+
```json
129+
{
130+
"content": [
131+
{
132+
"type": "text",
133+
"text": "{\"result\": 15.0, \"operation\": \"addition\", \"operands\": [10.0, 5.0], \"success\": true}"
134+
}
135+
]
136+
}
137+
```
138+
139+
### 6. Test Complex Tool (create_user)
140+
141+
```bash
142+
curl -s -X POST -H "Authorization: Bearer $TOKEN" \
143+
-H "Content-Type: application/json" \
144+
http://localhost:4444/tools/invoke \
145+
-d '{
146+
"name": "create_user",
147+
"arguments": {
148+
"name": "John Doe",
149+
"email": "[email protected]",
150+
"age": 30,
151+
"roles": ["admin", "user"]
152+
}
153+
}' | jq '.'
154+
```
155+
156+
**Expected Output**:
157+
```json
158+
{
159+
"content": [
160+
{
161+
"type": "text",
162+
"text": "{\"name\": \"John Doe\", \"email\": \"[email protected]\", \"age\": 30, \"roles\": [\"admin\", \"user\"]}"
163+
}
164+
]
165+
}
166+
```
167+
168+
### 7. Test Tool Without outputSchema (echo)
169+
170+
```bash
171+
curl -s -H "Authorization: Bearer $TOKEN" \
172+
http://localhost:4444/tools | \
173+
jq '.[] | select(.name == "echo") | {name, outputSchema}'
174+
```
175+
176+
**Expected Output**:
177+
```json
178+
{
179+
"name": "echo",
180+
"outputSchema": null
181+
}
182+
```
183+
184+
## Export/Import Testing
185+
186+
### 8. Export Tools with outputSchema
187+
188+
```bash
189+
curl -s -H "Authorization: Bearer $TOKEN" \
190+
http://localhost:4444/bulk/export > /tmp/tools-export.json
191+
192+
# Check the export
193+
jq '.tools[] | select(.name == "add_numbers") | {name, has_output_schema: (.output_schema != null)}' /tmp/tools-export.json
194+
```
195+
196+
**Expected Output**:
197+
```json
198+
{
199+
"name": "add_numbers",
200+
"has_output_schema": true
201+
}
202+
```
203+
204+
### 9. View Exported outputSchema
205+
206+
```bash
207+
jq '.tools[] | select(.name == "add_numbers") | .output_schema' /tmp/tools-export.json
208+
```
209+
210+
### 10. Count Tools with outputSchema
211+
212+
```bash
213+
curl -s -H "Authorization: Bearer $TOKEN" \
214+
http://localhost:4444/tools | \
215+
jq '[.[] | select(.outputSchema != null)] | length'
216+
```
217+
218+
## Database Validation
219+
220+
### 11. Check Database Schema
221+
222+
```bash
223+
sqlite3 mcp.db "PRAGMA table_info(tools);" | grep output_schema
224+
```
225+
226+
**Expected Output**:
227+
```
228+
12|output_schema|JSON|1||0
229+
```
230+
231+
### 12. Query outputSchema from Database
232+
233+
```bash
234+
sqlite3 mcp.db "SELECT name, output_schema FROM tools WHERE name='add_numbers';"
235+
```
236+
237+
## Complete Test Script
238+
239+
Save this as `test-output-schema.sh`:
240+
241+
```bash
242+
#!/bin/bash
243+
244+
# Generate token
245+
export TOKEN=$(python3 -m mcpgateway.utils.create_jwt_token --username [email protected] --exp 0 --secret changeme123 2>/dev/null | head -1)
246+
247+
echo "=== Testing outputSchema Implementation ==="
248+
echo ""
249+
250+
echo "1. Listing all tools with outputSchema status..."
251+
curl -s -H "Authorization: Bearer $TOKEN" \
252+
http://localhost:4444/tools | \
253+
jq '.[] | select(.name | contains("_numbers") or contains("create_user") or contains("validate") or . == "echo") | {name, has_outputSchema: (.outputSchema != null)}'
254+
255+
echo ""
256+
echo "2. Viewing add_numbers outputSchema..."
257+
curl -s -H "Authorization: Bearer $TOKEN" \
258+
http://localhost:4444/tools | \
259+
jq '.[] | select(.name == "add_numbers") | .outputSchema | keys'
260+
261+
echo ""
262+
echo "3. Invoking add_numbers tool..."
263+
curl -s -X POST -H "Authorization: Bearer $TOKEN" \
264+
-H "Content-Type: application/json" \
265+
http://localhost:4444/tools/invoke \
266+
-d '{"name": "add_numbers", "arguments": {"a": 10, "b": 5}}' | jq '.content[0].text | fromjson'
267+
268+
echo ""
269+
echo "4. Invoking create_user tool..."
270+
curl -s -X POST -H "Authorization: Bearer $TOKEN" \
271+
-H "Content-Type: application/json" \
272+
http://localhost:4444/tools/invoke \
273+
-d '{"name": "create_user", "arguments": {"name": "Test User", "email": "[email protected]", "age": 25, "roles": ["user"]}}' | jq '.content[0].text | fromjson'
274+
275+
echo ""
276+
echo "5. Checking export includes outputSchema..."
277+
curl -s -H "Authorization: Bearer $TOKEN" \
278+
http://localhost:4444/bulk/export | \
279+
jq '.tools[] | select(.name == "add_numbers") | has("output_schema")'
280+
281+
echo ""
282+
echo "=== All Tests Complete ==="
283+
```
284+
285+
Run it:
286+
```bash
287+
chmod +x test-output-schema.sh
288+
./test-output-schema.sh
289+
```
290+
291+
## Troubleshooting
292+
293+
### Token expired or invalid
294+
```bash
295+
# Generate new token
296+
export TOKEN=$(python3 -m mcpgateway.utils.create_jwt_token --username [email protected] --exp 0 --secret changeme123 2>/dev/null | head -1)
297+
```
298+
299+
### Gateway not running
300+
```bash
301+
# Check if gateway is running
302+
curl -s http://localhost:4444/health
303+
304+
# Start gateway
305+
make dev
306+
```
307+
308+
### Tools not showing up
309+
```bash
310+
# Check gateway registration
311+
curl -s -H "Authorization: Bearer $TOKEN" \
312+
http://localhost:4444/gateways | jq '.'
313+
314+
# Check if test server is running
315+
ps aux | grep output_schema_test_server
316+
```
317+
318+
### outputSchema is null when it shouldn't be
319+
```bash
320+
# Check database migration
321+
sqlite3 mcp.db "SELECT sql FROM sqlite_master WHERE name='tools';" | grep output_schema
322+
323+
# Re-discover tools from gateway
324+
curl -X POST -H "Authorization: Bearer $TOKEN" \
325+
http://localhost:4444/gateways/{gateway-id}/refresh
326+
```

0 commit comments

Comments
 (0)