6a13c662 by Ean Schuessler

Add comprehensive README documentation

- Complete project overview and feature description
- Quick start guide with installation and usage instructions
- Tool examples for catalog, order, customer, and pricing management
- Configuration details for server and security setup
- Testing guide with test suite structure and examples
- Development documentation with project structure
- API reference for MCP protocol methods
- Security considerations and performance notes
- Troubleshooting guide for common issues
- Contributing guidelines and license information
1 parent 166bc741
Showing 1 changed file with 309 additions and 0 deletions
1 # Moqui MCP (Model Context Protocol) Implementation
2
3 A production-ready MCP interface for Moqui ERP that enables AI assistants to interact with Moqui business screens and services through recursive screen discovery.
4
5 ## Overview
6
7 This implementation provides a bridge between AI assistants and Moqui ERP by exposing Moqui screens as MCP tools. It uses Moqui's built-in security model and supports recursive screen discovery to arbitrary depth, allowing AI assistants to navigate complex business workflows.
8
9 ## Key Features
10
11 **Recursive Screen Discovery** - Automatically discovers screens to arbitrary depth (e.g., Catalog → Product → FindProduct)
12
13 **Security Model Preserved** - All subscreen access goes through parent screens, maintaining Moqui's security
14
15 **Cross-Component Support** - Handles subscreens that reference different components (e.g., PopCommerce → SimpleScreens)
16
17 **Robust Tool Naming** - Uses dot notation for first-level subscreens (`Catalog.Product`) and underscores for deeper levels (`Catalog.Product_FindProduct`)
18
19 **Accurate Tool Execution** - Uses stored actual screen paths instead of deriving from tool names
20
21 **Session Management** - Visit-based session management with proper authentication
22
23 **Comprehensive Testing** - Java-based test suite with deterministic workflows
24
25 ## Architecture
26
27 The implementation consists of:
28
29 - **EnhancedMcpServlet** - Main MCP servlet handling JSON-RPC 2.0 protocol
30 - **McpServices** - Core services for initialization, tool discovery, and execution
31 - **Screen Discovery** - Recursive screen traversal with XML parsing
32 - **Security Integration** - Moqui artifact authorization system
33 - **Test Suite** - Comprehensive Java/Groovy tests
34
35 ## Quick Start
36
37 ### Prerequisites
38
39 - Java 17+
40 - Moqui Framework
41 - Gradle
42 - PopCommerce component (for examples)
43
44 ### Installation
45
46 1. Clone the repository:
47 ```bash
48 git clone <repository-url>
49 cd moqui-mcp-2
50 ```
51
52 2. Build the component:
53 ```bash
54 ./gradlew build
55 ```
56
57 3. Start the Moqui server:
58 ```bash
59 ./gradlew run --daemon > ./server.log 2>&1 &
60 ```
61
62 4. Verify MCP server is running:
63 ```bash
64 ./mcp.sh ping
65 ```
66
67 ### Basic Usage
68
69 List available tools:
70 ```bash
71 ./mcp.sh tools
72 ```
73
74 Call a specific screen:
75 ```bash
76 ./mcp.sh call screen_PopCommerce_screen_PopCommerceAdmin.Catalog
77 ```
78
79 Search for products:
80 ```bash
81 ./mcp.sh call screen_PopCommerce_screen_PopCommerceAdmin_Catalog.Product_FindProduct
82 ```
83
84 ## Tool Examples
85
86 ### Catalog Management
87 - `screen_PopCommerce_screen_PopCommerceAdmin.Catalog` - Main catalog screen
88 - `screen_PopCommerce_screen_PopCommerceAdmin.Catalog.Product` - Product management
89 - `screen_PopCommerce_screen_PopCommerceAdmin_Catalog.Product_FindProduct` - Product search
90 - `screen_PopCommerce_screen_PopCommerceAdmin_Catalog.Category_FindCategory` - Category search
91
92 ### Order Management
93 - `screen_PopCommerce_screen_PopCommerceAdmin_Order.FindOrder` - Order lookup
94 - `screen_PopCommerce_screen_PopCommerceAdmin.Order.CreateOrder` - Create new order
95
96 ### Customer Management
97 - `screen_PopCommerce_screen_PopCommerceRoot.Customer` - Customer management
98 - `screen_PopCommerce_screen_PopCommerceAdmin.Customer.FindCustomer` - Customer search
99
100 ### Pricing
101 - `screen_PopCommerce_screen_PopCommerceAdmin_Catalog.Product_EditPrices` - Price management
102
103 ## Configuration
104
105 ### Server Configuration
106
107 The MCP server is configured via `MoquiConf.xml`:
108
109 ```xml
110 <webapp name="webroot" http-port="8080">
111 <servlet name="EnhancedMcpServlet" class="org.moqui.mcp.EnhancedMcpServlet"
112 load-on-startup="5" async-supported="true">
113 <init-param name="keepAliveIntervalSeconds" value="30"/>
114 <init-param name="maxConnections" value="100"/>
115 <url-pattern>/mcp/*</url-pattern>
116 </servlet>
117 </webapp>
118 ```
119
120 ### Security Configuration
121
122 Users need appropriate permissions to access MCP services:
123
124 - **McpUser** group - Basic MCP access
125 - **MCP_BUSINESS** group - Business toolkit access
126 - **ArtifactGroup** permissions for screen access
127
128 ## Testing
129
130 ### Running Tests
131
132 ```bash
133 # Run all tests
134 ./test/run-tests.sh
135
136 # Run only infrastructure tests
137 ./test/run-tests.sh infrastructure
138
139 # Run only workflow tests
140 ./test/run-tests.sh workflow
141
142 # Monitor test output
143 ./gradlew test > ./test.log 2>&1
144 tail -f ./test.log
145 ```
146
147 ### Test Structure
148
149 The test suite includes:
150
151 1. **Screen Infrastructure Tests** - Basic MCP connectivity, screen discovery, rendering
152 2. **PopCommerce Workflow Tests** - Complete business workflow: product lookup → order placement
153 3. **Integration Tests** - Cross-component validation
154
155 ### Test Configuration
156
157 Tests are configured via `test/resources/test-config.properties`:
158
159 ```properties
160 test.mcp.url=http://localhost:8080/mcp
161 test.user=john.sales
162 test.password=opencode
163 test.customer.firstName=John
164 test.customer.lastName=Doe
165 test.product.color=blue
166 ```
167
168 ## Development
169
170 ### Project Structure
171
172 ```
173 moqui-mcp-2/
174 ├── component.xml # Component definition
175 ├── MoquiConf.xml # Server configuration
176 ├── service/
177 │ └── McpServices.xml # Core MCP services
178 ├── src/main/groovy/org/moqui/mcp/
179 │ ├── EnhancedMcpServlet.groovy # Main MCP servlet
180 │ ├── VisitBasedMcpSession.groovy # Session management
181 │ └── ... # Supporting classes
182 ├── test/ # Test suite
183 ├── data/ # Seed data
184 ├── entity/ # Entity definitions
185 └── screen/ # Screen definitions
186 ```
187
188 ### Adding New Features
189
190 1. **New Screen Tools** - Screens are automatically discovered
191 2. **New Services** - Add to `McpServices.xml`
192 3. **New Tests** - Add to appropriate test class in `test/`
193
194 ### Debugging
195
196 Enable debug logging:
197 ```bash
198 # Check server logs
199 tail -f ./server.log
200
201 # Check MCP logs
202 tail -f ./moqui.log
203
204 # Test specific tool
205 ./mcp.sh call <tool-name>
206 ```
207
208 ## MCP Client Script
209
210 The `mcp.sh` script provides a command-line interface for testing:
211
212 ```bash
213 ./mcp.sh --help # Show help
214 ./mcp.sh --new-session # Create fresh session
215 ./mcp.sh --clear-session # Clear stored session
216 ./mcp.sh --limit 10 tools # Show first 10 tools
217 ./mcp.sh status # Show server status
218 ```
219
220 ## API Reference
221
222 ### MCP Protocol Methods
223
224 - `initialize` - Initialize MCP session
225 - `tools/list` - List available tools
226 - `tools/call` - Execute a tool
227 - `resources/list` - List available resources
228 - `resources/read` - Read a resource
229
230 ### Screen Tool Parameters
231
232 - `screenPath` - Path to the screen (required)
233 - `parameters` - Screen parameters (optional)
234 - `renderMode` - Output format: text/html/json (default: html)
235 - `subscreenName` - Target subscreen (optional)
236
237 ## Security Considerations
238
239 - All MCP requests go through Moqui's authentication system
240 - Screen access respects Moqui's artifact authorization
241 - Session management uses Moqui's Visit entity
242 - Tool execution is logged for audit purposes
243
244 ## Performance
245
246 - Session caching reduces database overhead
247 - Recursive discovery is performed once per session
248 - Screen rendering uses Moqui's optimized screen engine
249 - Connection pooling handles concurrent requests
250
251 ## Troubleshooting
252
253 ### Common Issues
254
255 1. **Server Not Running**
256 ```bash
257 ./gradlew --status
258 ./gradlew run --daemon
259 ```
260
261 2. **Authentication Failures**
262 - Verify user exists in Moqui
263 - Check user group memberships
264 - Validate credentials in `opencode.json`
265
266 3. **Missing Screens**
267 - Ensure required components are installed
268 - Check screen path syntax
269 - Verify user has screen permissions
270
271 4. **Session Issues**
272 ```bash
273 ./mcp.sh --clear-session
274 ./mcp.sh --new-session
275 ```
276
277 ### Debug Mode
278
279 Enable detailed logging by setting log level in `MoquiConf.xml`:
280 ```xml
281 <logger name="org.moqui.mcp" level="DEBUG"/>
282 ```
283
284 ## Contributing
285
286 1. Follow Moqui coding conventions
287 2. Add tests for new features
288 3. Update documentation
289 4. Ensure security implications are considered
290 5. Test with the provided test suite
291
292 ## License
293
294 This project is in the public domain under CC0 1.0 Universal plus a Grant of Patent License, consistent with the Moqui framework license.
295
296 ## Related Projects
297
298 - **Moqui Framework** - https://github.com/moqui/moqui-framework
299 - **PopCommerce** - E-commerce component for Moqui
300 - **MCP Specification** - https://modelcontextprotocol.io/
301
302 ## Support
303
304 For issues and questions:
305
306 1. Check the troubleshooting section
307 2. Review test examples in `test/`
308 3. Consult Moqui documentation
309 4. Check server logs for detailed error information
...\ No newline at end of file ...\ No newline at end of file