Skip to main content
Glama
bintocher

Qlik Sense MCP Server

by bintocher

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
NameRequiredDescriptionDefault
app_idYesApplication ID

Implementation Reference

  • 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"]}),
  • 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", "")

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bintocher/qlik-sense-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server