get_app_script
Retrieve load script content from Qlik Sense applications using the application ID to access data transformation logic.
Instructions
Get load script from app
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| app_id | Yes | Application ID |
Implementation Reference
- qlik_sense_mcp_server/server.py:275-275 (registration)Registration of the 'get_app_script' tool in the MCP list_tools handler, including name, description, and input schema requiring 'app_id'.Tool(name="get_app_script", description="Get load script from app", inputSchema={"type": "object", "properties": {"app_id": {"type": "string", "description": "Application ID"}}, "required": ["app_id"]}),
- qlik_sense_mcp_server/server.py:545-590 (handler)MCP tool handler for 'get_app_script': validates input, connects to Qlik Engine, opens app safely, retrieves script via engine_api.get_script, handles errors, and returns JSON response.elif name == "get_app_script": app_id = arguments["app_id"] def _get_script(): app_handle = -1 try: self.engine_api.connect() app_result = self.engine_api.open_doc_safe(app_id, no_data=True) if "qReturn" not in app_result: raise Exception(f"Failed to open app: invalid response {app_result}") app_handle = app_result["qReturn"].get("qHandle", -1) if app_handle == -1: raise Exception(f"Failed to get app handle: {app_result}") script = self.engine_api.get_script(app_handle) return { "qScript": script, "app_id": app_id, "app_handle": app_handle, "script_length": len(script) if script else 0 } except Exception as e: error_msg = str(e) if "already open" in error_msg.lower(): error_msg = f"App {app_id} is already open in another session. Try again later or use a different session." elif "failed to open app" in error_msg.lower(): error_msg = f"Could not open app {app_id}. Check if app exists and you have access." return { "error": error_msg, "app_id": app_id, "app_handle": app_handle } finally: if app_handle != -1: try: self.engine_api.close_doc(app_handle) except: pass self.engine_api.disconnect() script = await asyncio.to_thread(_get_script) return [ TextContent( type="text", text=json.dumps(script, indent=2, ensure_ascii=False) ) ]
- Core implementation of script retrieval: sends 'GetScript' JSON-RPC request to Qlik Sense Engine API via WebSocket and extracts qScript from response.def get_script(self, app_handle: int) -> str: """Get load script.""" result = self.send_request("GetScript", [], handle=app_handle) return result.get("qScript", "")