1+ #! /bin/bash
2+
3+ # Demo script to showcase per-user tool filtering in ASP.NET Core MCP Server
4+ # Usage: ./demo.sh (make sure the server is running on localhost:3001)
5+
6+ echo " ==============================================="
7+ echo " ASP.NET Core MCP Server Per-User Tool Filter Demo"
8+ echo " ==============================================="
9+ echo " "
10+
11+ BASE_URL=" http://localhost:3001"
12+ HEADERS_JSON=(-H " Content-Type: application/json" -H " Accept: application/json, text/event-stream" )
13+ LIST_TOOLS=' {"jsonrpc":"2.0","id":1,"method":"tools/list"}'
14+
15+ echo " 1. Testing ANONYMOUS user (no authentication headers):"
16+ echo " Expected tools: echo, get_time (2 total)"
17+ echo " ---"
18+ response=$( curl -s -X POST " $BASE_URL /" " ${HEADERS_JSON[@]} " -d " $LIST_TOOLS " )
19+ tool_count=$( echo " $response " | grep -o ' "name":"[^"]*"' | wc -l)
20+ echo " Tools available: $tool_count "
21+ echo " $response " | grep -o ' "name":"[^"]*"' | sed ' s/"name":"/ - /' | sed ' s/"//'
22+ echo " "
23+
24+ echo " 2. Testing REGULAR USER (user role):"
25+ echo " Expected tools: echo, get_time, calculate, get_user_info (4 total)"
26+ echo " ---"
27+ USER_HEADERS=(-H " X-User-Role: user" -H " X-User-Id: user-alice" )
28+ response=$( curl -s -X POST " $BASE_URL /" " ${HEADERS_JSON[@]} " " ${USER_HEADERS[@]} " -d " $LIST_TOOLS " )
29+ tool_count=$( echo " $response " | grep -o ' "name":"[^"]*"' | wc -l)
30+ echo " Tools available: $tool_count "
31+ echo " $response " | grep -o ' "name":"[^"]*"' | sed ' s/"name":"/ - /' | sed ' s/"//'
32+ echo " "
33+
34+ echo " 3. Testing ADMIN USER (admin role):"
35+ echo " Expected tools: all 7 tools including admin-only ones"
36+ echo " ---"
37+ ADMIN_HEADERS=(-H " X-User-Role: admin" -H " X-User-Id: admin-john" )
38+ response=$( curl -s -X POST " $BASE_URL /" " ${HEADERS_JSON[@]} " " ${ADMIN_HEADERS[@]} " -d " $LIST_TOOLS " )
39+ tool_count=$( echo " $response " | grep -o ' "name":"[^"]*"' | wc -l)
40+ echo " Tools available: $tool_count "
41+ echo " $response " | grep -o ' "name":"[^"]*"' | sed ' s/"name":"/ - /' | sed ' s/"//'
42+ echo " "
43+
44+ echo " 4. Testing tool execution - Admin calling system status:"
45+ echo " ---"
46+ CALL_ADMIN_TOOL=' {"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"get_system_status","arguments":{}}}'
47+ response=$( curl -s -X POST " $BASE_URL /" " ${HEADERS_JSON[@]} " " ${ADMIN_HEADERS[@]} " -d " $CALL_ADMIN_TOOL " )
48+ echo " $response " | grep -o ' "text":"[^"]*"' | sed ' s/"text":"/' | sed ' s/"//' | head -1
49+ echo " "
50+
51+ echo " 5. Testing tool execution - User calling calculator:"
52+ echo " ---"
53+ CALL_USER_TOOL=' {"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"calculate","arguments":{"expression":"10 + 15"}}}'
54+ response=$( curl -s -X POST " $BASE_URL /" " ${HEADERS_JSON[@]} " " ${USER_HEADERS[@]} " -d " $CALL_USER_TOOL " )
55+ echo " $response " | grep -o ' "text":"[^"]*"' | sed ' s/"text":"/' | sed ' s/"//' | head -1
56+ echo " "
57+
58+ echo " ==============================================="
59+ echo " Demo completed! Per-user tool filtering working correctly."
60+ echo " ==============================================="
0 commit comments