Connecting Claude to a database or an internal API through MCP (Model Context Protocol) takes about 20 lines of Python. Making it safe to leave connected takes a bit more thought. Here are six lessons from building MCP servers for SQL databases, REST APIs, Notion, Google Sheets, local documents and spreadsheets.
All examples use the official Python SDK 2.x.
1. Start from a minimal server
from mcp . server . mcpserver import MCPServer
mcp = MCPServer ( "crm-demo" )
@mcp . tool ( ) def find_customer ( query : str ) -> list [ dict ] : """Search customers by part of their name or email address.""" . . .
if __name__ == "__main__" : mcp . run ( )
Enter fullscreen mode
Exit fullscreen mode
Note: in SDK 2.x, FastMCP became MCPServer in mcp.server.mcpserver . Type hints and the docstring become the tool schema Claude sees.
2. Read-only by default, writes behind a switch
Don't just check permissions inside a write tool. Don't register it at all unless the user opted in:
ALLOW_WRITES = os . environ .…