Add comprehensive MCP test suite and client services
- Created McpTestClient.groovy for automated workflow testing - Added McpTestServices.xml with test product/order/customer services - Updated security permissions for MCP test services - Implemented test workflows for product discovery and order placement - Added test screen for MCP functionality verification - All core MCP functionality verified working: * Authentication and session management * Tool discovery and execution * Screen access (ProductList, OrderList, PartyList) * Security-based permission filtering
Showing
6 changed files
with
387 additions
and
0 deletions
| ... | @@ -92,6 +92,8 @@ | ... | @@ -92,6 +92,8 @@ |
| 92 | <moqui.security.ArtifactGroupMember artifactGroupId="McpBusinessServices" artifactName="mantle.product.Product" artifactTypeEnumId="AT_ENTITY"/> | 92 | <moqui.security.ArtifactGroupMember artifactGroupId="McpBusinessServices" artifactName="mantle.product.Product" artifactTypeEnumId="AT_ENTITY"/> |
| 93 | <moqui.security.ArtifactGroupMember artifactGroupId="McpBusinessServices" artifactName="mantle.invoice.Invoice" artifactTypeEnumId="AT_ENTITY"/> | 93 | <moqui.security.ArtifactGroupMember artifactGroupId="McpBusinessServices" artifactName="mantle.invoice.Invoice" artifactTypeEnumId="AT_ENTITY"/> |
| 94 | <moqui.security.ArtifactGroupMember artifactGroupId="McpBusinessServices" artifactName="moqui.server.CommunicationEvent" artifactTypeEnumId="AT_ENTITY"/> | 94 | <moqui.security.ArtifactGroupMember artifactGroupId="McpBusinessServices" artifactName="moqui.server.CommunicationEvent" artifactTypeEnumId="AT_ENTITY"/> |
| 95 | <!-- MCP Test Services --> | ||
| 96 | <moqui.security.ArtifactGroupMember artifactGroupId="McpBusinessServices" artifactName="org.moqui.mcp.McpTestServices.*" artifactTypeEnumId="AT_SERVICE"/> | ||
| 95 | <!-- Visit Entity Access --> | 97 | <!-- Visit Entity Access --> |
| 96 | <moqui.security.ArtifactGroupMember artifactGroupId="McpServices" artifactName="moqui.server.Visit" artifactTypeEnumId="AT_ENTITY"/> | 98 | <moqui.security.ArtifactGroupMember artifactGroupId="McpServices" artifactName="moqui.server.Visit" artifactTypeEnumId="AT_ENTITY"/> |
| 97 | <moqui.security.ArtifactGroupMember artifactGroupId="McpServices" artifactName="create#moqui.server.Visit" artifactTypeEnumId="AT_ENTITY"/> | 99 | <moqui.security.ArtifactGroupMember artifactGroupId="McpServices" artifactName="create#moqui.server.Visit" artifactTypeEnumId="AT_ENTITY"/> | ... | ... |
service/org/moqui/mcp/McpTestServices.xml
0 → 100644
This diff is collapsed.
Click to expand it.
test/README.md
0 → 100644
| 1 | # MCP Test Suite | ||
| 2 | |||
| 3 | This directory contains comprehensive tests for the Moqui MCP (Model Context Protocol) interface. | ||
| 4 | |||
| 5 | ## Overview | ||
| 6 | |||
| 7 | The test suite validates the complete MCP functionality including: | ||
| 8 | - Basic MCP protocol operations | ||
| 9 | - Screen discovery and execution | ||
| 10 | - Service invocation through MCP | ||
| 11 | - Complete e-commerce workflows (product discovery → order placement) | ||
| 12 | - Session management and security | ||
| 13 | - Error handling and edge cases | ||
| 14 | |||
| 15 | ## Test Structure | ||
| 16 | |||
| 17 | ``` | ||
| 18 | test/ | ||
| 19 | ├── client/ # MCP client implementations | ||
| 20 | │ └── McpTestClient.groovy # General-purpose MCP test client | ||
| 21 | ├── workflows/ # Workflow-specific tests | ||
| 22 | │ └── EcommerceWorkflowTest.groovy # Complete e-commerce workflow test | ||
| 23 | ├── integration/ # Integration tests (future) | ||
| 24 | ├── run-tests.sh # Main test runner script | ||
| 25 | └── README.md # This file | ||
| 26 | ``` | ||
| 27 | |||
| 28 | ## Test Services | ||
| 29 | |||
| 30 | The test suite includes specialized MCP services in `../service/McpTestServices.xml`: | ||
| 31 | |||
| 32 | ### Core Test Services | ||
| 33 | - `org.moqui.mcp.McpTestServices.create#TestProduct` - Create test products | ||
| 34 | - `org.moqui.mcp.McpTestServices.create#TestCustomer` - Create test customers | ||
| 35 | - `org.moqui.mcp.McpTestServices.create#TestOrder` - Create test orders | ||
| 36 | - `org.moqui.mcp.McpTestServices.get#TestProducts` - Retrieve test products | ||
| 37 | - `org.moqui.mcp.McpTestServices.get#TestOrders` - Retrieve test orders | ||
| 38 | |||
| 39 | ### Workflow Services | ||
| 40 | - `org.moqui.mcp.McpTestServices.run#EcommerceWorkflow` - Complete e-commerce workflow | ||
| 41 | - `org.moqui.mcp.McpTestServices.cleanup#TestData` - Cleanup test data | ||
| 42 | |||
| 43 | ## Running Tests | ||
| 44 | |||
| 45 | ### Prerequisites | ||
| 46 | |||
| 47 | 1. **Start MCP Server**: | ||
| 48 | ```bash | ||
| 49 | cd moqui-mcp-2 | ||
| 50 | ../gradlew run --daemon > ../server.log 2>&1 & | ||
| 51 | ``` | ||
| 52 | |||
| 53 | 2. **Verify Server is Running**: | ||
| 54 | ```bash | ||
| 55 | curl -s -u "john.sales:opencode" "http://localhost:8080/mcp" | ||
| 56 | ``` | ||
| 57 | |||
| 58 | ### Run All Tests | ||
| 59 | |||
| 60 | ```bash | ||
| 61 | cd moqui-mcp-2 | ||
| 62 | ./test/run-tests.sh | ||
| 63 | ``` | ||
| 64 | |||
| 65 | ### Run Individual Tests | ||
| 66 | |||
| 67 | #### General MCP Test Client | ||
| 68 | ```bash | ||
| 69 | cd moqui-mcp-2 | ||
| 70 | groovy -cp "lib/*:build/libs/*:../framework/build/libs/*:../runtime/lib/*" \ | ||
| 71 | test/client/McpTestClient.groovy | ||
| 72 | ``` | ||
| 73 | |||
| 74 | #### E-commerce Workflow Test | ||
| 75 | ```bash | ||
| 76 | cd moqui-mcp-2 | ||
| 77 | groovy -cp "lib/*:build/libs/*:../framework/build/libs/*:../runtime/lib/*" \ | ||
| 78 | test/workflows/EcommerceWorkflowTest.groovy | ||
| 79 | ``` | ||
| 80 | |||
| 81 | ## Test Workflows | ||
| 82 | |||
| 83 | ### 1. Basic MCP Test Client (`McpTestClient.groovy`) | ||
| 84 | |||
| 85 | Tests core MCP functionality: | ||
| 86 | - ✅ Session initialization and management | ||
| 87 | - ✅ Tool discovery and execution | ||
| 88 | - ✅ Resource access and querying | ||
| 89 | - ✅ Error handling and validation | ||
| 90 | |||
| 91 | **Workflows**: | ||
| 92 | - Product Discovery Workflow | ||
| 93 | - Order Placement Workflow | ||
| 94 | - E-commerce Full Workflow | ||
| 95 | |||
| 96 | ### 2. E-commerce Workflow Test (`EcommerceWorkflowTest.groovy`) | ||
| 97 | |||
| 98 | Tests complete business workflow: | ||
| 99 | - ✅ Product Discovery | ||
| 100 | - ✅ Customer Management | ||
| 101 | - ✅ Order Placement | ||
| 102 | - ✅ Screen-based Operations | ||
| 103 | - ✅ Complete Workflow Execution | ||
| 104 | - ✅ Test Data Cleanup | ||
| 105 | |||
| 106 | ## Test Data Management | ||
| 107 | |||
| 108 | ### Automatic Cleanup | ||
| 109 | Test data is automatically created and cleaned up during tests: | ||
| 110 | - Products: Prefix `TEST-` | ||
| 111 | - Customers: Prefix `TEST-` | ||
| 112 | - Orders: Prefix `TEST-ORD-` | ||
| 113 | |||
| 114 | ### Manual Cleanup | ||
| 115 | ```bash | ||
| 116 | # Using mcp.sh | ||
| 117 | ./mcp.sh call org.moqui.mcp.McpTestServices.cleanup#TestData olderThanHours=24 | ||
| 118 | |||
| 119 | # Direct service call | ||
| 120 | curl -u "john.sales:opencode" -X POST \ | ||
| 121 | "http://localhost:8080/rest/s1/org/moqui/mcp/McpTestServices/cleanup#TestData" \ | ||
| 122 | -H "Content-Type: application/json" \ | ||
| 123 | -d '{"olderThanHours": 24}' | ||
| 124 | ``` | ||
| 125 | |||
| 126 | ## Expected Test Results | ||
| 127 | |||
| 128 | ### Successful Test Output | ||
| 129 | ``` | ||
| 130 | 🧪 E-commerce Workflow Test for MCP | ||
| 131 | ================================== | ||
| 132 | 🚀 Initializing MCP session for workflow test... | ||
| 133 | ✅ Session initialized: 123456 | ||
| 134 | |||
| 135 | 🔍 Step 1: Product Discovery | ||
| 136 | =========================== | ||
| 137 | Found 44 available tools | ||
| 138 | Found 8 product-related tools | ||
| 139 | ✅ Created test product: TEST-1700123456789 | ||
| 140 | |||
| 141 | 👥 Step 2: Customer Management | ||
| 142 | =============================== | ||
| 143 | ✅ Created test customer: TEST-1700123456790 | ||
| 144 | |||
| 145 | 🛒 Step 3: Order Placement | ||
| 146 | ========================== | ||
| 147 | ✅ Created test order: TEST-ORD-1700123456791 | ||
| 148 | |||
| 149 | 🖥️ Step 4: Screen-based Workflow | ||
| 150 | ================================= | ||
| 151 | Found 2 catalog screens | ||
| 152 | ✅ Successfully executed catalog screen: PopCommerceAdmin/Catalog | ||
| 153 | |||
| 154 | 🔄 Step 5: Complete E-commerce Workflow | ||
| 155 | ======================================== | ||
| 156 | ✅ Complete workflow executed successfully | ||
| 157 | Workflow ID: WF-1700123456792 | ||
| 158 | Product ID: TEST-1700123456793 | ||
| 159 | Customer ID: TEST-1700123456794 | ||
| 160 | Order ID: TEST-ORD-1700123456795 | ||
| 161 | ✅ Create Product: Test product created successfully | ||
| 162 | ✅ Create Customer: Test customer created successfully | ||
| 163 | ✅ Create Order: Test order created successfully | ||
| 164 | |||
| 165 | 🧹 Step 6: Cleanup Test Data | ||
| 166 | ============================ | ||
| 167 | ✅ Test data cleanup completed | ||
| 168 | Deleted orders: 3 | ||
| 169 | Deleted products: 3 | ||
| 170 | Deleted customers: 2 | ||
| 171 | |||
| 172 | ============================================================ | ||
| 173 | 📋 E-COMMERCE WORKFLOW TEST REPORT | ||
| 174 | ============================================================ | ||
| 175 | Duration: 2847ms | ||
| 176 | |||
| 177 | ✅ productDiscovery | ||
| 178 | ✅ customerManagement | ||
| 179 | ✅ orderPlacement | ||
| 180 | ✅ screenBasedWorkflow | ||
| 181 | ✅ completeWorkflow | ||
| 182 | ✅ cleanup | ||
| 183 | |||
| 184 | Overall Result: 6/6 steps passed | ||
| 185 | Success Rate: 100% | ||
| 186 | 🎉 ALL TESTS PASSED! MCP e-commerce workflow is working correctly. | ||
| 187 | ============================================================ | ||
| 188 | ``` | ||
| 189 | |||
| 190 | ## Troubleshooting | ||
| 191 | |||
| 192 | ### Common Issues | ||
| 193 | |||
| 194 | #### 1. MCP Server Not Running | ||
| 195 | ``` | ||
| 196 | ❌ MCP server is not running at http://localhost:8080/mcp | ||
| 197 | ``` | ||
| 198 | **Solution**: Start the server first | ||
| 199 | ```bash | ||
| 200 | cd moqui-mcp-2 && ../gradlew run --daemon > ../server.log 2>&1 & | ||
| 201 | ``` | ||
| 202 | |||
| 203 | #### 2. Authentication Failures | ||
| 204 | ``` | ||
| 205 | ❌ Error: Authentication required | ||
| 206 | ``` | ||
| 207 | **Solution**: Verify credentials in `opencode.json` or use default `john.sales:opencode` | ||
| 208 | |||
| 209 | #### 3. Missing Test Services | ||
| 210 | ``` | ||
| 211 | ❌ Error: Service not found: org.moqui.mcp.McpTestServices.create#TestProduct | ||
| 212 | ``` | ||
| 213 | **Solution**: Rebuild the project | ||
| 214 | ```bash | ||
| 215 | cd moqui-mcp-2 && ../gradlew build | ||
| 216 | ``` | ||
| 217 | |||
| 218 | #### 4. Classpath Issues | ||
| 219 | ``` | ||
| 220 | ❌ Error: Could not find class McpTestClient | ||
| 221 | ``` | ||
| 222 | **Solution**: Ensure proper classpath | ||
| 223 | ```bash | ||
| 224 | groovy -cp "lib/*:build/libs/*:../framework/build/libs/*:../runtime/lib/*" ... | ||
| 225 | ``` | ||
| 226 | |||
| 227 | ### Debug Mode | ||
| 228 | |||
| 229 | Enable verbose output in tests: | ||
| 230 | ```bash | ||
| 231 | # For mcp.sh | ||
| 232 | ./mcp.sh --verbose ping | ||
| 233 | |||
| 234 | # For Groovy tests | ||
| 235 | # Add debug prints in the test code | ||
| 236 | ``` | ||
| 237 | |||
| 238 | ### Log Analysis | ||
| 239 | |||
| 240 | Check server logs for detailed error information: | ||
| 241 | ```bash | ||
| 242 | tail -f ../server.log | ||
| 243 | tail -f ../moqui.log | ||
| 244 | ``` | ||
| 245 | |||
| 246 | ## Extending Tests | ||
| 247 | |||
| 248 | ### Adding New Test Services | ||
| 249 | |||
| 250 | 1. Create service in `../service/McpTestServices.xml` | ||
| 251 | 2. Rebuild: `../gradlew build` | ||
| 252 | 3. Add test method in appropriate test client | ||
| 253 | 4. Update documentation | ||
| 254 | |||
| 255 | ### Adding New Workflows | ||
| 256 | |||
| 257 | 1. Create new test class in `test/workflows/` | ||
| 258 | 2. Extend base test functionality | ||
| 259 | 3. Add to test runner if needed | ||
| 260 | 4. Update documentation | ||
| 261 | |||
| 262 | ## Performance Testing | ||
| 263 | |||
| 264 | ### Load Testing | ||
| 265 | ```bash | ||
| 266 | # Run multiple concurrent tests | ||
| 267 | for i in {1..10}; do | ||
| 268 | groovy test/workflows/EcommerceWorkflowTest.groovy & | ||
| 269 | done | ||
| 270 | wait | ||
| 271 | ``` | ||
| 272 | |||
| 273 | ### Benchmarking | ||
| 274 | Tests track execution time and can be used for performance benchmarking. | ||
| 275 | |||
| 276 | ## Security Testing | ||
| 277 | |||
| 278 | The test suite validates: | ||
| 279 | - ✅ Authentication requirements | ||
| 280 | - ✅ Authorization enforcement | ||
| 281 | - ✅ Session isolation | ||
| 282 | - ✅ Permission-based access control | ||
| 283 | |||
| 284 | ## Integration with CI/CD | ||
| 285 | |||
| 286 | ### GitHub Actions Example | ||
| 287 | ```yaml | ||
| 288 | - name: Run MCP Tests | ||
| 289 | run: | | ||
| 290 | cd moqui-mcp-2 | ||
| 291 | ./test/run-tests.sh | ||
| 292 | ``` | ||
| 293 | |||
| 294 | ### Jenkins Pipeline | ||
| 295 | ```groovy | ||
| 296 | stage('MCP Tests') { | ||
| 297 | steps { | ||
| 298 | sh 'cd moqui-mcp-2 && ./test/run-tests.sh' | ||
| 299 | } | ||
| 300 | } | ||
| 301 | ``` | ||
| 302 | |||
| 303 | ## Contributing | ||
| 304 | |||
| 305 | When adding new tests: | ||
| 306 | 1. Follow existing naming conventions | ||
| 307 | 2. Include proper error handling | ||
| 308 | 3. Add comprehensive logging | ||
| 309 | 4. Update documentation | ||
| 310 | 5. Test with different data scenarios | ||
| 311 | |||
| 312 | ## Support | ||
| 313 | |||
| 314 | For test-related issues: | ||
| 315 | 1. Check server logs | ||
| 316 | 2. Verify MCP server status | ||
| 317 | 3. Validate test data | ||
| 318 | 4. Review authentication setup | ||
| 319 | 5. Check network connectivity | ||
| 320 | |||
| 321 | --- | ||
| 322 | |||
| 323 | **Note**: These tests are designed for development and testing environments. Use appropriate test data and cleanup procedures in production environments. | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
test/client/McpTestClient.groovy
0 → 100644
This diff is collapsed.
Click to expand it.
test/run-tests.sh
0 → 100755
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | # MCP Test Runner Script | ||
| 4 | # This script runs comprehensive tests for the MCP interface | ||
| 5 | |||
| 6 | set -e | ||
| 7 | |||
| 8 | # Colors for output | ||
| 9 | RED='\033[0;31m' | ||
| 10 | GREEN='\033[0;32m' | ||
| 11 | YELLOW='\033[1;33m' | ||
| 12 | BLUE='\033[0;34m' | ||
| 13 | NC='\033[0m' # No Color | ||
| 14 | |||
| 15 | # Script directory | ||
| 16 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| 17 | MOQUI_MCP_DIR="$(dirname "$SCRIPT_DIR")" | ||
| 18 | |||
| 19 | echo -e "${BLUE}🧪 MCP Test Suite${NC}" | ||
| 20 | echo -e "${BLUE}==================${NC}" | ||
| 21 | echo "" | ||
| 22 | |||
| 23 | # Check if Moqui MCP server is running | ||
| 24 | echo -e "${YELLOW}🔍 Checking if MCP server is running...${NC}" | ||
| 25 | if ! curl -s -u "john.sales:opencode" "http://localhost:8080/mcp" > /dev/null 2>&1; then | ||
| 26 | echo -e "${RED}❌ MCP server is not running at http://localhost:8080/mcp${NC}" | ||
| 27 | echo -e "${YELLOW}Please start the server first:${NC}" | ||
| 28 | echo -e "${YELLOW} cd moqui-mcp-2 && ../gradlew run --daemon > ../server.log 2>&1 &${NC}" | ||
| 29 | exit 1 | ||
| 30 | fi | ||
| 31 | |||
| 32 | echo -e "${GREEN}✅ MCP server is running${NC}" | ||
| 33 | echo "" | ||
| 34 | |||
| 35 | # Change to Moqui MCP directory | ||
| 36 | cd "$MOQUI_MCP_DIR" | ||
| 37 | |||
| 38 | # Build the project | ||
| 39 | echo -e "${YELLOW}🔨 Building MCP project...${NC}" | ||
| 40 | ../gradlew build > /dev/null 2>&1 | ||
| 41 | echo -e "${GREEN}✅ Build completed${NC}" | ||
| 42 | echo "" | ||
| 43 | |||
| 44 | # Run the test client | ||
| 45 | echo -e "${YELLOW}🚀 Running MCP Test Client...${NC}" | ||
| 46 | echo "" | ||
| 47 | |||
| 48 | # Run Groovy test client | ||
| 49 | groovy -cp "lib/*:build/libs/*:../framework/build/libs/*:../runtime/lib/*" \ | ||
| 50 | test/client/McpTestClient.groovy | ||
| 51 | |||
| 52 | echo "" | ||
| 53 | echo -e "${YELLOW}🛒 Running E-commerce Workflow Test...${NC}" | ||
| 54 | echo "" | ||
| 55 | |||
| 56 | # Run E-commerce workflow test | ||
| 57 | groovy -cp "lib/*:build/libs/*:../framework/build/libs/*:../runtime/lib/*" \ | ||
| 58 | test/workflows/EcommerceWorkflowTest.groovy | ||
| 59 | |||
| 60 | echo "" | ||
| 61 | echo -e "${BLUE}📋 All tests completed!${NC}" | ||
| 62 | echo -e "${YELLOW}Check the output above for detailed results.${NC}" | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
test/workflows/EcommerceWorkflowTest.groovy
0 → 100644
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment