# mark3labs/mcp-go architecture

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

- Interactive diagram: https://gitdiagram.com/mark3labs/mcp-go
- Repository: https://github.com/mark3labs/mcp-go

## Overview

##### Project Type and Purpose
- The project is a Go library that implements the Model Context Protocol, which is designed to let LLM applications interact with external data and tools. It’s essentially a server framework (with client examples) that exposes functionalities (tools), data (resources), and prompt templates for LLMs.
- The README provides usage examples, describing how to create a server, add tools (like a calculator or HTTP tool), and even offer resources and prompts. It’s clear this is intended to abstract protocol details so that developers can integrate external capabilities into LLM apps easily.

##### File Structure
- Top-Level Directories:
- client: Contains code for the MCP client implementation (with both stdio and SSE using Go).
- server: Implements the MCP server, including different communication methods (stdio, SSE) and internal generation components.
- mcp: Contains core protocol logic (tool definitions, types, utilities, prompts, etc.).
- examples: Provides sample usage of the MCP server in various contexts.
- .github: Contains workflow definitions for CI and release.
- testdata & other files support testing and licensing/documentation.
- The separation of code under client, server, and mcp shows a clear architecture that distinguishes between protocol-level (mcp package), server operations (server package), and client communications (client package).

## Diagram (Mermaid)

```mermaid
flowchart TD 
    %% Client/Examples Layer
    subgraph "Client/Examples Layer"
        Client["Client (stdio & SSE)"]:::client
        Examples["Examples (Integration Proofs)"]:::example
    end

    %% Server Layer
    subgraph "Server Layer"
        MCPServer["MCP Server"]:::server
        CodeGen["Internal Code Generation (internal/gen)"]:::server
    end

    %% Core Library Layer
    subgraph "Core Library Layer"
        MCPCore["MCP Core Library"]:::core
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        CICD["CI/CD Workflows"]:::ci
    end

    %% Relationships
    Client -->|"RequestToolCall"| MCPServer
    MCPServer -->|"ReturnToolResult"| Client
    MCPServer -->|"ValidatesWith"| MCPCore
    MCPServer -->|"UsesCodeGen"| CodeGen
    Examples -->|"DemonstratesUsageOf"| MCPServer

    %% Click Events
    click MCPCore "https://github.com/mark3labs/mcp-go/tree/main/mcp/"
    click MCPServer "https://github.com/mark3labs/mcp-go/tree/main/server/"
    click CodeGen "https://github.com/mark3labs/mcp-go/tree/main/server/internal/gen/"
    click Client "https://github.com/mark3labs/mcp-go/tree/main/client/"
    click Examples "https://github.com/mark3labs/mcp-go/tree/main/examples/"
    click CICD "https://github.com/mark3labs/mcp-go/tree/main/.github/workflows/"

    %% Styles
    classDef client fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef server fill:#66ccff,stroke:#333,stroke-width:2px;
    classDef core fill:#99ff99,stroke:#333,stroke-width:2px;
    classDef example fill:#cc99ff,stroke:#333,stroke-width:2px;
    classDef ci fill:#ff9999,stroke:#333,stroke-width:2px;
```
