"""FastMCP server that exposes curated macOS terminal tools."""
from __future__ import annotations
from fastmcp import Context, FastMCP
from fastmcp.exceptions import ToolError
from . import tools
app = FastMCP(
name="macos-tools-mcp",
instructions=(
"Use these tools to inspect the local macOS system via read-only terminal "
"commands. Avoid requesting actions that would modify system state."
),
version="0.1.0",
)
@app.tool(
name="diskutil_list",
description="List all disks and partitions using `diskutil list`.",
)
def diskutil_list(_: Context | None = None) -> str:
return tools.diskutil_list()
@app.tool(
name="battery_status",
description="Show current battery information reported by `pmset -g batt`.",
)
def battery_status(_: Context | None = None) -> str:
return tools.battery_status()
@app.tool(
name="network_services",
description="List configured network services as reported by `networksetup`.",
)
def network_services(_: Context | None = None) -> list[str]:
return list(tools.available_network_services())
@app.tool(
name="network_service_details",
description="Retrieve interface details (IP, subnet, router) for a network service.",
)
def network_service_details(service_name: str, _: Context | None = None) -> str:
service = service_name.strip()
if not service:
raise ToolError("Provide the name of a network service to inspect")
available = set(tools.available_network_services())
if available and service not in available:
raise ToolError(
"Unknown network service. Choose one of: " + ", ".join(sorted(available))
)
return tools.network_service_details(service)
@app.tool(
name="system_profile",
description="Return structured data from `system_profiler` for the requested data type.",
)
def system_profile(data_type: str = "software", _: Context | None = None) -> dict:
return tools.system_profile(data_type)
def run() -> None:
"""Run the FastMCP server."""
app.run()
if __name__ == "__main__":
run()