cd /news/developer-tools/ai-mcp-demo-py · home topics developer-tools article
[ARTICLE · art-8888] src=gist.github.com ↗ pub= topic=developer-tools verified=true sentiment=· neutral

ai-mcp-demo.py

The provided code demonstrates a simple MCP (Model Context Protocol) server named "host info mcp" built using the `FastMCP` library. It defines a single tool, `get_host_info`, which collects and returns system information—including OS details, memory, CPU count, and CPU model—as a formatted JSON string. The server is configured to run over standard I/O (stdio) and registers the tool for use by an MCP client.

read1 min views27 publishedMay 10, 2025
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())
── more in #developer-tools 4 stories · sorted by recency
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/ai-mcp-demo-py] indexed:0 read:1min 2025-05-10 ·