is_connected
Check whether an active Frida session is alive and healthy, returning connection status, process PID, and device information.
Instructions
Check if Frida session is still alive and healthy. Returns connection status, PID, and device info.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/frida_mcp/device.py:190-208 (handler)The actual implementation of the 'is_connected' tool. Checks the active Frida session, queries the PID and module list, and returns connection status.
def is_connected() -> dict: """Check if Frida session is still alive and healthy.""" fs = registry.get_active() if fs is None: return {"connected": False, "reason": "no_session"} try: pid = fs.session._impl.pid modules = fs.api.memory_list_modules() module_count = len(modules) if modules else 0 return { "connected": True, "session_id": fs.id, "pid": pid, "device": fs.device.name, "module_count": module_count, } except Exception as e: return {"connected": False, "reason": str(e)} - src/frida_mcp/tools.py:52-56 (schema)Tool registration/schema for 'is_connected'. Defines name, description, and empty inputSchema (no arguments required).
Tool( name="is_connected", description="Check if Frida session is still alive and healthy. Returns connection status, PID, and device info.", inputSchema={"type": "object", "properties": {}, "required": []}, ), - src/frida_mcp/server.py:35-36 (registration)Dispatch/call_tool function in the MCP server. Routes 'is_connected' to device.is_connected().
elif name == "is_connected": return device.is_connected() - tests/test_helpers.py:40-82 (helper)Tests for is_connected function covering three scenarios: no session, valid session, and dead session.
class TestIsConnected: """Tests for is_connected function""" def setup_method(self): _registry.close_all() def test_not_connected_when_no_session(self): result = is_connected() assert result["connected"] is False assert result["reason"] == "no_session" def test_connected_with_valid_session(self): mock_device = MagicMock() mock_device.name = "Test Device" mock_session = MagicMock() mock_session._impl.pid = 1234 mock_api = MagicMock() mock_api.memory_list_modules.return_value = [{"name": "libc.so"}] _registry.create(mock_device, mock_session, mock_api, "com.test", 1234) result = is_connected() assert result["connected"] is True assert result["pid"] == 1234 assert result["device"] == "Test Device" assert result["module_count"] == 1 def test_not_connected_when_session_dead(self): mock_device = MagicMock() mock_device.name = "Test Device" mock_session = MagicMock() mock_session._impl.pid = property(lambda s: (_ for _ in ()).throw(Exception("dead"))) mock_api = MagicMock() mock_api.memory_list_modules.side_effect = Exception("session dead") _registry.create(mock_device, mock_session, mock_api, "com.test", 1234) result = is_connected() assert result["connected"] is False assert "reason" in result def teardown_method(self): _registry.close_all()