-
Notifications
You must be signed in to change notification settings - Fork 420
Improved Error for Add tool and edit Tool #569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: RAKHI DUTTA <[email protected]>
Signed-off-by: RAKHI DUTTA <[email protected]>
Signed-off-by: RAKHI DUTTA <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rakdutta I tried this flow
Step 1: Add a REST tool
name: test
url: http://example.com
integration type: REST
request type: GET
Step 2: Add a second REST tool
name: test2
url: http://example.com
integration type: REST
request type: GET
Step 3: Modify second REST tool name to 'test'
Noticed 2 issues
- It should show duplicate name error message, showing invalid input
- Error is showing in a new page instead of the current one.
Signed-off-by: RAKHI DUTTA <[email protected]>
|
@madhav165 |
|
@rakdutta Getting the correct error message, but still redirecting to a new page. |
|
@madhav165 |
|
Could we check if all tests are still present please? |
Signed-off-by: RAKHI DUTTA <[email protected]>
Signed-off-by: RAKHI DUTTA <[email protected]>
|
@madhav165 |
Signed-off-by: RAKHI DUTTA <[email protected]>
|
Hi @rakdutta / @rakdutta1 ,
Can you please recheck? Summary Below:
Your code has been rated at 9.98/10 (previous run: 10.00/10, -0.02) ************* Module mcpgateway.schemas
============================short test summary info ================== |
|
@MohanLaksh |
Signed-off-by: RAKHI DUTTA <[email protected]>
Signed-off-by: RAKHI DUTTA <[email protected]>
|
@madhav165 @MohanLaksh
Fixed failing test cases in test_tool_service.py The following pylint errors have already been addressed in PR #577 by @TS0713: |
PR Review Summary
✅ Overall Assessment: APPROVED with minor recommendationsThis PR successfully refactors the tool registration and editing flow to use database-level constraint checking instead of application-level duplicate checks. The changes are well-implemented across the entire stack. Key Changes Verified:
Recommendations Before Merge:
Technical Notes:
Pre-Merge ChecklistDatabase Schema
Error Formatting
Frontend
Test Coverage
Final Verification
|
Quick Testexport MCPGATEWAY_BEARER_TOKEN=$(python3 -m mcpgateway.utils.create_jwt_token -u admin --secret my-test-key)✅ 1. First, create a tool (this should succeed):curl -X POST http://localhost:4444/admin/tools/ \
-H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "name=test_tool&url=http://example.com&requestType=POST&integrationType=REST"✅ 2. Try to create the SAME tool again (this should fail with 409):curl -X POST http://localhost:4444/admin/tools/ \
-H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "name=test_tool&url=http://different.com&requestType=GET&integrationType=REST"Expected response: {
"message": "A tool with this name already exists",
"success": false
}✅ 3. Test editing a tool to conflict with another name:First, create a second tool: curl -X POST http://localhost:4444/admin/tools/ \
-H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "name=another_tool&url=http://another.com&requestType=PUT&integrationType=REST"Then get the tool id: curl -H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" http://localhost:4444/admin/tools | jq Then try to edit it to have the same name as the first tool (replace curl -X POST http://localhost:4444/admin/tools/{tool_id}/edit/ \
-H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "name=test_tool&url=http://another.com&requestType=DELETE&integrationType=REST" |
#!/bin/bash
# Check if token is set
if [ -z "$MCPGATEWAY_BEARER_TOKEN" ]; then
echo "Error: MCPGATEWAY_BEARER_TOKEN not set"
echo "Run: export MCPGATEWAY_BEARER_TOKEN='your-token-here'"
exit 1
fi
BASE_URL="http://localhost:4444"
AUTH="Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN"
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to make requests and handle responses properly
make_request() {
local method="$1"
local endpoint="$2"
local data="$3"
local expected_status="$4"
local test_name="$5"
echo -e "\n${YELLOW}=== $test_name ===${NC}"
# Make request and capture response with status
local response
response=$(curl -s -w "\n__STATUS__%{http_code}" -X "$method" "$BASE_URL$endpoint" \
-H "$AUTH" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "$data" 2>/dev/null)
# Extract body and status
local body=$(echo "$response" | sed -n '1,/__STATUS__/p' | sed '$d')
local status=$(echo "$response" | grep -o '__STATUS__[0-9]*' | sed 's/__STATUS__//')
# Display results
echo "HTTP Status: $status"
echo "Response:"
echo "$body" | jq . 2>/dev/null || echo "$body"
# Check if status matches expected
if [ "$status" = "$expected_status" ]; then
echo -e "${GREEN}✓ Status matches expected: $expected_status${NC}"
else
echo -e "${RED}✗ Expected status $expected_status but got $status${NC}"
fi
# Return status for further processing
echo "$status"
}
# Function to extract ID from JSON response
extract_id() {
local json="$1"
echo "$json" | jq -r '.id // empty' 2>/dev/null
}
echo -e "${YELLOW}Starting MCP Gateway Tool Tests${NC}"
echo "Using endpoint: $BASE_URL"
# Test 1: Create a valid tool
echo -e "\n${YELLOW}Test 1: Create Valid Tool${NC}"
RESPONSE1=$(curl -s -X POST "$BASE_URL/admin/tools/" \
-H "$AUTH" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "name=test_tool_1&url=http://example.com&requestType=POST&integrationType=REST")
echo "$RESPONSE1" | jq . 2>/dev/null || echo "$RESPONSE1"
TOOL1_ID=$(extract_id "$RESPONSE1")
echo "Created tool ID: $TOOL1_ID"
# Test 2: Try to create duplicate (should fail with 409)
make_request "POST" "/admin/tools/" \
"name=test_tool_1&url=http://different.com&requestType=GET&integrationType=REST" \
"409" \
"Test 2: Duplicate Tool Name (Should Fail)"
# Test 3: Create second tool with different name
echo -e "\n${YELLOW}Test 3: Create Second Tool${NC}"
RESPONSE3=$(curl -s -X POST "$BASE_URL/admin/tools/" \
-H "$AUTH" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "name=test_tool_2&url=http://another.com&requestType=PUT&integrationType=REST")
echo "$RESPONSE3" | jq . 2>/dev/null || echo "$RESPONSE3"
TOOL2_ID=$(extract_id "$RESPONSE3")
echo "Created tool ID: $TOOL2_ID"
# Test 4: Edit tool to conflict with existing name
if [ -n "$TOOL2_ID" ]; then
make_request "POST" "/admin/tools/$TOOL2_ID/edit/" \
"name=test_tool_1&url=http://edited.com&requestType=DELETE&integrationType=REST" \
"409" \
"Test 4: Edit Tool to Existing Name (Should Fail)"
fi
# Test 5: Successful edit with unique name
if [ -n "$TOOL2_ID" ]; then
make_request "POST" "/admin/tools/$TOOL2_ID/edit/" \
"name=test_tool_2_edited&url=http://edited.com&requestType=PATCH&integrationType=REST" \
"200" \
"Test 5: Edit Tool with Unique Name (Should Succeed)"
fi
# Test 6: Validation errors
make_request "POST" "/admin/tools/" \
"name=missing_url&requestType=POST&integrationType=REST" \
"422" \
"Test 6: Missing URL (Validation Error)"
make_request "POST" "/admin/tools/" \
"url=http://example.com&requestType=POST&integrationType=REST" \
"422" \
"Test 7: Missing Name (Validation Error)"
make_request "POST" "/admin/tools/" \
"name=invalid_combo&url=http://example.com&requestType=SSE&integrationType=REST" \
"422" \
"Test 8: Invalid REST+SSE Combination"
# Test 9: Special characters
make_request "POST" "/admin/tools/" \
"name=test_with_underscore&url=http://example.com&requestType=POST&integrationType=REST" \
"200" \
"Test 9: Name with Underscore"
make_request "POST" "/admin/tools/" \
"name=test-with-hyphen&url=http://example.com&requestType=POST&integrationType=REST" \
"200" \
"Test 10: Name with Hyphen"
# Test 11: Concurrent duplicate attempts
echo -e "\n${YELLOW}Test 11: Concurrent Duplicate Attempts${NC}"
echo "Launching 5 parallel requests for the same tool name..."
for i in {1..5}; do
(
RESPONSE=$(curl -s -w "\n__STATUS__%{http_code}" -X POST "$BASE_URL/admin/tools/" \
-H "$AUTH" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "name=concurrent_test&url=http://concurrent$i.com&requestType=POST&integrationType=REST" 2>/dev/null)
STATUS=$(echo "$RESPONSE" | grep -o '__STATUS__[0-9]*' | sed 's/__STATUS__//')
echo "Request $i: Status $STATUS"
) &
done
wait
echo -e "\n${YELLOW}Test Summary Complete${NC}"
echo "All tests have been executed. Check the results above."Results |
|
Looks good to merge, this will need further testing downstream, but for now - merging the PR. |
* 363 tool Signed-off-by: RAKHI DUTTA <[email protected]> * tool 363 Signed-off-by: RAKHI DUTTA <[email protected]> * 363_tool Signed-off-by: RAKHI DUTTA <[email protected]> * ToolUpdate Signed-off-by: RAKHI DUTTA <[email protected]> * revert test_tool_service with main version Signed-off-by: RAKHI DUTTA <[email protected]> * admin.js changes for edit_tool Signed-off-by: RAKHI DUTTA <[email protected]> * update test_admin Signed-off-by: RAKHI DUTTA <[email protected]> * flake8 error fix Signed-off-by: RAKHI DUTTA <[email protected]> * test cases update Signed-off-by: RAKHI DUTTA <[email protected]> --------- Signed-off-by: RAKHI DUTTA <[email protected]> Co-authored-by: RAKHI DUTTA <[email protected]>
* 363 tool Signed-off-by: RAKHI DUTTA <[email protected]> * tool 363 Signed-off-by: RAKHI DUTTA <[email protected]> * 363_tool Signed-off-by: RAKHI DUTTA <[email protected]> * ToolUpdate Signed-off-by: RAKHI DUTTA <[email protected]> * revert test_tool_service with main version Signed-off-by: RAKHI DUTTA <[email protected]> * admin.js changes for edit_tool Signed-off-by: RAKHI DUTTA <[email protected]> * update test_admin Signed-off-by: RAKHI DUTTA <[email protected]> * flake8 error fix Signed-off-by: RAKHI DUTTA <[email protected]> * test cases update Signed-off-by: RAKHI DUTTA <[email protected]> --------- Signed-off-by: RAKHI DUTTA <[email protected]> Co-authored-by: RAKHI DUTTA <[email protected]>
* 363 tool Signed-off-by: RAKHI DUTTA <[email protected]> * tool 363 Signed-off-by: RAKHI DUTTA <[email protected]> * 363_tool Signed-off-by: RAKHI DUTTA <[email protected]> * ToolUpdate Signed-off-by: RAKHI DUTTA <[email protected]> * revert test_tool_service with main version Signed-off-by: RAKHI DUTTA <[email protected]> * admin.js changes for edit_tool Signed-off-by: RAKHI DUTTA <[email protected]> * update test_admin Signed-off-by: RAKHI DUTTA <[email protected]> * flake8 error fix Signed-off-by: RAKHI DUTTA <[email protected]> * test cases update Signed-off-by: RAKHI DUTTA <[email protected]> --------- Signed-off-by: RAKHI DUTTA <[email protected]> Co-authored-by: RAKHI DUTTA <[email protected]>

Refactored admin.py for both add and edit tool routers:
Updated admin_add_tool and admin_edit_tool functions to handle ValidationError and IntegrityError exceptions
Updated mcpgateway/services/tool_service.py:
Update the below test file to handle new error code for Add tool and Edit Tool function
1)test_admin_api.py
2)test_admin.py
3)test_main.py
4)test_tool_service.py