𝗕𝘂𝗶𝗹𝗱𝗶𝗻𝗴 𝗮 𝗣𝘆𝘁𝗵𝗼𝗻 𝗠𝗖𝗣 𝗦𝗲𝗿𝘃𝗲𝗿 𝗳𝗿𝗼𝗺 𝗦𝗰𝗿𝗮𝘁𝗰𝗵

The Model Context Protocol (MCP) is now an industry standard. It reached 97 million monthly SDK downloads. Every major AI tool uses it. Most guides only show you how to install existing servers. This guide shows you how to build your own using Python and the GitHub API.

What is MCP? It is a protocol that lets AI clients call external services. Your server handles requests from tools like Claude or Cursor.

The Three Core Parts of MCP:

  • Tools: Functions the AI calls to take action or get data.
  • Resources: Read-only data endpoints like files or database records.
  • Prompts: Reusable instruction templates for consistent workflows.

Setup Your Project Create a directory and install the necessary libraries using uv:

mkdir github-mcp-server cd github-mcp-server uv init . uv add "mcp[cli]" httpx

Building the Server Use FastMCP to handle the heavy lifting. A good MCP server uses three specific files: server.py, pyproject.toml, and an optional .env file for your GitHub token.

Pro Tips for Development:

  • Use Pydantic models for tool returns. This gives the AI structured data instead of messy strings.
  • Write clear docstrings. The AI reads these to decide when to use your tool.
  • Clamp numeric inputs. AI models often send unexpected numbers like 0 or 100.
  • Handle exceptions. A crash in your server can kill the entire connection.

Testing and Deployment Do not wait to test in Claude. Use the MCP Inspector first. Run: uv run mcp dev server.py

This opens a local interface at http://localhost:5173. You can test tools, resources, and prompts in one place.

Connecting to Claude Desktop: Update your config file to include your server. Use the full path to your server.py file. Always use uv run instead of the bare python command to avoid environment errors.

Connecting to Claude Code: Use the CLI command: claude mcp add github-tools -- uv run python /path/to/server.py

Building custom MCP servers lets you bring live data into your AI workflows.

Source: https://dev.to/moksh/building-a-python-mcp-server-from-scratch-a-practical-github-api-guide-397k

Optional learning community: https://t.me/GyaanSetuAi