chore: add D212 lint rule to enforce Google-style docstrings (#1892)

This commit is contained in:
Felix Weinberger 2026-01-16 16:10:52 +00:00 • committed by GitHub
commit d41d0c0128
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
143 changed files with 452 additions and 925 deletions

View file

@ -136,8 +136,7 @@ Let's create a simple MCP server that exposes a calculator tool and some data:
<!-- snippet-source examples/snippets/servers/fastmcp_quickstart.py -->
```python
"""
FastMCP quickstart example.
"""FastMCP quickstart example.
Run from the repository root:
uv run examples/snippets/servers/fastmcp_quickstart.py
@ -727,9 +726,8 @@ Client usage:
<!-- snippet-source examples/snippets/clients/completion_client.py -->
```python
"""
cd to the `examples/snippets` directory and run:
uv run completion-client
"""cd to the `examples/snippets` directory and run:
uv run completion-client
"""
import asyncio
@ -1004,9 +1002,8 @@ MCP servers can use authentication by providing an implementation of the `TokenV
<!-- snippet-source examples/snippets/servers/oauth_server.py -->
```python
"""
Run from the repository root:
uv run examples/snippets/servers/oauth_server.py
"""Run from the repository root:
uv run examples/snippets/servers/oauth_server.py
"""
from pydantic import AnyHttpUrl
@ -1245,9 +1242,8 @@ Note that `uv run mcp run` or `uv run mcp dev` only supports server using FastMC
<!-- snippet-source examples/snippets/servers/streamable_config.py -->
```python
"""
Run from the repository root:
uv run examples/snippets/servers/streamable_config.py
"""Run from the repository root:
uv run examples/snippets/servers/streamable_config.py
"""
from mcp.server.fastmcp import FastMCP
@ -1283,9 +1279,8 @@ You can mount multiple FastMCP servers in a Starlette application:
<!-- snippet-source examples/snippets/servers/streamable_starlette_mount.py -->
```python
"""
Run from the repository root:
uvicorn examples.snippets.servers.streamable_starlette_mount:app --reload
"""Run from the repository root:
uvicorn examples.snippets.servers.streamable_starlette_mount:app --reload
"""
import contextlib
@ -1394,8 +1389,7 @@ You can mount the StreamableHTTP server to an existing ASGI server using the `st
<!-- snippet-source examples/snippets/servers/streamable_http_basic_mounting.py -->
```python
"""
Basic example showing how to mount StreamableHTTP server in Starlette.
"""Basic example showing how to mount StreamableHTTP server in Starlette.
Run from the repository root:
uvicorn examples.snippets.servers.streamable_http_basic_mounting:app --reload
@ -1442,8 +1436,7 @@ _Full example: [examples/snippets/servers/streamable_http_basic_mounting.py](htt
<!-- snippet-source examples/snippets/servers/streamable_http_host_mounting.py -->
```python
"""
Example showing how to mount StreamableHTTP server using Host-based routing.
"""Example showing how to mount StreamableHTTP server using Host-based routing.
Run from the repository root:
uvicorn examples.snippets.servers.streamable_http_host_mounting:app --reload
@ -1490,8 +1483,7 @@ _Full example: [examples/snippets/servers/streamable_http_host_mounting.py](http
<!-- snippet-source examples/snippets/servers/streamable_http_multiple_servers.py -->
```python
"""
Example showing how to mount multiple StreamableHTTP servers with path configuration.
"""Example showing how to mount multiple StreamableHTTP servers with path configuration.
Run from the repository root:
uvicorn examples.snippets.servers.streamable_http_multiple_servers:app --reload
@ -1548,8 +1540,7 @@ _Full example: [examples/snippets/servers/streamable_http_multiple_servers.py](h
<!-- snippet-source examples/snippets/servers/streamable_http_path_config.py -->
```python
"""
Example showing path configuration when mounting FastMCP.
"""Example showing path configuration when mounting FastMCP.
Run from the repository root:
uvicorn examples.snippets.servers.streamable_http_path_config:app --reload
@ -1644,9 +1635,8 @@ For more control, you can use the low-level server implementation directly. This
<!-- snippet-source examples/snippets/servers/lowlevel/lifespan.py -->
```python
"""
Run from the repository root:
uv run examples/snippets/servers/lowlevel/lifespan.py
"""Run from the repository root:
uv run examples/snippets/servers/lowlevel/lifespan.py
"""
from collections.abc import AsyncIterator
@ -1761,8 +1751,7 @@ The lifespan API provides:
<!-- snippet-source examples/snippets/servers/lowlevel/basic.py -->
```python
"""
Run from the repository root:
"""Run from the repository root:
uv run examples/snippets/servers/lowlevel/basic.py
"""
@ -1840,9 +1829,8 @@ The low-level server supports structured output for tools, allowing you to retur
<!-- snippet-source examples/snippets/servers/lowlevel/structured_output.py -->
```python
"""
Run from the repository root:
uv run examples/snippets/servers/lowlevel/structured_output.py
"""Run from the repository root:
uv run examples/snippets/servers/lowlevel/structured_output.py
"""
import asyncio
@ -1943,9 +1931,8 @@ For full control over the response including the `_meta` field (for passing data
<!-- snippet-source examples/snippets/servers/lowlevel/direct_call_tool_result.py -->
```python
"""
Run from the repository root:
uv run examples/snippets/servers/lowlevel/direct_call_tool_result.py
"""Run from the repository root:
uv run examples/snippets/servers/lowlevel/direct_call_tool_result.py
"""
import asyncio
@ -2023,9 +2010,7 @@ For servers that need to handle large datasets, the low-level server provides pa
<!-- snippet-source examples/snippets/servers/pagination_example.py -->
```python
"""
Example of implementing pagination with MCP server decorators.
"""
"""Example of implementing pagination with MCP server decorators."""
import mcp.types as types
from mcp.server.lowlevel import Server
@ -2068,9 +2053,7 @@ _Full example: [examples/snippets/servers/pagination_example.py](https://github.
<!-- snippet-source examples/snippets/clients/pagination_client.py -->
```python
"""
Example of consuming paginated MCP endpoints from a client.
"""
"""Example of consuming paginated MCP endpoints from a client."""
import asyncio
@ -2129,9 +2112,8 @@ The SDK provides a high-level client interface for connecting to MCP servers usi
<!-- snippet-source examples/snippets/clients/stdio_client.py -->
```python
"""
cd to the `examples/snippets/clients` directory and run:
uv run client
"""cd to the `examples/snippets/clients` directory and run:
uv run client
"""
import asyncio
@ -2221,9 +2203,8 @@ Clients can also connect using [Streamable HTTP transport](https://modelcontextp
<!-- snippet-source examples/snippets/clients/streamable_basic.py -->
```python
"""
Run from the repository root:
uv run examples/snippets/clients/streamable_basic.py
"""Run from the repository root:
uv run examples/snippets/clients/streamable_basic.py
"""
import asyncio
@ -2261,9 +2242,8 @@ When building MCP clients, the SDK provides utilities to help display human-read
<!-- snippet-source examples/snippets/clients/display_utilities.py -->
```python
"""
cd to the `examples/snippets` directory and run:
uv run display-utilities-client
"""cd to the `examples/snippets` directory and run:
uv run display-utilities-client
"""
import asyncio
@ -2346,8 +2326,7 @@ The SDK includes [authorization support](https://modelcontextprotocol.io/specifi
<!-- snippet-source examples/snippets/clients/oauth_client.py -->
```python
"""
Before running, specify running MCP RS server URL.
"""Before running, specify running MCP RS server URL.
To spin up RS server locally, see
examples/servers/simple-auth/README.md

View file

@ -1,6 +1,5 @@
#!/usr/bin/env python3
"""
MCP OAuth conformance test client.
"""MCP OAuth conformance test client.
This client is designed to work with the MCP conformance test framework.
It automatically handles OAuth flows without user interaction by programmatically
@ -89,8 +88,7 @@ class InMemoryTokenStorage(TokenStorage):
class ConformanceOAuthCallbackHandler:
"""
OAuth callback handler that automatically fetches the authorization URL
"""OAuth callback handler that automatically fetches the authorization URL
and extracts the auth code, without requiring user interaction.
This mimics the behavior of the TypeScript ConformanceOAuthProvider.
@ -101,8 +99,7 @@ class ConformanceOAuthCallbackHandler:
self._state: str | None = None
async def handle_redirect(self, authorization_url: str) -> None:
"""
Fetch the authorization URL and extract the auth code from the redirect.
"""Fetch the authorization URL and extract the auth code from the redirect.
The conformance test server returns a redirect with the auth code,
so we can capture it programmatically.
@ -148,8 +145,7 @@ class ConformanceOAuthCallbackHandler:
async def run_authorization_code_client(server_url: str) -> None:
"""
Run the conformance test client with authorization code flow.
"""Run the conformance test client with authorization code flow.
This function:
1. Connects to the MCP server with OAuth authorization code flow
@ -180,8 +176,7 @@ async def run_authorization_code_client(server_url: str) -> None:
async def run_client_credentials_jwt_client(server_url: str) -> None:
"""
Run the conformance test client with client credentials flow using private_key_jwt (SEP-1046).
"""Run the conformance test client with client credentials flow using private_key_jwt (SEP-1046).
This function:
1. Connects to the MCP server with OAuth client_credentials grant
@ -223,8 +218,7 @@ async def run_client_credentials_jwt_client(server_url: str) -> None:
async def run_client_credentials_basic_client(server_url: str) -> None:
"""
Run the conformance test client with client credentials flow using client_secret_basic.
"""Run the conformance test client with client credentials flow using client_secret_basic.
This function:
1. Connects to the MCP server with OAuth client_credentials grant

View file

@ -1,6 +1,5 @@
#!/usr/bin/env python3
"""
Simple MCP client example with OAuth authentication support.
"""Simple MCP client example with OAuth authentication support.
This client connects to an MCP server using streamable HTTP transport with OAuth.

View file

@ -1,5 +1,4 @@
"""
SSE Polling Demo Client
"""SSE Polling Demo Client
Demonstrates the client-side auto-reconnect for SSE polling pattern.

View file

@ -1,5 +1,4 @@
"""
FastMCP Complex inputs Example
"""FastMCP Complex inputs Example
Demonstrates validation via pydantic with complex models.
"""

View file

@ -1,5 +1,4 @@
"""
FastMCP Desktop Example
"""FastMCP Desktop Example
A simple example that exposes the desktop directory as a resource.
"""

View file

@ -1,6 +1,4 @@
"""
FastMCP Echo Server with direct CallToolResult return
"""
"""FastMCP Echo Server with direct CallToolResult return"""
from typing import Annotated

View file

@ -1,6 +1,4 @@
"""
FastMCP Echo Server
"""
"""FastMCP Echo Server"""
from mcp.server.fastmcp import FastMCP

View file

@ -1,5 +1,4 @@
"""
FastMCP Icons Demo Server
"""FastMCP Icons Demo Server
Demonstrates using icons with tools, resources, prompts, and implementation.
"""

View file

@ -1,6 +1,4 @@
"""
FastMCP Echo Server that sends log messages and progress updates to the client
"""
"""FastMCP Echo Server that sends log messages and progress updates to the client"""
import asyncio

View file

@ -4,8 +4,7 @@
# uv pip install 'pydantic-ai-slim[openai]' asyncpg numpy pgvector
"""
Recursive memory system inspired by the human brain's clustering of memories.
"""Recursive memory system inspired by the human brain's clustering of memories.
Uses OpenAI's 'text-embedding-3-small' model and pgvector for efficient
similarity search.
"""

View file

@ -1,6 +1,4 @@
"""
FastMCP Example showing parameter descriptions
"""
"""FastMCP Example showing parameter descriptions"""
from pydantic import Field

View file

@ -1,5 +1,4 @@
"""
FastMCP Screenshot Example
"""FastMCP Screenshot Example
Give Claude a tool to capture and view screenshots.
"""
@ -15,8 +14,7 @@ mcp = FastMCP("Screenshot Demo")
@mcp.tool()
def take_screenshot() -> Image:
"""
Take a screenshot of the user's screen and return it as an image. Use
"""Take a screenshot of the user's screen and return it as an image. Use
this tool anytime the user wants you to look at something they're doing.
"""
import pyautogui

View file

@ -1,6 +1,4 @@
"""
FastMCP Echo Server
"""
"""FastMCP Echo Server"""
from mcp.server.fastmcp import FastMCP

View file

@ -2,8 +2,7 @@
# dependencies = []
# ///
"""
FastMCP Text Me Server
"""FastMCP Text Me Server
--------------------------------
This defines a simple FastMCP server that sends a text message to a phone number via https://surgemsg.com/.

View file

@ -1,5 +1,4 @@
"""
Example FastMCP server that uses Unicode characters in various places to help test
"""Example FastMCP server that uses Unicode characters in various places to help test
Unicode handling in tools and inspectors.
"""
@ -10,8 +9,7 @@ mcp = FastMCP()
@mcp.tool(description="🌟 A tool that uses various Unicode characters in its description: á é í ó ú ñ 漢字 🎉")
def hello_unicode(name: str = "世界", greeting: str = "¡Hola") -> str:
"""
A simple tool that demonstrates Unicode handling in:
"""A simple tool that demonstrates Unicode handling in:
- Tool description (emojis, accents, CJK characters)
- Parameter defaults (CJK characters)
- Return values (Spanish punctuation, emojis)

View file

@ -1,5 +1,4 @@
"""
FastMCP Weather Example with Structured Output
"""FastMCP Weather Example with Structured Output
Demonstrates how to use structured output with tools to return
well-typed, validated data that clients can easily process.

View file

@ -1,6 +1,5 @@
#!/usr/bin/env python3
"""
MCP Everything Server - Conformance Test Server
"""MCP Everything Server - Conformance Test Server
Server implementing all MCP features for conformance testing based on Conformance Server Specification.
"""

View file

@ -1,5 +1,4 @@
"""
Authorization Server for MCP Split Demo.
"""Authorization Server for MCP Split Demo.
This server handles OAuth flows, client registration, and token issuance.
Can be replaced with enterprise authorization servers like Auth0, Entra ID, etc.
@ -41,8 +40,7 @@ class AuthServerSettings(BaseModel):
class SimpleAuthProvider(SimpleOAuthProvider):
"""
Authorization Server provider with simple demo authentication.
"""Authorization Server provider with simple demo authentication.
This provider:
1. Issues MCP tokens after simple credential authentication
@ -98,8 +96,7 @@ def create_authorization_server(server_settings: AuthServerSettings, auth_settin
# Add token introspection endpoint (RFC 7662) for Resource Servers
async def introspect_handler(request: Request) -> Response:
"""
Token introspection endpoint for Resource Servers.
"""Token introspection endpoint for Resource Servers.
Resource Servers call this endpoint to validate tokens without
needing direct access to token storage.
@ -157,8 +154,7 @@ async def run_server(server_settings: AuthServerSettings, auth_settings: SimpleA
@click.command()
@click.option("--port", default=9000, help="Port to listen on")
def main(port: int) -> int:
"""
Run the MCP Authorization Server.
"""Run the MCP Authorization Server.
This server handles OAuth flows and can be used by multiple Resource Servers.

View file

@ -1,5 +1,4 @@
"""
Legacy Combined Authorization Server + Resource Server for MCP.
"""Legacy Combined Authorization Server + Resource Server for MCP.
This server implements the old spec where MCP servers could act as both AS and RS.
Used for backwards compatibility testing with the new split AS/RS architecture.
@ -87,8 +86,7 @@ def create_simple_mcp_server(server_settings: ServerSettings, auth_settings: Sim
@app.tool()
async def get_time() -> dict[str, Any]:
"""
Get the current server time.
"""Get the current server time.
This tool demonstrates that system information can be protected
by OAuth authentication. User must be authenticated to access it.

Some files were not shown because too many files have changed in this diff Show more