# jritsema/python-sdk architecture

> Architecture diagram of the GitHub repository jritsema/python-sdk, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jritsema/python-sdk
- Repository: https://github.com/jritsema/python-sdk

## Overview

##### Main Components
- MCP Server Core:
- FastMCP server (located in src/mcp/server/fastmcp) that handles the protocol, routing, and execution of server logic.
- “lowlevel” server implementation which provides a more customizable view (src/mcp/server/lowlevel).
- Central role of the FastMCP “Server” as an interface between protocol events and application logic.
- Resources, Tools, and Prompts:
- As a separate submodule or component. For instance, “resources” (src/mcp/server/fastmcp/resources) expose data; “tools” (src/mcp/server/fastmcp/tools) implement functions or side effects; and “prompts” (src/mcp/server/fastmcp/prompts) define templates for LLM interactions.
- MCP Client:
- Client logic (in src/mcp/client) that uses interfaces such as stdio or SSE for connecting to the MCP server.
- CLI and Utility Components:
- Command-line interface(s) (src/mcp/cli) that allow users to run servers, install them into environments like Claude Desktop, or otherwise interact in development mode.
- Shared Modules & Utilities:
- Shared libraries (src/mcp/shared) that provide common types, session management, logging, and other helper functions.
- Examples and Test Infrastructure:
- In a separate lane or as a modular “usage” section, display various examples (under examples/) such as the “simple-chatbot”, “simple-prompt” server, and the “SQLite Explorer” that demonstrate real-world uses of the SDK.
- Tests (tests/) that ensure integrity of the client, server, and shared modules.

##### Relationships and Interactions
- From the MCP Client (initiated via CLI) to the MCP Server – showing how requests (e.g., “call tool”, “list resource”) are issued.
- Inside the server, illustrate internal communication channels where the server dispatches incoming protocol messages to the appropriate resource/tool/prompt handlers.
- Lifecycle management (for initialization and shutdown) interacting with the “lowlevel” server’s lifespan functions.
- External interactions:
- For instance, the integration with external dependencies such as standard transports (e.g., stdio, SSE) or HTTP libraries (like httpx used in async tools).

##### Architectural Patterns & Design Principles
- Separation of Concerns:
- Modular Design:
- The division of the server code (into fastmcp, lowlevel, and shared utilities) enforces good modularity.
- Extensibility:

##### Relevant Technologies & Frameworks
- That the project is built in Python and uses “uv” for project management.
- External libraries shown in examples (like httpx for asynchronous HTTP calls or PIL for image processing) can be noted as part of the tool implementations.
- References to various files that configure GitHub workflows, pre-commit, and deployment scripts which emphasize automated testing and CI/CD integration.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Server Side
    subgraph "Server Side"
        direction TB
        FS["FastMCP Server"]:::server
        subgraph "FastMCP Submodules"
            direction TB
            R["Resources"]:::server_sub
            T["Tools"]:::server_sub
            P["Prompts"]:::server_sub
        end
        LL["Low-Level Server"]:::server
        FS -->|"invokes"| R
        FS -->|"invokes"| T
        FS -->|"invokes"| P
        FS ---|"lifecycle"| LL
    end

    %% Client Side
    subgraph "Client Side"
        direction TB
        client["MCP Client"]:::client
        entry["Client Entry (__main__)"]:::client
        stdio["Stdio Interface"]:::client
        sse["SSE Interface"]:::client
        client --> entry
        client --> stdio
        client --> sse
    end

    %% CLI & Utilities
    subgraph "CLI & Utilities"
        direction TB
        cli["CLI"]:::cli
        claude["Claude Integration"]:::cli
        cli --> claude
        shared["Shared Modules"]:::utility
        context["Context Module"]:::utility
        session["Session Module"]:::utility
        shared --> context
        shared --> session
    end

    %% Examples & Tests
    subgraph "Examples & Tests"
        direction TB
        ex_servers["Server Examples"]:::example
        ex_clients["Client Examples"]:::example
        tests["Tests Suite"]:::example
    end

    %% External Dependencies
    ext["External Dependencies (uv, httpx, PIL)"]:::external

    %% Interactions and Data Flow
    entry -->|"request"| FS
    entry -->|"request"| LL
    cli -->|"initiates"| FS
    shared --- FS
    shared --- client
    FS --- ext
    T --- ext

    %% Legend Connections for internal routing in server
    FS -->|"ResourceRequest"| R
    FS -->|"ToolCall"| T
    FS -->|"PromptInvocation"| P

    %% Click Events
    click FS "https://github.com/jritsema/python-sdk/blob/main/src/mcp/server/fastmcp/server.py"
    click R "https://github.com/jritsema/python-sdk/tree/main/src/mcp/server/fastmcp/resources/"
    click T "https://github.com/jritsema/python-sdk/tree/main/src/mcp/server/fastmcp/tools/"
    click P "https://github.com/jritsema/python-sdk/tree/main/src/mcp/server/fastmcp/prompts/"
    click LL "https://github.com/jritsema/python-sdk/blob/main/src/mcp/server/lowlevel/server.py"
    click client "https://github.com/jritsema/python-sdk/tree/main/src/mcp/client/"
    click entry "https://github.com/jritsema/python-sdk/blob/main/src/mcp/client/__main__.py"
    click stdio "https://github.com/jritsema/python-sdk/blob/main/src/mcp/client/stdio.py"
    click sse "https://github.com/jritsema/python-sdk/blob/main/src/mcp/client/sse.py"
    click cli "https://github.com/jritsema/python-sdk/tree/main/src/mcp/cli/"
    click claude "https://github.com/jritsema/python-sdk/blob/main/src/mcp/cli/claude.py"
    click shared "https://github.com/jritsema/python-sdk/tree/main/src/mcp/shared/"
    click context "https://github.com/jritsema/python-sdk/blob/main/src/mcp/shared/context.py"
    click session "https://github.com/jritsema/python-sdk/blob/main/src/mcp/shared/session.py"
    click ex_servers "https://github.com/jritsema/python-sdk/tree/main/examples/servers/"
    click ex_clients "https://github.com/jritsema/python-sdk/tree/main/examples/clients/"
    click tests "https://github.com/jritsema/python-sdk/tree/main/tests/"

    %% Styles
    classDef server fill:#ffcccc,stroke:#990000,stroke-width:2px;
    classDef server_sub fill:#ffdabc,stroke:#cc3300,stroke-width:2px;
    classDef client fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef cli fill:#f0e68c,stroke:#b8860b,stroke-width:2px;
    classDef utility fill:#ccccff,stroke:#000099,stroke-width:2px;
    classDef example fill:#ffffcc,stroke:#999900,stroke-width:2px;
    classDef external fill:#e8e8e8,stroke:#666666,stroke-width:2px;
```
