# rishikeshl0510/typescript-sdk architecture

> Architecture diagram of the GitHub repository rishikeshl0510/typescript-sdk, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rishikeshl0510/typescript-sdk
- Repository: https://github.com/rishikeshl0510/typescript-sdk

## Overview

##### Project type and purpose
- From the file tree and README we see this is a single-package TypeScript SDK implementing the Model Context Protocol (MCP). It provides both:
- A high-level Client library (in src/client) for connecting to any MCP server.
- A high-level Server library (in src/server) for defining Resources, Tools and Prompts.
- Shared modules (in src/shared) that implement the core MCP wire-protocol, types, transport abstractions, serialization, etc.
- CLI entrypoint (src/cli.ts) exposing both client and server command-line tools.

##### File structure
- Top-level configuration and metadata: package.json, tsconfig.*, eslint.config.mjs, jest.config.js.
- src/
- client/ — high-level Client API, transports (stdio, websocket, SSE), tests and mocks.
- server/ — McpServer and low-level Server implementations, auth middleware, handlers, transports (stdio, SSE), tests.
- shared/ — protocol definitions, transport interface, URI templates, stdio helper, transport dispatch logic.
- __mocks__, integration-tests, unit tests sprinkled throughout client and server directories.
- README defines usage patterns: instantiating McpServer, adding resources/tools/prompts, wiring transports (StdioServerTransport, SSEServerTransport), creating Client with StdioClientTransport.

##### README for additional insights
- The “Overview” and “Core Concepts” sections describe a layered architecture:
- Transport layer (stdio, SSE, websocket)
- MCP protocol core (Shared)
- High-level API layers (Client vs. Server)
- Application code that wires in user-defined Resources/Tools/Prompts

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Module"
        CI["Client API"]:::sdk
        SCT["StdioClientTransport"]:::external
        WCT["WebSocketClientTransport"]:::external
        SECT["SSEClientTransport"]:::external
        CA["Client Auth Helpers"]:::sdk
    end

    subgraph "Shared Core"
        PC["Protocol Core"]:::sdk
        TI["Transport Interface"]:::sdk
        UT["URI Templates"]:::sdk
        SH["Stdio Helpers"]:::sdk
        SAU["Shared Auth Utilities"]:::sdk
    end

    subgraph "Server Module"
        SAAPI["Server API"]:::sdk
        MCP["McpServer Core"]:::sdk
        CMP["Completable Support"]:::sdk
        SST["StdioServerTransport"]:::external
        SSET["SSEServerTransport"]:::external
        subgraph "Server Auth"
            AR["Auth Router"]:::sdk
            AP["Auth Provider"]:::sdk
            AC["Auth Clients/Errors"]:::sdk
            subgraph "Auth Middleware"
                AM1["allowedMethods"]:::sdk
                AM2["bearerAuth"]:::sdk
                AM3["clientAuth"]:::sdk
            end
            subgraph "Auth Handlers"
                AH1["authorize"]:::sdk
                AH2["metadata"]:::sdk
                AH3["register"]:::sdk
                AH4["revoke"]:::sdk
                AH5["token"]:::sdk
            end
        end
    end

    CLI["CLI Entrypoint"]:::sdk
    UC["User Code (Resources/Tools/Prompts)"]:::user
    EO["External I/O (stdio/HTTP/SSE/WebSocket)"]:::external

    CI -->|"calls"| SCT
    CI -->|"calls"| WCT
    CI -->|"calls"| SECT
    CI -->|"uses"| CA

    SCT -->|"serialize/deserialize"| PC
    WCT -->|"serialize/deserialize"| PC
    SECT -->|"serialize/deserialize"| PC
    CA -->|"auth logic"| PC

    PC -->|"invokes"| SST
    PC -->|"invokes"| SSET
    TI -->|"implements"| SCT
    TI -->|"implements"| WCT
    TI -->|"implements"| SECT
    TI -->|"implements"| SST
    TI -->|"implements"| SSET
    UT -->|"templating"| PC
    SH -->|"stdio glue"| PC
    SAU -->|"auth utils"| PC

    SST -->|"route to"| SAAPI
    SSET -->|"route to"| SAAPI

    SAAPI -->|"defines"| MCP
    SAAPI -->|"calls"| AR
    MCP -->|"provides"| CMP
    AR -->|"uses"| AP
    AR -->|"uses"| AC
    AC -->|"error handling"| AR
    AP -->|"middleware"| AM1
    AP -->|"middleware"| AM2
    AP -->|"middleware"| AM3
    AM1 -->|"handler"| AH1
    AM2 -->|"handler"| AH5
    AM3 -->|"handler"| AH3
    SAAPI -->|"executes"| UC

    UC -->|"implements handlers"| AH2
    UC -->|"implements handlers"| AH4

    CLI -->|"entrypoint"| CI
    CLI -->|"entrypoint"| SAAPI

    EO -->|"channel"| SCT
    EO -->|"channel"| SST

    click CI "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/client/index.ts"
    click SCT "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/client/stdio.ts"
    click WCT "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/client/websocket.ts"
    click SECT "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/client/sse.ts"
    click CA "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/client/auth.ts"
    click SAAPI "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/server/index.ts"
    click MCP "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/server/mcp.ts"
    click CMP "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/server/completable.ts"
    click SST "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/server/stdio.ts"
    click SSET "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/server/sse.ts"
    click AR "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/server/auth/router.ts"
    click AP "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/server/auth/provider.ts"
    click AC "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/server/auth/clients.ts"
    click AM1 "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/server/auth/middleware/allowedMethods.ts"
    click AM2 "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/server/auth/middleware/bearerAuth.ts"
    click AM3 "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/server/auth/middleware/clientAuth.ts"
    click AH1 "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/server/auth/handlers/authorize.ts"
    click AH2 "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/server/auth/handlers/metadata.ts"
    click AH3 "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/server/auth/handlers/register.ts"
    click AH4 "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/server/auth/handlers/revoke.ts"
    click AH5 "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/server/auth/handlers/token.ts"
    click PC "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/shared/protocol.ts"
    click TI "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/shared/transport.ts"
    click UT "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/shared/uriTemplate.ts"
    click SH "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/shared/stdio.ts"
    click CLI "https://github.com/rishikeshl0510/typescript-sdk/blob/main/src/cli.ts"

    classDef sdk fill:#E0F7FA,stroke:#006064
    classDef external fill:#F5F5F5,stroke:#888
    classDef user fill:#E8F5E9,stroke:#2E7D32
```
