FastMCP is the high-level server API in the official Python SDK. It uses type hints and docstrings to produce tool schemas, which makes it a good fit for Python codebases that already use typing and Pydantic. This guide keeps the setup reproducible and the failure modes visible.
1. Create a locked environment
uv init github-triage-mcp
cd github-triage-mcp
uv add "mcp[cli]" httpx
Commit pyproject.toml and uv.lock. A client that runs uv run will then get the same dependency set on every machine. If you use pip instead, pin the SDK and record the Python version in the README.
2. Write a typed server
server.py:
from __future__ import annotations
import os
from typing import Literal
import httpx
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("github-triage")
@mcp.tool()
async def get_issue(repo: str, number: int) -> str:
"""Fetch a GitHub issue title and state.
Args:
repo: Repository in owner/name form, for example modelcontextprotocol/servers.
number: Positive issue number.
"""
if number < 1:
raise ValueError("number must be positive")
token = os.environ.get("GITHUB_TOKEN")
if not token:
raise RuntimeError("GITHUB_TOKEN is not configured")
async with httpx.AsyncClient(timeout=15.0) as client:
response = await client.get(
f"https://api.github.com/repos/{repo}/issues/{number}",
headers={
"Authorization": f"Bearer {token}",
"Accept": "application/vnd.github+json",
},
)
if response.status_code == 404:
return f"Issue {repo}#{number} was not found or is not visible to this token."
response.raise_for_status()
issue = response.json()
return f"{issue['title']} [{issue['state']}]"
if __name__ == "__main__":
mcp.run()
The docstring is part of the tool contract: it becomes the description shown to the model. Keep credentials in the environment and out of the arguments. Return a clear message for a permission or visibility failure instead of pretending the issue does not exist.
3. Run and inspect it
GITHUB_TOKEN=... uv run mcp dev server.py
MCP Inspector lists the get_issue tool with repo and number arguments. Test a valid repository, a nonexistent issue, and a missing token. Inspector is a development tool; it is not a substitute for testing your own error paths.
Never put a real token in shell history in shared environments. Use a local secret manager or an exported variable from a private shell.
4. Install it in a client
For Claude Code project scope, use .mcp.json:
{
"mcpServers": {
"github-triage": {
"command": "uv",
"args": ["run", "--directory", "/absolute/path/to/github-triage-mcp", "server.py"],
"env": { "GITHUB_TOKEN": "${GITHUB_TOKEN}" }
}
}
}
For Codex, generate TOML with the Config Generator or write:
[mcp_servers.github-triage]
command = "uv"
args = ["run", "--directory", "/absolute/path/to/github-triage-mcp", "server.py"]
[mcp_servers.github-triage.env]
GITHUB_TOKEN = "YOUR_GITHUB_TOKEN_HERE"
Codex’s env values are literal. Do not paste a production token into a shared TOML file; use a local secret injection method appropriate to your environment.
5. Verify the release gate
- The client lists the server without an error.
- The tool appears with two typed arguments.
- A valid request returns a title and state.
- A missing token produces a readable failure.
- The server survives a failed request and remains connected.
- The documented command uses an absolute path and works from a GUI client.
If the client cannot find uv, use its absolute path. If the server exits immediately, inspect stderr for a traceback and ensure nothing prints to stdout. Python’s logging module writes to stderr by default, while print() writes to stdout and can corrupt the protocol stream.
Next: Pydantic tool contracts, async tools and timeouts, and the Python production checklist.
Sources
Sources were checked on Oct 23, 2026. Versions and client behavior can change; confirm the current documentation before relying on a configuration.