The Model Context Protocol (MCP) ecosystem is often presented as complex and SDK-heavy, but a new tutorial on DEV.to by author shipitcodes reveals that the core mechanics are surprisingly simple. The guide demonstrates how to build a fully functional MCP server using only about 90 lines of plain Python, eliminating the need for external dependencies. This approach strips away the abstraction layers, showing that the server is essentially just a process reading JSON from stdin and writing to stdout.

The Wire Protocol and Session Flow

The article details the stdio transport mechanism, which relies on JSON-RPC 2.0 messages sent one per line. A standard session involves the client sending an initialize request, to which the server replies with its protocol version, capabilities, and name. The client then sends a notifications/initialized notification, followed by tools/list to discover available functions. Finally, the client executes tools/call when the model decides to use a tool. The tutorial’s code handles these specific methods, ignoring notifications without IDs to prevent client confusion.

Error Handling and stdout Discipline

A critical takeaway from the implementation is the distinction between protocol errors and tool failures. The code returns JSON-RPC error codes like -32601 for method not found or -32602 for invalid params when the client misbehaves. However, if a tool itself fails (e.g., a missing argument), the server returns a normal result with isError: true. This allows the model to see the failure as text and potentially retry. Additionally, the author stresses that stdout is sacred; only protocol messages should go there, with debug output directed to stderr to avoid breaking the session.

Integration and Future Extensions

To integrate the server, users simply add a command entry to their client’s configuration, pointing to the Python script. The tutorial provides a specific JSON config example for clients like Claude Desktop or Cursor. While the 90-line example covers tools, the author notes that production servers typically add resources for file access, stricter schema validation, and version negotiation. This foundational understanding demystifies the protocol, allowing developers to build custom agents without getting lost in framework-specific nuances.

Key Takeaways

  • MCP servers using stdio are just processes exchanging JSON-RPC 2.0 messages over stdin/stdout.
  • Distinguish between protocol errors (JSON-RPC error codes) and tool errors (result with isError: true).
  • Never write debug logs to stdout; use stderr to avoid corrupting the protocol stream.
  • The core handshake involves initialize, notifications/initialized, tools/list, and tools/call.
  • Plain Python is sufficient for basic implementations, removing the barrier of heavy SDKs.

The Bottom Line

If you can read a JSON line and write a JSON line, you can build an MCP server. Stop hiding behind SDKs and understand the wire protocol; it makes debugging infinitely easier.