Formatters¶
formatters ¶
Shared output formatters for tool results.
This module provides functions to format parsed data into human-readable strings for tool output.
format_disk_usage ¶
Format disk usage output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stdout
|
str
|
Raw output from df command. |
required |
disk_io
|
str | None
|
Optional disk I/O statistics. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string representation. |
Source code in src/linux_mcp_server/formatters.py
format_hardware_info ¶
Format hardware information output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
dict[str, str]
|
Dictionary of command name to output. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted string representation. |
Source code in src/linux_mcp_server/formatters.py
format_listening_ports ¶
format_listening_ports(
ports: list[ListeningPort],
header: str = "=== Listening Ports ===\n",
) -> str
Format listening ports into a readable string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ports
|
list[ListeningPort]
|
List of ListeningPort objects. |
required |
header
|
str
|
Header text for the output. |
'=== Listening Ports ===\n'
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string representation. |
Source code in src/linux_mcp_server/formatters.py
format_network_connections ¶
format_network_connections(
connections: list[NetworkConnection],
header: str = "=== Active Network Connections ===\n",
) -> str
Format network connections into a readable string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connections
|
list[NetworkConnection]
|
List of NetworkConnection objects. |
required |
header
|
str
|
Header text for the output. |
'=== Active Network Connections ===\n'
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string representation. |
Source code in src/linux_mcp_server/formatters.py
format_network_interfaces ¶
format_network_interfaces(
interfaces: dict[str, NetworkInterface],
stats: dict[str, NetworkInterface] | None = None,
) -> str
Format network interface information into a readable string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interfaces
|
dict[str, NetworkInterface]
|
Dictionary of interface name to NetworkInterface objects. |
required |
stats
|
dict[str, NetworkInterface] | None
|
Optional dictionary of interface statistics. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string representation. |
Source code in src/linux_mcp_server/formatters.py
format_process_detail ¶
format_process_detail(
ps_output: str,
proc_status: dict[str, str] | None = None,
pid: int | None = None,
) -> str
Format detailed process information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ps_output
|
str
|
Raw output from ps command for the process. |
required |
proc_status
|
dict[str, str] | None
|
Parsed /proc/{pid}/status content. |
None
|
pid
|
int | None
|
Process ID for the header. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string representation. |
Source code in src/linux_mcp_server/formatters.py
format_process_list ¶
format_process_list(
processes: list[ProcessInfo],
max_display: int | None = None,
header: str = "=== Running Processes ===\n",
) -> str
Format process list into a readable string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
processes
|
list[ProcessInfo]
|
List of ProcessInfo objects. |
required |
max_display
|
int | None
|
Maximum number of processes to display. |
None
|
header
|
str
|
Header text for the output. |
'=== Running Processes ===\n'
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string representation. |
Source code in src/linux_mcp_server/formatters.py
format_service_logs ¶
Format service logs output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stdout
|
str
|
Raw output from journalctl. |
required |
service_name
|
str
|
Name of the service. |
required |
lines_count
|
int
|
Number of log lines requested. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted string representation. |
Source code in src/linux_mcp_server/formatters.py
format_service_status ¶
Format service status output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stdout
|
str
|
Raw output from systemctl status. |
required |
service_name
|
str
|
Name of the service. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted string representation. |
Source code in src/linux_mcp_server/formatters.py
format_services_list ¶
Format service list output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stdout
|
str
|
Raw output from systemctl list-units. |
required |
running_count
|
int | None
|
Optional count of running services. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string representation. |