Skip to content

Instantly share code, notes, and snippets.

@jrelo
Created September 21, 2025 14:46
Show Gist options
  • Save jrelo/5e516733000387f627a00c25e2460c03 to your computer and use it in GitHub Desktop.
Save jrelo/5e516733000387f627a00c25e2460c03 to your computer and use it in GitHub Desktop.
MCP example
#!/usr/bin/env python3
from mcp.server.fastmcp import FastMCP
from mcp.server.sse import sse_app # SSE transport ASGI app
import uvicorn
import subprocess
# Create MCP server
mcp = FastMCP("Pi-MCP-Server")
@mcp.tool()
def run_command(cmd: str):
"""Run shell command as mcp user."""
try:
out = subprocess.check_output(cmd, shell=True, text=True, stderr=subprocess.STDOUT)
return {"output": out}
except subprocess.CalledProcessError as e:
return {"error": e.output, "returncode": e.returncode}
# Wrap FastMCP in SSE app
app = sse_app(mcp)
if __name__ == "__main__":
# Start HTTP server on LAN
uvicorn.run(app, host="0.0.0.0", port=5000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment