Formatters¶
formatters ¶
Shared output formatters for tool results.
This module provides functions to format parsed data into human-readable strings for tool output.
format_audit_logs ¶
Format audit logs output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stdout
|
str
|
Raw output from tail on audit.log. |
required |
lines_count
|
int
|
Number of log lines. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted string representation. |
Source code in src/linux_mcp_server/formatters.py
format_block_devices ¶
Format block devices output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stdout
|
str
|
Raw output from lsblk. |
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_cpu_info ¶
Format CPU information into a readable string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
info
|
CpuInfo
|
CpuInfo object. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted string representation. |
Source code in src/linux_mcp_server/formatters.py
format_directory_listing ¶
format_directory_listing(
entries: list[NodeEntry],
path: str,
sort_by: str,
reverse: bool = False,
) -> str
Format directory listing into a readable string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries
|
list[NodeEntry]
|
List of NodeEntry objects. |
required |
path
|
str
|
Path that was listed. |
required |
sort_by
|
str
|
Sort field used. |
required |
reverse
|
bool
|
Whether the sort was reversed. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string representation. |
Source code in src/linux_mcp_server/formatters.py
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_file_listing ¶
format_file_listing(
entries: list[NodeEntry],
path: str,
sort_by: str,
reverse: bool = False,
) -> str
Format file listing into a readable string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries
|
list[NodeEntry]
|
List of NodeEntry objects. |
required |
path
|
str
|
Path that was listed. |
required |
sort_by
|
str
|
Sort field used. |
required |
reverse
|
bool
|
Whether the sort was reversed. |
False
|
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_journal_logs ¶
format_journal_logs(
stdout: str,
lines_count: int,
unit: str | None = None,
priority: str | None = None,
since: str | None = None,
) -> str
Format journal logs output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stdout
|
str
|
Raw output from journalctl. |
required |
lines_count
|
int
|
Number of log lines. |
required |
unit
|
str | None
|
Optional unit filter. |
None
|
priority
|
str | None
|
Optional priority filter. |
None
|
since
|
str | None
|
Optional time filter. |
None
|
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_log_file ¶
Format log file output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stdout
|
str
|
Raw content from log file. |
required |
log_path
|
str
|
Path to the log file. |
required |
lines_count
|
int
|
Number of lines read. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted string representation. |
Source code in src/linux_mcp_server/formatters.py
format_memory_info ¶
Format memory information into a readable string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
memory
|
SystemMemory
|
SystemMemory object containing RAM and swap info. |
required |
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. |
Source code in src/linux_mcp_server/formatters.py
format_system_info ¶
Format system information into a readable string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
info
|
SystemInfo
|
SystemInfo object. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted string representation. |