AI Courses

Build a tiny server + the safety checklist

Written by

in

Build a tiny server + the safety checklist | Master AI Automation in 4 hours Master AI Automation in 4 hours Course About Ayush Modules Sample chapter Toolbox The Microcap Minute Classroom / Module 05: MCP: Plug-ins With Standards / Chapter 5 Build a tiny server + the safety checklist Watch first, then read. Same lesson, your pace. What you will learn – A working MCP server in ~15 lines of Python – How clients discover your tools – The five-point checklist for handing AI real powers Your server Create wordcount.py anywhere: from mcp.server.fastmcp import FastMCP mcp = FastMCP(“study-tools”) @mcp.tool() def word_count(text: str) -> int: “””Count words in any text.””” return len(text.split()) if __name__ == “__main__”: mcp.run() Install once: uv pip install “mcp[cli]” . Wire into Claude Desktop’s config (Chapter 3’s ritual): “study-tools”: { “command”: “/path/to/.venv/bin/python”, “args”: [“/path/to/wordcount.py”] } Restart, verify word_count appears, then ask: “Use word_count on: this sentence.” The model discovers your tool from its description, calls it, returns 4. Stare at what happened: you wrote no AI code. A decorated function + one docstring line became an ability the model can choose. That decorator, @mcp.tool() , plus a clear docstring is the whole craft; the model reads that sentence to decide when your tool matters. Write docstrings like you’re briefing a smart stranger, because you are. Extend it yourself later: a reading_time tool (words ÷ 200), a summarise_file tool reading disk. Same pattern forever. The safety checklist You now grant abilities, so act like it. Before connecting any server, yours or others’: Least privilege , scope filesystem servers to named folders, never / or home wholesale Reads before writes , prefer servers/tools that only look; add write powers deliberately Know the off-switch , config removal + restart kills access instantly; test it once Sensitive stays offline , keys, passwords, personal documents never live inside reachable folders while experimenting Watch first runs , after new installs, observe what the AI actually does with tools; surprise = unplug and investigate MCP grants are deliberate acts by you, revocable in seconds. With the checklist above, the doorway stays yours, the AI walks through it when invited, not otherwise. Try it yourself Get word_count running end to end (build → wire → restart → call). Then add reading_time yourself using the same pattern, without copying more than the decorator line. Finally rehearse the off-switch: remove the block, restart, confirm the tools vanished, restore them. Log both tools and your audit notes in learn/first-mcp-server.md . Key takeaways – An MCP server is just described functions; @mcp.tool() + honest docstrings = new AI abilities. – Clients auto-discover tools; the model chooses based on your descriptions. – Safety = least privilege, read-first, tested off-switch, sensitive data offline, supervised early runs. – You’ve crossed from using agents to equipping them. Download the exercise sheet (PDF) Module workbook (PDF) ← Prev: The shelf Module 05 index → Classroom / Module 05: MCP: Plug-ins With Standards / Chapter 5 Build a tiny server + the safety checklist What you will learn – A working MCP server in ~15 lines of Python – How clients discover your tools – The five-point checklist for handing AI real powers Your server Create wordcount.py anywhere: from mcp.server.fastmcp import FastMCP mcp = FastMCP(“study-tools”) @mcp.tool() def word_count(text: str) -> int: “””Count words in any text.””” return len(text.split()) if __name__ == “__main__”: mcp.run() Install once: uv pip install “mcp[cli]” . Wire into Claude Desktop’s config (Chapter 3’s ritual): “study-tools”: { “command”: “/path/to/.venv/bin/python”, “args”: [“/path/to/wordcount.py”] } Restart, verify word_count appears, then ask: “Use word_count on: this sentence.” The model discovers your tool from its description, calls it, returns 4. Stare at what happened: you wrote no AI

📄 Download PDF

📄 Download PDF