.. cli_overview:

Overview
========

The CanKing CLI is a command line interface for Kvaser CanKing. It is installed with CanKing and can be found in the installation folder, typically `C:\\Program Files\\Kvaser CanKing\\service\\ck.exe` on Windows and `/opt/canking/service/ck` on Linux.

To get started with the CanKing CLI, open a terminal and type `ck --help` to see the available commands and options.

For more information on a specific command, type `ck <command> --help`.

.. _cli_canking_terminal:

CanKing Terminal
----------------

The CanKing CLI can be accessed from within the CanKing application. To do this, open CanKing and go to the `Tools Panel` in the lower part of the main window. From there, select `Terminal` to open a terminal view with the CanKing CLI ready to use.

If the `Tools Panel` isn't visible, then select 'More'->'View'->'Toggle Tools Panel' from the head menu.

.. _cli_windows_terminal:

Windows Terminal
----------------

On Windows, you can open a Command Prompt or PowerShell window and navigate to the CanKing CLI installation folder. You can then run the `ck.exe` executable with the desired commands and options.

To make CanKing CLI available from any folder, you can add the installation folder to your system's PATH environment variable.

**Adding CanKing CLI to PATH on Windows**

1. Open the Start menu and search for "Environment Variables"
2. Click "Edit the system environment variables"
3. In the System Properties dialog, click "Environment Variables..."
4. In the Environment Variables dialog, find "Path" in the System variables section and click "Edit..."
5. Click "New" and add the CanKing CLI installation folder path (typically `C:\\Program Files\\Kvaser CanKing\\service`)
6. Click "OK" to close all dialogs
7. Restart your Command Prompt or PowerShell window

After adding to PATH, you can run `ck` commands from any directory without specifying the full path to the executable.

.. _cli_linux_terminal:

Linux Terminal
--------------

On Linux, you can open a terminal and run the `ck` executable with the desired commands and options. A symbolic link to the `ck` executable is already added to `/usr/bin` making it available from any directory.

.. _cli_ai_agent_tools:

AI Agent Tools
--------------

CanKing includes an MCP (`Model Context Protocol <https://modelcontextprotocol.io/>`_) server, ``CanKingMcpServer``, that exposes the CanKing CLI functionality as tools for AI agent tools such as Claude Code, GitHub Copilot and Codex. Once it is set up, you can use plain language to ask the agent to list connected devices, build a measurement setup, start and stop measurements, send CAN and LIN messages, manage extensions and analyze logged data.

The MCP server is installed next to ``ck`` in the CanKing installation folder:

- Windows: ``C:\Program Files\Kvaser CanKing\service\CanKingMcpServer.exe``
- Linux: ``/opt/canking/service/CanKingMcpServer``

It uses the **stdio** transport, which means the AI agent tool starts it as a subprocess and talks to it over standard input and output. A running CanKing Service is required, and the port of a local service is discovered automatically.

**Claude Code**

Register the server from a terminal:

.. code-block:: bash

   claude mcp add canking --scope user -- "C:\Program Files\Kvaser CanKing\service\CanKingMcpServer.exe"

Alternatively, create a ``.mcp.json`` file in your project folder:

.. code-block:: json

   {
     "mcpServers": {
       "canking": {
         "command": "C:\\Program Files\\Kvaser CanKing\\service\\CanKingMcpServer.exe",
         "args": []
       }
     }
   }

Run the ``/mcp`` command inside Claude Code to verify that the ``canking`` server is connected.

**GitHub Copilot**

In Visual Studio Code, create a ``.vscode/mcp.json`` file in your workspace:

.. code-block:: json

   {
     "servers": {
       "canking": {
         "type": "stdio",
         "command": "C:\\Program Files\\Kvaser CanKing\\service\\CanKingMcpServer.exe",
         "args": []
       }
     }
   }

Open the Chat view, switch to **Agent** mode, and the CanKing tools become available from the tools picker.

**Codex**

Add the server to ``~/.codex/config.toml``, which is ``%USERPROFILE%\.codex\config.toml`` on Windows:

.. code-block:: toml

   [mcp_servers.canking]
   command = 'C:\Program Files\Kvaser CanKing\service\CanKingMcpServer.exe'
   args = []

**Connecting to a remote CanKing Service**

To make the AI agent tool work against a CanKing Service running on another machine, pass the URL and the API key as arguments in the configuration above:

.. code-block:: text

   "args": ["--url", "https://my-canking-host:5001", "--api-key", "<key>"]

The same values can be supplied through the ``CANKING_REMOTE_URL`` and ``CANKING_REMOTE_API_KEY`` environment variables.

.. _cli_commands:

Commands
--------

.. toctree::
   :maxdepth: 1

   ck add canchannel <add/canchannel>
   ck add db <add/db>
   ck add extension <add/extension>
   ck add filter <add/filter>
   ck add interpreter j1939 <add/interpreter/j1939>
   ck add linchannel <add/linchannel>
   ck add logreplay <add/logreplay>
   ck add messagelogger <add/messagelogger>
   ck add signallogger <add/signallogger>
   ck add traffic <add/traffic>
   ck connect nodes <connect/nodes>
   ck delete dataproc <delete/dataproc>
   ck delete source <delete/source>
   ck delete target <delete/target>
   ck disable node <disable/node>
   ck disconnect nodes <disconnect/nodes>
   ck enable node <enable/node>
   ck get about <get/about>
   ck get devices <get/devices>
   ck get event-log <get/event-log>
   ck get log-formats <get/log-formats>
   ck get meas-setup <get/meas-setup>
   ck get nodes <get/nodes>
   ck install extension <install/extension>
   ck pack extension <pack/extension>
   ck remote disable <remote/disable>
   ck remote enable <remote/enable>
   ck remote fs delete <remote/fs/delete>
   ck remote fs download <remote/fs/download>
   ck remote fs list <remote/fs/list>
   ck remote fs mkdir <remote/fs/mkdir>
   ck remote fs roots <remote/fs/roots>
   ck remote fs upload <remote/fs/upload>
   ck remote generate-cert <remote/generate-cert>
   ck send can <send/can>
   ck send lin <send/lin>
   ck send lin-clear <send/lin-clear>
   ck send lin-request <send/lin-request>
   ck send lin-update <send/lin-update>
   ck send lin-wakeup <send/lin-wakeup>
   ck send queue <send/queue>
   ck set meas-setup <set/meas-setup>
   ck start channel <start/channel>
   ck start logreplay <start/logreplay>
   ck start meas <start/meas>
   ck start stream <start/stream>
   ck start traffic <start/traffic>
   ck stop channel <stop/channel>
   ck stop logreplay <stop/logreplay>
   ck stop meas <stop/meas>
   ck stop traffic <stop/traffic>
   ck uninstall extension <uninstall/extension>
   ck update canchannel <update/canchannel>
   ck update db <update/db>
   ck update extension <update/extension>
   ck update filter <update/filter>
   ck update interpreter j1939 <update/interpreter/j1939>
   ck update linchannel <update/linchannel>
   ck update logreplay <update/logreplay>
   ck update messagelogger <update/messagelogger>
   ck update signallogger <update/signallogger>
   ck update traffic <update/traffic>

