# anjor/ollama-mcp-client architecture

> Architecture diagram of the GitHub repository anjor/ollama-mcp-client, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/anjor/ollama-mcp-client
- Repository: https://github.com/anjor/ollama-mcp-client

## Overview

##### Project type and purpose
- This is an open-source Python client library for the Model Context Protocol (MCP) that uses the Ollama API.
- It implements the MCP Client tutorial, swapping out the Claude-specific code for an Ollama backend.
- It’s not a full-stack web app but a reusable library/tool that can be embedded in other Python code or run via CLI.

##### File structure
- Top-level:
- client.py – likely a CLI entrypoint or convenience wrapper
- examples/ollama_example.py – demo on how to invoke the client
- src/abstract/base_client.py – MCP Client abstract base class and interface
- src/clients/ollama_client.py – concrete implementation using Ollama stdio transport
- pyproject.toml, setup.py – packaging and dependency config
- Directory pattern:
- src/abstract: interface and shared base logic
- src/clients: pluggable implementations (currently only “ollama”)
- Transport: stdio only, spawning or connecting to an Ollama process.

##### README for additional insights
- Only stdio transport is supported now
- Installation: pip editable, usage via “uv run examples/ollama_example.py”
- Purpose: fetch the latest MCP data from an Ollama service.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Applications
    subgraph "User Applications"
        direction TB
        CLI["client.py"]:::userapp
        Example["examples/ollama_example.py"]:::userapp
    end

    %% MCP Client Library
    subgraph "MCP Client Library"
        direction TB
        subgraph "Abstract Layer"
            direction TB
            AbsInit["__init__.py"]:::abstract
            BaseClient["BaseClient"]:::abstract
        end
        subgraph "Clients (Pluggable)"
            direction TB
            ClientsInit["__init__.py"]:::clientpkg
            OllamaClient["OllamaClient"]:::clientimpl
        end
    end

    %% Transport and External
    StdIO["StdIO Transport"]:::transport
    OllamaProc["Ollama Process\n(Ollama API Server)"]:::external

    %% Packaging
    subgraph "Packaging Configuration"
        direction TB
        pyproject["pyproject.toml"]:::config
        setup["setup.py"]:::config
    end

    %% Data Flow
    CLI -->|"use BaseClient interface"| BaseClient
    Example -->|"use BaseClient interface"| BaseClient
    BaseClient -->|"calls implementation"| OllamaClient
    OllamaClient -->|"spawn/process"| StdIO
    StdIO -->|"stdin: send JSON"| OllamaProc
    OllamaProc -->|"stdout: response JSON"| StdIO
    StdIO -->|"read/deserialize"| OllamaClient
    OllamaClient -->|"return data"| BaseClient
    BaseClient -->|"deliver result"| CLI
    BaseClient -->|"deliver result"| Example

    %% Click Events
    click CLI "https://github.com/anjor/ollama-mcp-client/blob/main/client.py"
    click Example "https://github.com/anjor/ollama-mcp-client/blob/main/examples/ollama_example.py"
    click AbsInit "https://github.com/anjor/ollama-mcp-client/blob/main/src/abstract/__init__.py"
    click BaseClient "https://github.com/anjor/ollama-mcp-client/blob/main/src/abstract/base_client.py"
    click ClientsInit "https://github.com/anjor/ollama-mcp-client/blob/main/src/clients/__init__.py"
    click OllamaClient "https://github.com/anjor/ollama-mcp-client/blob/main/src/clients/ollama_client.py"
    click pyproject "https://github.com/anjor/ollama-mcp-client/blob/main/pyproject.toml"
    click setup "https://github.com/anjor/ollama-mcp-client/blob/main/setup.py"

    %% Styles
    classDef userapp fill:#FFD699,stroke:#E69A00,color:#000
    classDef abstract fill:#D0E1F9,stroke:#4A86E8,color:#000
    classDef clientpkg fill:#D9EAD3,stroke:#6AA84F,color:#000
    classDef clientimpl fill:#B4A7D6,stroke:#674EA7,color:#000
    classDef transport fill:#F9CB9C,stroke:#E69138,color:#000
    classDef external fill:#CFE2F3,stroke:#3D85C6,color:#000
    classDef config fill:#F4CCCC,stroke:#CC0000,color:#000
```
