# llmcontext/gomcp architecture

> Architecture diagram of the GitHub repository llmcontext/gomcp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/llmcontext/gomcp
- Repository: https://github.com/llmcontext/gomcp

## Overview

##### Project Type and Core Purpose
This is a protocol implementation project that provides a standardized way for AI models to interact with external tools and data sources. It's specifically an implementation of Anthropic's Model Context Protocol in Go.

##### Main Components

A. Core Components:
- MCP Server
- Protocol Handler
- Tool Registry
- Transport Layer
- Proxy/Multiplexer
- Inspector

B. Supporting Components:
- Configuration Management
- Logging System
- Prompts Management
- JSON-RPC Handler

**[Client Layer]**

**[Transport Layer]**

**[Protocol Layer]**

**[Core Services Layer]**

**[Tool Providers Layer]**

##### Transport Layer (Top)
- Both stdio and socket transport options

##### Protocol Layer
- MCP and MUX protocol handlers
- JSON-RPC message handling

##### Core Services Layer
- Tool Registry
- Prompt Manager
- Configuration Manager
- Logger

##### Tool Providers Layer
- Tool Context
- Tool Implementation

##### Supporting Components (Side Panel)
- Inspector Interface
- Debug Protocol Handler

Connection Guidelines:

##### Interface points between layers

Special Considerations:

##### Multiplexer Architecture
- How the proxy/multiplexer can connect multiple MCP servers
- Hub and proxy components
- Use different line styles for control vs data flow

##### Tool Registration Flow
- Tool registration process
- Configuration loading
- Validation steps

##### Protocol Message Flow
- Initialize request/response
- Tool discovery process
- Demonstrate prompt handling

Labels and Annotations:

##### Error handling paths

Technical Details to Highlight:

##### JSON-RPC Communication
- Request/Response patterns
- Notification handling
- Schema validation

##### Tool Provider Interface
- Tool context creation
- Input/Output handling
- Configuration management

##### Transport Mechanisms
- stdio for Claude desktop
- Socket for network communication

- Component types
- Connection types
- Protocol message types
- State indicators

Remember to include the key directories from the file tree:
- channels/
- cmd/
- config/
- jsonrpc/
- protocol/
- tools/
- transport/

This will help developers understand how the code structure maps to the architectural components.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        CL[Client Application]
    end

    subgraph Transport
        ST["STDIO Transport"]:::transport
        SOC["Socket Transport"]:::transport
        BT["Base Transport"]:::transport
    end

    subgraph Protocol
        MCP["MCP Protocol"]:::protocol
        MUXP["MUX Protocol"]:::protocol
        JRPC["JSON-RPC Handler"]:::protocol
    end

    subgraph Core
        MS["MCP Server"]:::core
        MUXS["MUX Server"]:::core
        HUB["Hub"]:::core
        PROXY["Proxy"]:::core
        INSP["Inspector"]:::core
    end

    subgraph Services
        TR["Tool Registry"]:::service
        PR["Prompts Registry"]:::service
        CONF["Configuration"]:::service
        LOG["Logger"]:::service
    end

    subgraph Tools
        TC["Tool Context"]:::tool
        TI["Tool Implementation"]:::tool
    end

    subgraph Validation
        MV["Message Validator"]:::validation
    end

    %% Connections
    CL --> ST & SOC
    ST & SOC --> BT
    BT --> MCP & MUXP
    MCP & MUXP --> JRPC
    JRPC --> MS & MUXS
    MS & MUXS --> HUB
    HUB --> PROXY
    HUB --> INSP
    MS & MUXS --> TR
    TR --> TC
    TC --> TI
    JRPC --> MV

    %% Service Connections
    MS & MUXS & HUB --> LOG
    MS & MUXS & HUB --> CONF
    TR --> PR

    %% Styles
    classDef transport fill:#a8d1f0
    classDef protocol fill:#90EE90
    classDef core fill:#FFB347
    classDef service fill:#DEB887
    classDef tool fill:#DDA0DD
    classDef validation fill:#D3D3D3

    %% Click Events
    click ST "https://github.com/llmcontext/gomcp/blob/main/transport/stdio.go"
    click SOC "https://github.com/llmcontext/gomcp/tree/main/transport/socket/"
    click BT "https://github.com/llmcontext/gomcp/blob/main/transport/jsonRpcTransport.go"
    click MCP "https://github.com/llmcontext/gomcp/tree/main/protocol/mcp/"
    click MUXP "https://github.com/llmcontext/gomcp/tree/main/protocol/mux/"
    click JRPC "https://github.com/llmcontext/gomcp/blob/main/jsonrpc/types.go"
    click MS "https://github.com/llmcontext/gomcp/blob/main/channels/hubmcpserver/mcp_server.go"
    click MUXS "https://github.com/llmcontext/gomcp/blob/main/channels/hubmuxserver/mux_server.go"
    click HUB "https://github.com/llmcontext/gomcp/blob/main/channels/hub/hub.go"
    click PROXY "https://github.com/llmcontext/gomcp/blob/main/channels/proxy/proxy.go"
    click INSP "https://github.com/llmcontext/gomcp/blob/main/channels/hubinspector/inspector.go"
    click TR "https://github.com/llmcontext/gomcp/blob/main/tools/toolsRegistry.go"
    click PR "https://github.com/llmcontext/gomcp/blob/main/prompts/promptsRegistry.go"
    click CONF "https://github.com/llmcontext/gomcp/blob/main/config/server_configuration.go"
    click LOG "https://github.com/llmcontext/gomcp/blob/main/logger/logger.go"
    click TC "https://github.com/llmcontext/gomcp/blob/main/tools/context.go"
    click MV "https://github.com/llmcontext/gomcp/blob/main/jsonrpc/checkJsonMessage.go"
```
