# chrishayuk/mcp-cli architecture

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

- Interactive diagram: https://gitdiagram.com/chrishayuk/mcp-cli
- Repository: https://github.com/chrishayuk/mcp-cli

## Overview

##### Component Details

a) CLI Interface Components:
- Entry Point (`__main__.py`)
- Command Router
- Chat Handler (`chat_handler.py`)
- Tools Handler (`tools_handler.py`)

b) Message System (Central):
- Message Types (show as a collection)
- Initialize Messages
- Ping Messages
- Tools Messages
- Prompts Messages
- Resources Messages
- Message Handlers
- JSON-RPC Implementation

c) Transport Layer:
- STDIO Transport
- Client Implementation
- Server Parameters
- Server Shutdown Handling

d) Configuration & Environment:
- Config Manager (`config.py`)
- Environment Handler (`environment.py`)
- Server Configuration

e) External Integrations:
- OpenAI API Connection
- Ollama Integration
- SQLite Server Connection

##### Important Relationships to Highlight

- Bidirectional communication between CLI and Message System
- Flow from user input through the system to model providers
- Demonstrate how the transport layer interfaces with both the message system and external servers
- Configuration influence on all components

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Interface_Layer
        CLI["CLI Interface"]:::cli
        click CLI "https://github.com/chrishayuk/mcp-cli/blob/main/src/mcpcli/__main__.py"
        CH["Chat Handler"]:::handler
        click CH "https://github.com/chrishayuk/mcp-cli/blob/main/src/mcpcli/chat_handler.py"
        TH["Tools Handler"]:::handler
        click TH "https://github.com/chrishayuk/mcp-cli/blob/main/src/mcpcli/tools_handler.py"
        CLI --> CH
        CLI --> TH
    end

    subgraph Core_Protocol_Layer
        subgraph Message_System
            MT["Message Types"]:::message
            click MT "https://github.com/chrishayuk/mcp-cli/tree/main/src/mcpcli/messages/message_types"
            MH["Message Handlers"]:::message
            click MH "https://github.com/chrishayuk/mcp-cli/blob/main/src/mcpcli/messages/send_message.py"

            subgraph Message_Types
                IM["Initialize Messages"]:::msgtype
                click IM "https://github.com/chrishayuk/mcp-cli/blob/main/src/mcpcli/messages/message_types/initialize_message.py"
                PM["Ping Messages"]:::msgtype
                click PM "https://github.com/chrishayuk/mcp-cli/blob/main/src/mcpcli/messages/message_types/ping_message.py"
                TM["Tools Messages"]:::msgtype
                click TM "https://github.com/chrishayuk/mcp-cli/blob/main/src/mcpcli/messages/message_types/tools_messages.py"
                PRM["Prompts Messages"]:::msgtype
                click PRM "https://github.com/chrishayuk/mcp-cli/blob/main/src/mcpcli/messages/message_types/prompts_messages.py"
                RM["Resources Messages"]:::msgtype
                click RM "https://github.com/chrishayuk/mcp-cli/blob/main/src/mcpcli/messages/message_types/resources_messages.py"
            end
        end

        subgraph Transport
            ST["STDIO Transport"]:::transport
            click ST "https://github.com/chrishayuk/mcp-cli/tree/main/src/mcpcli/transport/stdio"
            SC["STDIO Client"]:::transport
            click SC "https://github.com/chrishayuk/mcp-cli/blob/main/src/mcpcli/transport/stdio/stdio_client.py"
            SP["Server Parameters"]:::transport
            click SP "https://github.com/chrishayuk/mcp-cli/blob/main/src/mcpcli/transport/stdio/stdio_server_parameters.py"
            SS["Server Shutdown"]:::transport
            click SS "https://github.com/chrishayuk/mcp-cli/blob/main/src/mcpcli/transport/stdio/stdio_server_shutdown.py"
        end

        subgraph Config
            CM["Config Manager"]:::config
            click CM "https://github.com/chrishayuk/mcp-cli/blob/main/src/mcpcli/config.py"
            EH["Environment Handler"]:::config
            click EH "https://github.com/chrishayuk/mcp-cli/blob/main/src/mcpcli/environment.py"
            SCONF["Server Configuration"]:::config
            click SCONF "https://github.com/chrishayuk/mcp-cli/blob/main/server_config.json"
        end
    end

    subgraph Provider_Integration_Layer
        LC["LLM Client"]:::provider
        click LC "https://github.com/chrishayuk/mcp-cli/blob/main/src/mcpcli/llm_client.py"
        SPG["System Prompt Generator"]:::provider
        click SPG "https://github.com/chrishayuk/mcp-cli/blob/main/src/mcpcli/system_prompt_generator.py"
        CC["Connection Check"]:::provider
        click CC "https://github.com/chrishayuk/mcp-cli/blob/main/src/mcpcli/scripts/connection_check.py"
        OAI["OpenAI API"]:::external
        OLL["Ollama"]:::external
        DB[(SQLite)]:::database
    end

    %% Connections
    Interface_Layer --> Message_System
    Message_System --> Transport
    Transport --> Provider_Integration_Layer
    Config --> Interface_Layer
    Config --> Message_System
    Config --> Transport
    LC --> OAI
    LC --> OLL
    CC --> DB

    %% Styles
    classDef cli fill:#2196F3,stroke:#1565C0,color:white
    classDef handler fill:#42A5F5,stroke:#1565C0,color:white
    classDef message fill:#4CAF50,stroke:#2E7D32,color:white
    classDef msgtype fill:#81C784,stroke:#2E7D32,color:white
    classDef transport fill:#FFC107,stroke:#FFA000,color:black
    classDef config fill:#9E9E9E,stroke:#616161,color:white
    classDef provider fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef external fill:#E91E63,stroke:#C2185B,color:white
    classDef database fill:#795548,stroke:#4E342E,color:white
```
