Organizing your architecture
A huge advantage of using a low-level server is that you can control the architecture of your server. You can organize your code in a way that makes sense for your project. For example, you can define all your tools in a folder called tools. Tools also don’t need to know about the server instance. Sounds promising, right? Let’s see how next.
You can organize your code well with a high-level server too, but it’s usually a bit messier as you need to pass the server instance around, as we said initially in this chapter.
Here’s how you have defined MCP server features so far in a high-level server:
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("Echo")
@mcp.tool()
def echo_tool(message: str) -> str:
"""Echo a message as a tool"""
return f"Tool echo: {message}"
@mcp.tool()
def add_tool(a: int, b: int) -> int:
"""Add two...