Run the Server with stdio
Start the server so a client can connect locally.
Run the Server with stdio is a free MCP Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the MCP Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Time to Start It Up
You have a server object and a tool. Now you need to actually run it so a client can connect and use what you built. 🏃
What stdio Means
The simplest transport is stdio: standard input and output. The client launches your script and talks to it through those two streams.
Call run()
Starting the server is one method. Calling mcp.run() hands control to FastMCP, which begins listening for messages right away.
mcp.run()Choose the Transport
Pass a transport argument to be explicit. For local use you want "stdio", which is also the default when you call run.
mcp.run(transport="stdio")The Main Guard
Wrap the call in the classic __main__ guard. That way the server starts only when the file is run directly, not when imported.
if __name__ == "__main__":
mcp.run()The Whole File
Here is a complete server: import, instance, tool, and run. Just a handful of lines and it speaks MCP.
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("demo")
@mcp.tool()
def hello() -> str:
return "Hi!"
if __name__ == "__main__":
mcp.run()stdout Is Reserved
One golden rule: never print to standard output. That stream carries protocol messages, and stray text will corrupt them.
Log to stderr Instead
Need to debug? Write to stderr, not stdout. The client ignores stderr, so your notes stay out of the protocol stream.
import sys
print("starting up", file=sys.stderr)The Client Launches You
With stdio, you rarely run the script by hand. The host app starts your process for you using a configured command.
It Waits, Not Loops Idle
After run() the server blocks, waiting for messages. It isn't frozen; it's listening for the next request from the client.
stdio Is Local Only
Remember that stdio works only on the same machine, since it relies on a launched process. Remote servers use HTTP transport instead, which comes later.
Quick Check
Why must you avoid plain print() in a stdio server?
Recap
You ran the server with mcp.run() over stdio, guarded it with __main__, and kept stdout clean. It's live and listening. Let's confirm it works! ✅
Frequently asked questions
Is the “Run the Server with stdio” lesson free?
Yes — the full text of “Run the Server with stdio” is free to read here on the web, and the MCP Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the MCP Academy course, upgrade to CoddyKit PRO.
What will I learn in “Run the Server with stdio”?
Start the server so a client can connect locally. You practise MCP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start MCP Academy?
No prior experience is required. MCP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Run the Server with stdio” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this MCP Academy lesson?
Yes. Every MCP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Create a FastMCP Instance
- Add a Hello Tool
- Run the Server with stdio
- Confirm It Loads & Lists Tools