Skip to content

Commit bf7406f

Browse files
RahulHereRahulHere
authored andcommitted
Test MCP Inspector Flow (#130)
- Created comprehensive test suite for MCP Inspector OAuth flow - Implemented test for Connect triggering authentication - Added test for connection without auth when disabled - Created successful authentication and session creation test - Implemented Authorization header verification test - Added tool authorization with scope validation tests - Created token expiration handling test - Implemented multiple tool invocation test - Added weather tool scope requirement tests - Created session persistence test across reconnects - Implemented invalid token handling test - Added OAuth endpoint compliance verification - Created MCP Inspector client simulator class - Implemented mock token generation for testing - Added test runner script with configuration
1 parent f2d9cc1 commit bf7406f

File tree

3 files changed

+633
-0
lines changed

3 files changed

+633
-0
lines changed

tests/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ add_executable(test_memory_cache auth/test_memory_cache.cc)
1111
add_executable(test_http_client auth/test_http_client.cc)
1212
add_executable(test_jwks_client auth/test_jwks_client.cc)
1313
add_executable(test_keycloak_integration auth/test_keycloak_integration.cc)
14+
add_executable(test_mcp_inspector_flow auth/test_mcp_inspector_flow.cc)
1415
add_executable(test_variant core/test_variant.cc)
1516
add_executable(test_variant_extensive core/test_variant_extensive.cc)
1617
add_executable(test_variant_advanced core/test_variant_advanced.cc)
@@ -188,6 +189,14 @@ target_link_libraries(test_keycloak_integration
188189
CURL::libcurl
189190
)
190191

192+
target_link_libraries(test_mcp_inspector_flow
193+
gopher_mcp_c
194+
gtest
195+
gtest_main
196+
Threads::Threads
197+
CURL::libcurl
198+
)
199+
191200
target_link_libraries(test_variant
192201
gtest
193202
gtest_main
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
# Script to run MCP Inspector OAuth flow tests
3+
4+
# Configuration
5+
MCP_SERVER_URL=${MCP_SERVER_URL:-"http://localhost:3000"}
6+
AUTH_SERVER_URL=${AUTH_SERVER_URL:-"http://localhost:8080/realms/master"}
7+
OAUTH_CLIENT_ID=${OAUTH_CLIENT_ID:-"mcp-inspector"}
8+
OAUTH_CLIENT_SECRET=${OAUTH_CLIENT_SECRET:-"mcp-secret"}
9+
OAUTH_REDIRECT_URI=${OAUTH_REDIRECT_URI:-"http://localhost:5173/auth/callback"}
10+
REQUIRE_AUTH_ON_CONNECT=${REQUIRE_AUTH_ON_CONNECT:-"true"}
11+
12+
# Colors for output
13+
RED='\033[0;31m'
14+
GREEN='\033[0;32m'
15+
YELLOW='\033[1;33m'
16+
BLUE='\033[0;34m'
17+
NC='\033[0m' # No Color
18+
19+
echo "========================================="
20+
echo "MCP Inspector OAuth Flow Test Runner"
21+
echo "========================================="
22+
echo ""
23+
echo "Configuration:"
24+
echo " MCP Server URL: $MCP_SERVER_URL"
25+
echo " Auth Server URL: $AUTH_SERVER_URL"
26+
echo " Client ID: $OAUTH_CLIENT_ID"
27+
echo " Redirect URI: $OAUTH_REDIRECT_URI"
28+
echo " Require Auth on Connect: $REQUIRE_AUTH_ON_CONNECT"
29+
echo ""
30+
31+
# Export environment variables
32+
export MCP_SERVER_URL
33+
export AUTH_SERVER_URL
34+
export OAUTH_CLIENT_ID
35+
export OAUTH_CLIENT_SECRET
36+
export OAUTH_REDIRECT_URI
37+
export REQUIRE_AUTH_ON_CONNECT
38+
39+
# Run test executable
40+
TEST_BINARY="../../build/tests/test_mcp_inspector_flow"
41+
42+
if [ ! -f "$TEST_BINARY" ]; then
43+
echo -e "${RED}Test binary not found at $TEST_BINARY${NC}"
44+
echo "Please build the tests first:"
45+
echo " cd ../../build && make test_mcp_inspector_flow"
46+
exit 1
47+
fi
48+
49+
echo "Running OAuth flow tests..."
50+
echo "========================================="
51+
52+
# Run tests
53+
$TEST_BINARY --gtest_color=yes
54+
55+
TEST_RESULT=$?
56+
57+
echo ""
58+
echo "========================================="
59+
echo "Test Summary:"
60+
echo ""
61+
62+
if [ $TEST_RESULT -eq 0 ]; then
63+
echo -e "${GREEN}✅ All OAuth flow tests passed!${NC}"
64+
echo ""
65+
echo "The authentication flow is working correctly:"
66+
echo " • Connect triggers authentication when required"
67+
echo " • Tokens are properly validated"
68+
echo " • Authorization headers are correctly formatted"
69+
echo " • Tool scopes are enforced"
70+
echo " • Token expiration is handled"
71+
else
72+
echo -e "${RED}❌ Some OAuth flow tests failed!${NC}"
73+
echo ""
74+
echo "Please check:"
75+
echo " • OAuth server configuration"
76+
echo " • Client credentials"
77+
echo " • JWKS endpoint accessibility"
78+
fi
79+
80+
echo "========================================="
81+
82+
# Additional validation info
83+
if [ "$REQUIRE_AUTH_ON_CONNECT" == "true" ]; then
84+
echo ""
85+
echo -e "${BLUE}ℹ️ Authentication Required Mode${NC}"
86+
echo "MCP Inspector will require authentication on connect."
87+
echo "This ensures all tools are protected by default."
88+
else
89+
echo ""
90+
echo -e "${YELLOW}⚠️ Authentication Optional Mode${NC}"
91+
echo "MCP Inspector allows connection without authentication."
92+
echo "Individual tools may still require authentication."
93+
fi
94+
95+
exit $TEST_RESULT

0 commit comments

Comments
 (0)