execute_code
Run Python code in the napari server interpreter. Executes code with persistent namespace including viewer, napari, and np, returning the result's string representation.
Instructions
Execute arbitrary Python code in the server's interpreter.
Similar to napari's console. The execution namespace persists across calls and includes 'viewer', 'napari', and 'np'.
Parameters
code : str Python code string. The value of the last expression (if any) is returned as 'result_repr'. line_limit : int, default=30 Maximum number of output lines to return. Use -1 for unlimited output. Warning: Using -1 may consume a large number of tokens.
Note
In standalone mode, code execution runs synchronously on the main thread (required for Qt/napari operations) and has no timeout. In bridge mode, a 600-second timeout is enforced.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"code": "<code>"
},
"name": "execute_code"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | ||
| line_limit | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||