# rawveg/ollama-mcp architecture

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

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

## Overview

##### Project Type and Purpose
- This is a Node.js–based MCP (Model Context Protocol) server, written in TypeScript and packaged as a CLI tool (`src/cli.ts` → `ollama-mcp` command).
- It sits between MCP‐compatible client applications (e.g., Claude Desktop, Cline) and Ollama’s local LLM API, translating MCP requests into Ollama API calls and returning results over HTTP.
- Its responsibilities: list models, pull models, chat, fetch model details, and manage ports/configuration.

##### File Structure
- Top‐level:
- `package.json`, `tsconfig.json` – Node/TypeScript build and run configuration
- `mcp.json` – MCP meta/config descriptor
- `README.md`, `LICENSE` – project documentation and license
- `src/` directory:
- `cli.ts` – CLI entrypoint that parses args/env and launches the server
- `index.ts` – core HTTP server implementation, handlers for `/models`, `/chat`, etc.

##### Main Components
A. Client Layer
- MCP‐compatible applications (e.g., Claude Desktop, Cline)
- They issue HTTP requests to the MCP server on the configured port.
B. Server Layer (Node.js Process)
- CLI Launcher
- Reads `PORT`, `OLLAMA_API`, other env vars
- Loads `mcp.json` configuration
- Instantiates HTTP server
- HTTP Server
- Route handlers for GET `/models`, POST `/models/pull`, POST `/chat`, GET `/models/:name`
- Implements MCP request/response schema
- MCP Adapter
- Translates incoming HTTP requests to Ollama API calls
- Marshals responses back into MCP‐compatible JSON
C. External Service
- Ollama Local API (`http://localhost:11434` by default)
- Endpoints for listing, pulling, chatting, model info
- Environment Variables & Config
- `PORT`, `OLLAMA_API` override defaults
- `mcp.json` describes how the server integrates with host MCP apps

##### Architectural Patterns and Design Principles
- Layered architecture: CLI bootstrapper → HTTP server → protocol adapter → external API
- Adapter pattern: abstracts Ollama API behind MCP protocol
- Twelve‐factor app: config via environment, no persistent storage

##### Technologies, Frameworks, and Libraries
- Node.js (v16+), TypeScript
- HTTP library (e.g., built‐in `http` or Express)
- `mcp.json` format for MCP metadata
- NPM packaging for global install and `npx` invocation

##### Essential Details to Capture
- CLI startup sequence feeding env vars and `mcp.json` into the server
- Port management (default 3456, overridable via `PORT`)
- All four HTTP endpoints and their purpose
- The stateless, on‐the‐fly translation to Ollama API calls
- Integration points at both ends: MCP client on one side, Ollama on the other

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "MCP Clients"
        Clients["MCP-Compatible Clients"]:::client
    end

    Clients -->|"HTTP/JSON (MCP)"| HTTPServer

    subgraph "Node.js Process"
        CLI["CLI Launcher"]:::server
        HTTPServer["HTTP Server\n(GET /models, POST /models/pull,\nPOST /chat, GET /models/:name)"]:::server
        Adapter["MCP Adapter"]:::server

        CLI --> HTTPServer
        HTTPServer --> Adapter
    end

    Adapter -->|"HTTP/JSON"| Ollama["Ollama Local API\n(http://localhost:11434)"]:::external
    Ollama -->|"HTTP/JSON"| Adapter
    HTTPServer -->|"HTTP/JSON (MCP)"| Clients

    subgraph "Configuration & Docs"
        Env["Environment Variables\n(PORT, OLLAMA_API)"]:::config
        MCPMeta["mcp.json"]:::config
        TSConfig["tsconfig.json"]:::config
        Package["package.json"]:::config
        Readme["README.md"]:::config
        License["LICENSE"]:::config

        Env --> CLI
        MCPMeta --> CLI
        TSConfig --> CLI
        Package --> CLI
        Readme --> CLI
        License --> CLI
    end

    click CLI "https://github.com/rawveg/ollama-mcp/blob/main/src/cli.ts"
    click HTTPServer "https://github.com/rawveg/ollama-mcp/blob/main/src/index.ts"
    click Adapter "https://github.com/rawveg/ollama-mcp/blob/main/src/index.ts"
    click MCPMeta "https://github.com/rawveg/ollama-mcp/blob/main/mcp.json"
    click TSConfig "https://github.com/rawveg/ollama-mcp/blob/main/tsconfig.json"
    click Package "https://github.com/rawveg/ollama-mcp/blob/main/package.json"
    click Readme "https://github.com/rawveg/ollama-mcp/blob/main/README.md"
    click License "https://github.com/rawveg/ollama-mcp/tree/main/LICENSE"

    classDef client fill:#cce5ff,stroke:#004085,color:#004085
    classDef server fill:#d4edda,stroke:#155724,color:#155724
    classDef config fill:#e2e3e5,stroke:#6c757d,color:#383d41
    classDef external fill:#fff3cd,stroke:#856404,color:#856404
```
