# Pre-commit configuration for MkDocs MCP Example
# See https://pre-commit.com for more information
repos:
# Ruff - Python linting and formatting
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.9
hooks:
# Run the linter
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
types_or: [python, pyi]
# Run the formatter
- id: ruff-format
types_or: [python, pyi]
# MyPy - Static type checking
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
- id: mypy
additional_dependencies: [types-requests, types-PyYAML]
args: [--ignore-missing-imports]
exclude: ^tests/
# General hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
# Git hooks
- id: check-added-large-files
args: [--maxkb=1000]
- id: check-merge-conflict
- id: no-commit-to-branch
args: [--branch, main, --branch, master]
# File format hooks
- id: check-yaml
exclude: ^mkdocs-site/mkdocs\.yml$ # MkDocs YAML can have custom tags
- id: check-toml
- id: check-json
- id: check-xml
# Code quality hooks
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=lf]
# Python specific hooks
- id: check-ast
- id: check-builtin-literals
- id: check-docstring-first
- id: debug-statements
- id: name-tests-test
args: [--django]
# Markdown linting
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.38.0
hooks:
- id: markdownlint
args: [--fix]
exclude: ^docs/includes/
# YAML formatting
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: prettier
types_or: [yaml, json]
exclude: ^mkdocs-site/mkdocs\.yml$
# Security scanning
- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
hooks:
- id: bandit
args: [-c, pyproject.toml]
additional_dependencies: [bandit[toml]]
exclude: ^tests/
# Documentation specific hooks
- repo: local
hooks:
# Check MkDocs configuration
- id: mkdocs-check
name: Check MkDocs config
entry: bash -c 'cd mkdocs-site && mkdocs build --strict --quiet'
language: system
files: ^(docs/.*\.md|mkdocs-site/mkdocs\.yml)$
pass_filenames: false
# Validate Python imports in MCP server
- id: check-mcp-imports
name: Check MCP server imports
entry: python -c "import sys; sys.path.insert(0, 'mcp-server/src'); import mkdocs_mcp"
language: system
files: ^mcp-server/src/
pass_filenames: false
# Check that documentation links are valid (basic check)
- id: check-doc-links
name: Check documentation internal links
entry: python -c "
import re, sys, pathlib;
docs_dir = pathlib.Path('docs');
md_files = list(docs_dir.rglob('*.md'));
all_files = {f.relative_to(docs_dir).as_posix() for f in md_files};
errors = [];
for f in md_files:
content = f.read_text(encoding='utf-8');
links = re.findall(r'\]\(([^)]+\.md)\)', content);
for link in links:
if not link.startswith('http') and link not in all_files:
errors.append(f'{f.relative_to(docs_dir)}: broken link to {link}');
if errors:
print('\n'.join(errors));
sys.exit(1)
"
language: system
files: ^docs/.*\.md$
pass_filenames: false
# Global configuration
ci:
autofix_commit_msg: |
[pre-commit.ci] auto fixes from pre-commit hooks
for more information, see https://pre-commit.ci
autofix_prs: true
autoupdate_branch: ''
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
autoupdate_schedule: weekly
skip: [mkdocs-check, check-mcp-imports] # Skip custom hooks in CI
submodules: false