3eb03965 by Ean Schuessler

WIP: Enhanced MCP service security and session management

- Fixed internalLoginUser calls to use single parameter signature
- Implemented admin discovery with user permission filtering for tools
- Added proper session validation with authz bypass for Visit entity access
- Enhanced audit logging with authz handling for ArtifactHit creation
- Improved pagination support for tools/list with cursor-based navigation
- Added comprehensive logging for debugging MCP service interactions
- Temporarily bypassed entity permission checks for testing purposes
- Enhanced error handling and user context restoration throughout services

Key improvements:
- Tools now discovered as admin but filtered by original user permissions
- Session management properly validates Visit records and tracks activity
- Audit records created with proper authz handling
- Better error handling and user context switching in all MCP services
1 parent 8b135abb
No preview for this file type
...@@ -531,8 +531,20 @@ try { ...@@ -531,8 +531,20 @@ try {
531 return 531 return
532 } 532 }
533 533
534 // Process MCP method using Moqui services (no sessionId in direct JSON-RPC) 534 // Try to get session ID from cookie
535 def result = processMcpMethod(rpcRequest.method, rpcRequest.params, ec, null) 535 String sessionId = null
536 def cookies = request.getCookies()
537 if (cookies) {
538 for (cookie in cookies) {
539 if ("MCP-SESSION".equals(cookie.getName())) {
540 sessionId = cookie.getValue()
541 break
542 }
543 }
544 }
545
546 // Process MCP method using Moqui services with session ID if available
547 def result = processMcpMethod(rpcRequest.method, rpcRequest.params, ec, sessionId)
536 548
537 // Build JSON-RPC response 549 // Build JSON-RPC response
538 def rpcResponse = [ 550 def rpcResponse = [
...@@ -543,6 +555,12 @@ try { ...@@ -543,6 +555,12 @@ try {
543 555
544 response.setContentType("application/json") 556 response.setContentType("application/json")
545 response.setCharacterEncoding("UTF-8") 557 response.setCharacterEncoding("UTF-8")
558
559 // Set session cookie if result contains sessionId
560 if (rpcResponse.result?.sessionId) {
561 response.setHeader("Set-Cookie", "MCP-SESSION=${rpcResponse.result.sessionId}; Path=/; HttpOnly; SameSite=Lax")
562 }
563
546 response.writer.write(groovy.json.JsonOutput.toJson(rpcResponse)) 564 response.writer.write(groovy.json.JsonOutput.toJson(rpcResponse))
547 } 565 }
548 566
......