A Model Context Protocol (MCP) server for running ruff and ty with token-efficient output.
python-mcp gives LLMs direct access to lint, format-check, and type-check Python projects. Tool output is parsed structurally and reduced to compact diagnostics before it reaches the model.
- ruff_check - Lint files, glob patterns, or everything;
changed_onlychecks just the files touched in git - ruff_format - Verify formatting without modifying files
- ty_check - Type-check with concise output and an optional
error/warningseverity filter - Structured parsing - ruff JSON and ty GitLab code-quality output avoid fragile parsing of human-readable text
- Adaptive aggregation - large result sets include rule/file rollups before flat diagnostics, reducing repeated context
- changed_only - Check only staged, unstaged, and untracked Python files (
*.py,*.pyi)
python-mcp implements the Model Context Protocol to expose ruff and ty through three read-only tools. All tools return a CheckResult with token-efficient output text and the underlying exit_code.
ruff_check(paths?, changed_only?)- Run ruff lintingruff_format(paths?, changed_only?)- Runruff format --checkty_check(paths?, level?, changed_only?)- Runty check --output-format concise, filtering byall/error/warning
| Command | Input format | Output |
|---|---|---|
ruff check |
JSON | Compact grouped output; large runs get rule/file rollups |
ruff format --check |
Concise text | One line per unformatted file |
ty check |
GitLab JSON | Compact grouped output; severity filter applied |
Small and medium result sets use the plugin-compatible grouped layout because it has lower overhead. Large result sets switch to an rtk-like layout with Top rules, Top files, and flat diagnostic lines. This addresses rtk's large-result advantage without adding an external runtime dependency.
To start the server:
uvx python-mcpOr from a checkout:
uv run python-mcpConfigure an MCP client to launch the server in the project directory to check, e.g. for opencode:
{
"mcp": {
"python-mcp": {
"type": "stdio",
"command": "uvx",
"args": ["python-mcp"]
}
}
}The server checks the project in its working directory. To target another directory, set PYTHON_MCP_PROJECT_DIR.
Install the bundled python-mcp skill in a project when the agent client
discovers skills from .agents/skills:
uvx python-mcp skill install python-mcp --target .The skill directs agents to the server's three read-only tools:
ruff_check, ruff_format, and ty_check. It does not describe uv package
or environment management.
Environment variables, all optional:
PYTHON_MCP_LOG_LEVEL- Logging level, defaultINFOPYTHON_MCP_PROJECT_DIR- Project directory to check, default: server working directoryPYTHON_MCP_COMMAND_PREFIX- Prefix for native ruff/ty invocations, defaultuv run; set to empty to use binaries fromPATHPYTHON_MCP_COMMAND_TIMEOUT- Optional command timeout in seconds
This project is built with FastMCP and uv.
uv sync --extra dev
uv run ruff check
uv run ty check
uv run pytest