|
| 1 | +# MCP Gateway - Basic |
| 2 | + |
| 3 | +Test script for MCP Gateway development environments. |
| 4 | +Verifies API readiness, JWT auth, Gateway/Tool/Server lifecycle, and RPC invocation. |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +## 🔧 Environment Setup |
| 9 | + |
| 10 | +### 0. Bootstrap `.env` |
| 11 | + |
| 12 | +```bash |
| 13 | +cp .env.example .env |
| 14 | +``` |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +### 1. Start the Gateway |
| 19 | + |
| 20 | +```bash |
| 21 | +make podman podman-run-ssl |
| 22 | +# or |
| 23 | +make venv install serve-ssl |
| 24 | +``` |
| 25 | + |
| 26 | +Gateway will listen on: |
| 27 | + |
| 28 | +* Admin UI → [https://localhost:4444/admin](https://localhost:4444/admin) |
| 29 | +* Swagger → [https://localhost:4444/docs](https://localhost:4444/docs) |
| 30 | +* ReDoc → [https://localhost:4444/redoc](https://localhost:4444/redoc) |
| 31 | + |
| 32 | +--- |
| 33 | + |
| 34 | +## 🔑 Authentication |
| 35 | + |
| 36 | +### 2. Generate and export tokens |
| 37 | + |
| 38 | +#### Gateway JWT (for local API access) |
| 39 | + |
| 40 | +```bash |
| 41 | +export MCPGATEWAY_BEARER_TOKEN=$(python -m mcpgateway.utils.create_jwt_token -u admin) |
| 42 | +curl -k -H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" https://localhost:4444/health |
| 43 | +``` |
| 44 | + |
| 45 | +Expected: `{"status":"ok"}` |
| 46 | + |
| 47 | +#### Remote gateway token (peer) |
| 48 | + |
| 49 | +```bash |
| 50 | +export MY_MCP_TOKEN="sse-bearer-token-here..." |
| 51 | +``` |
| 52 | + |
| 53 | +#### Optional: local test server token (GitHub MCP server) |
| 54 | + |
| 55 | +```bash |
| 56 | +export LOCAL_MCP_URL="http://localhost:8000/sse" |
| 57 | +export LOCAL_MCP_TOOL_URL="http://localhost:9000/rpc" |
| 58 | +``` |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +### 3. Set convenience variables |
| 63 | + |
| 64 | +```bash |
| 65 | +export BASE_URL="https://localhost:4444" |
| 66 | +export AUTH_HEADER="Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" |
| 67 | +export JSON="Content-Type: application/json" |
| 68 | +``` |
| 69 | + |
| 70 | +--- |
| 71 | + |
| 72 | +## 🧪 Smoke Tests |
| 73 | + |
| 74 | +### 4. Ping JSON-RPC system |
| 75 | + |
| 76 | +```bash |
| 77 | +curl -k -X POST $BASE_URL/protocol/ping \ |
| 78 | + -H "$AUTH_HEADER" -H "$JSON" \ |
| 79 | + -d '{"jsonrpc":"2.0","id":1,"method":"ping"}' |
| 80 | +``` |
| 81 | + |
| 82 | +--- |
| 83 | + |
| 84 | +### 5. Add a Peer Gateway |
| 85 | + |
| 86 | +```bash |
| 87 | +curl -k -X POST $BASE_URL/gateways \ |
| 88 | + -H "$AUTH_HEADER" -H "$JSON" \ |
| 89 | + -d '{ |
| 90 | + "name": "my-mcp", |
| 91 | + "url": "https://link-to-remote-mcp-server/sse", |
| 92 | + "description": "My MCP Servers", |
| 93 | + "auth_type": "bearer", |
| 94 | + "auth_token": "'"$MY_MCP_TOKEN"'" |
| 95 | + }' |
| 96 | +``` |
| 97 | + |
| 98 | +List gateways: |
| 99 | + |
| 100 | +```bash |
| 101 | +curl -k -H "$AUTH_HEADER" $BASE_URL/gateways |
| 102 | +``` |
| 103 | + |
| 104 | +--- |
| 105 | + |
| 106 | +### 6. Add a Tool |
| 107 | + |
| 108 | +```bash |
| 109 | +curl -k -X POST $BASE_URL/tools \ |
| 110 | + -H "$AUTH_HEADER" -H "$JSON" \ |
| 111 | + -d '{ |
| 112 | + "name": "clock_tool", |
| 113 | + "url": "'"$LOCAL_MCP_TOOL_URL"'", |
| 114 | + "description": "Returns current time", |
| 115 | + "request_type": "POST", |
| 116 | + "integration_type": "MCP", |
| 117 | + "input_schema": { |
| 118 | + "type": "object", |
| 119 | + "properties": { |
| 120 | + "timezone": { "type": "string" } |
| 121 | + } |
| 122 | + } |
| 123 | + }' |
| 124 | +``` |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +### 7. Create a Virtual Server |
| 129 | + |
| 130 | +```bash |
| 131 | +curl -k -X POST $BASE_URL/servers \ |
| 132 | + -H "$AUTH_HEADER" -H "$JSON" \ |
| 133 | + -d '{ |
| 134 | + "name": "demo-server", |
| 135 | + "description": "Smoke-test virtual server", |
| 136 | + "icon": "mdi-server", |
| 137 | + "associatedTools": ["1"] |
| 138 | + }' |
| 139 | +``` |
| 140 | + |
| 141 | +Check: |
| 142 | + |
| 143 | +```bash |
| 144 | +curl -k -H "$AUTH_HEADER" $BASE_URL/servers |
| 145 | +``` |
| 146 | + |
| 147 | +--- |
| 148 | + |
| 149 | +### 8. Open an SSE stream |
| 150 | + |
| 151 | +```bash |
| 152 | +curl -k -N -H "$AUTH_HEADER" $BASE_URL/servers/1/sse |
| 153 | +``` |
| 154 | + |
| 155 | +Leave running - real-time events appear here. |
| 156 | + |
| 157 | +--- |
| 158 | + |
| 159 | +### 9. Invoke the Tool via RPC |
| 160 | + |
| 161 | +```bash |
| 162 | +curl -k -X POST $BASE_URL/rpc \ |
| 163 | + -H "$AUTH_HEADER" -H "$JSON" \ |
| 164 | + -d '{ |
| 165 | + "jsonrpc": "2.0", |
| 166 | + "id": 99, |
| 167 | + "method": "clock_tool", |
| 168 | + "params": { |
| 169 | + "timezone": "Europe/Dublin" |
| 170 | + } |
| 171 | + }' |
| 172 | +``` |
| 173 | + |
| 174 | +Expected: |
| 175 | + |
| 176 | +```json |
| 177 | +{ |
| 178 | + "jsonrpc": "2.0", |
| 179 | + "id": 99, |
| 180 | + "result": { |
| 181 | + "time": "2025-05-27T14:23:01+01:00" |
| 182 | + } |
| 183 | +} |
| 184 | +``` |
| 185 | + |
| 186 | +--- |
| 187 | + |
| 188 | +## 🧹 Cleanup |
| 189 | + |
| 190 | +```bash |
| 191 | +curl -k -X DELETE -H "$AUTH_HEADER" $BASE_URL/servers/1 |
| 192 | +curl -k -X DELETE -H "$AUTH_HEADER" $BASE_URL/tools/1 |
| 193 | +curl -k -X DELETE -H "$AUTH_HEADER" $BASE_URL/gateways/1 |
| 194 | +``` |
| 195 | + |
| 196 | +--- |
| 197 | + |
| 198 | +## ✅ Summary |
| 199 | + |
| 200 | +This smoke test validates: |
| 201 | + |
| 202 | +* ✅ Gateway JWT auth |
| 203 | +* ✅ Peer Gateway registration with remote bearer |
| 204 | +* ✅ Tool registration and RPC wiring |
| 205 | +* ✅ Virtual server creation |
| 206 | +* ✅ SSE subscription and live messaging |
| 207 | +* ✅ JSON-RPC invocation flow |
| 208 | + |
| 209 | +--- |
0 commit comments