Commands¶
commands ¶
Command registry for unified local and remote execution.
This module provides a centralized registry of commands used by tools, enabling consistent execution across local and remote systems.
CommandGroup ¶
Bases: BaseModel
Group of related commands for multi-command tool operations.
Attributes:
| Name | Type | Description |
|---|---|---|
commands |
Mapping[str, CommandSpec]
|
Named commands within the group. |
Source code in src/linux_mcp_server/commands.py
CommandSpec ¶
Bases: BaseModel
Specification for a single command with optional fallback.
Attributes:
| Name | Type | Description |
|---|---|---|
args |
tuple[str, ...]
|
Command arguments as a tuple of strings. |
fallback |
tuple[str, ...] | None
|
Alternative command arguments if primary fails. |
optional_flags |
Mapping[str, tuple[str, ...]] | None
|
Maps parameter names to flag arguments that are added
when the parameter is truthy. For example:
{"unit": ["--unit", "{unit}"]} adds "--unit |
Source code in src/linux_mcp_server/commands.py
run
async
¶
Run the command with optional fallback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str | None
|
Optional remote host address. |
None
|
**kwargs
|
object
|
Additional arguments passed to substitute_command_args. |
{}
|
Source code in src/linux_mcp_server/commands.py
run_bytes
async
¶
Run the command with optional fallback and return raw bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str | None
|
Optional remote host address. |
None
|
**kwargs
|
object
|
Additional arguments passed to substitute_command_args. |
{}
|
Source code in src/linux_mcp_server/commands.py
get_command ¶
Get a command spec from the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The command name in the registry. |
required |
subcommand
|
str
|
The subcommand key within the group (default: "default"). |
'default'
|
Returns:
| Type | Description |
|---|---|
CommandSpec
|
The CommandSpec for the given name and subcommand. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the command name or subcommand is not found. |
Source code in src/linux_mcp_server/commands.py
get_command_group ¶
Get a command group from the registry.
Use this when you need to iterate over all subcommands in a group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The command group name in the registry. |
required |
Returns:
| Type | Description |
|---|---|
CommandGroup
|
The CommandGroup for the given name. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the command name is not found in the registry. |
Source code in src/linux_mcp_server/commands.py
substitute_command_args ¶
Substitute placeholder values in command arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Sequence[str]
|
Sequence of command arguments, possibly with {placeholder} values. |
required |
**kwargs
|
object
|
Key-value pairs to substitute into placeholders. |
{}
|
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
Tuple of command arguments with placeholders replaced. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any placeholders are missing from kwargs or remain unsubstituted after replacement. |
Example
substitute_command_args(("ps", "-p", "{pid}"), pid=1234) ("ps", "-p", "1234")