ai-mcp-demo.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
from mcp.server.fastmcp import FastMCP
import tools
mcp = FastMCP("host info mcp")
mcp.add_tool(tools.get_host_info)
@mcp.tool()
def foo():
return ""
def main():
mcp.run("stdio") # sse
if __name__ == "__main__":
main()
import platform
import psutil
import subprocess
import json
def get_host_info() -> str:
"""get host information
Returns:
str: the host information in JSON string
"""
info: dict[str, str] = {
"system": platform.system(),
"release": platform.release(),
"machine": platform.machine(),
"processor": platform.processor(),
"memory_gb": str(round(psutil.virtual_memory().total / (1024**3), 2)),
}
cpu_count = psutil.cpu_count(logical=True)
if cpu_count is None:
info["cpu_count"] = "-1"
else:
info["cpu_count"] = str(cpu_count)
try:
cpu_model = subprocess.check_output(
["sysctl", "-n", "machdep.cpu.brand_string"]
).decode().strip()
info["cpu_model"] = cpu_model
except Exception:
info["cpu_model"] = "Unknown"
return json.dumps(info, indent=4)
if __name__ == '__main__':
print(get_host_info())
source & further reading
gist.github.com — original article
Building an LLM Wiki for Your Project — a step-by-step guide (agent-maintained knowledge base: schema, ingest/query/lint workflows, qmd search, lint script)
claude cost optimization instructions
Self-hosted AI assistant on a $9 VPS — Ollama + Open WebUI + Caddy