# giancbaring/msim architecture

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

- Interactive diagram: https://gitdiagram.com/giancbaring/msim
- Repository: https://github.com/giancbaring/msim

## Overview

MSIM is a single-file MCP server that exposes AnythingLLM-backed tools to MCP clients over HTTP, SSE, and WebSocket. The main workflow is client request → transport handler → MCP method dispatch → tool validation/default workspace selection → upstream MCP wrapper → AnythingLLM. The README also describes interactive configuration, workspace detection, logging, and background supervision. Most runtime code is in MSIM.py; excerpts confirm HTTP and WebSocket handling, while SSE and several operational details are documented but unsampled.

Main entry points: [`MSIM.py`](https://github.com/giancbaring/msim/blob/main/MSIM.py) (JSON-RPC dispatch), [`submodules/anythingllm-mcp`](https://github.com/giancbaring/msim/tree/main/submodules/anythingllm-mcp) (AnythingLLM MCP wrapper)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_transports["Client transports"]
  node_http["HTTP /mcp<br/>[MSIM.py]"]
  node_sse["SSE /sse<br/>[MSIM.py]"]
  node_websocket["WebSocket /ws<br/>[MSIM.py]"]
end

subgraph group_protocol["MCP handling"]
  node_dispatch["JSON-RPC dispatch<br/>[MSIM.py]"]
  node_toolcatalog["Tool definitions<br/>[MSIM.py]"]
  node_validation["Tool validation<br/>[MSIM.py]"]
  node_workspace["Workspace selection<br/>[MSIM.py]"]
  node_prompts["Prompts and resources<br/>[MSIM.py]"]
end

subgraph group_backend["AnythingLLM backend"]
  node_mcpwrapper["AnythingLLM MCP wrapper"]
  node_anythingllm["AnythingLLM API"]
end

subgraph group_operations["Server operations"]
  node_configuration["Interactive configuration<br/>[MSIM.py]"]
  node_logging["Structured logging<br/>[MSIM.py]"]
  node_lifecycle["Server lifecycle<br/>[MSIM.py]"]
  node_supervisor["Restart supervisor<br/>[MSIM.py]"]
end

node_client(("MCP client"))
node_user(("Operator"))

node_client -->|"sends requests"| node_http
node_client -->|"opens stream"| node_sse
node_client -->|"opens socket"| node_websocket
node_http -->|"dispatches requests"| node_dispatch
node_websocket -->|"dispatches methods"| node_dispatch
node_dispatch -->|"lists tools"| node_toolcatalog
node_dispatch -->|"lists prompts/resources"| node_prompts
node_dispatch -->|"validates calls"| node_validation
node_dispatch -->|"selects workspace"| node_workspace
node_dispatch -->|"calls tools"| node_mcpwrapper
node_toolcatalog -->|"fetches definitions"| node_mcpwrapper
node_workspace -->|"fetches workspaces"| node_anythingllm
node_mcpwrapper -->|"bridges API"| node_anythingllm
node_user -->|"sets credentials"| node_configuration
node_configuration -->|"sets default"| node_workspace
node_user -->|"starts or stops"| node_lifecycle
node_lifecycle -->|"records events"| node_logging
node_lifecycle -.->|"supports restarts"| node_supervisor

click node_http "https://github.com/giancbaring/msim/blob/main/MSIM.py"
click node_sse "https://github.com/giancbaring/msim/blob/main/MSIM.py"
click node_websocket "https://github.com/giancbaring/msim/blob/main/MSIM.py"
click node_dispatch "https://github.com/giancbaring/msim/blob/main/MSIM.py"
click node_toolcatalog "https://github.com/giancbaring/msim/blob/main/MSIM.py"
click node_validation "https://github.com/giancbaring/msim/blob/main/MSIM.py"
click node_workspace "https://github.com/giancbaring/msim/blob/main/MSIM.py"
click node_mcpwrapper "https://github.com/giancbaring/msim/tree/main/submodules/anythingllm-mcp"
click node_prompts "https://github.com/giancbaring/msim/blob/main/MSIM.py"
click node_configuration "https://github.com/giancbaring/msim/blob/main/MSIM.py"
click node_logging "https://github.com/giancbaring/msim/blob/main/MSIM.py"
click node_lifecycle "https://github.com/giancbaring/msim/blob/main/MSIM.py"
click node_supervisor "https://github.com/giancbaring/msim/blob/main/MSIM.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_http,node_sse,node_websocket,node_client toneBlue
class node_dispatch,node_toolcatalog,node_validation,node_workspace,node_prompts toneAmber
class node_mcpwrapper,node_anythingllm toneMint
class node_configuration,node_logging,node_lifecycle,node_supervisor toneRose
class node_user toneIndigo
```

## Components

### Client transports

- [HTTP /mcp](https://github.com/giancbaring/msim/blob/main/MSIM.py): `MSIM.py`
- [SSE /sse](https://github.com/giancbaring/msim/blob/main/MSIM.py): `MSIM.py`
- [WebSocket /ws](https://github.com/giancbaring/msim/blob/main/MSIM.py): `MSIM.py`

### MCP handling

- [JSON-RPC dispatch](https://github.com/giancbaring/msim/blob/main/MSIM.py): `MSIM.py`
- [Tool definitions](https://github.com/giancbaring/msim/blob/main/MSIM.py): `MSIM.py`
- [Tool validation](https://github.com/giancbaring/msim/blob/main/MSIM.py): `MSIM.py`
- [Workspace selection](https://github.com/giancbaring/msim/blob/main/MSIM.py): `MSIM.py`
- [Prompts and resources](https://github.com/giancbaring/msim/blob/main/MSIM.py): `MSIM.py`

### AnythingLLM backend

- [AnythingLLM MCP wrapper](https://github.com/giancbaring/msim/tree/main/submodules/anythingllm-mcp): `submodules/anythingllm-mcp`
- **AnythingLLM API**

### Server operations

- [Interactive configuration](https://github.com/giancbaring/msim/blob/main/MSIM.py): `MSIM.py`
- [Structured logging](https://github.com/giancbaring/msim/blob/main/MSIM.py): `MSIM.py`
- [Server lifecycle](https://github.com/giancbaring/msim/blob/main/MSIM.py): `MSIM.py`
- [Restart supervisor](https://github.com/giancbaring/msim/blob/main/MSIM.py): `MSIM.py`

### Other components

- **MCP client**
- **Operator**

## Connections

- MCP client → HTTP /mcp: sends requests
- MCP client → SSE /sse: opens stream
- MCP client → WebSocket /ws: opens socket
- HTTP /mcp → JSON-RPC dispatch: dispatches requests
- WebSocket /ws → JSON-RPC dispatch: dispatches methods
- JSON-RPC dispatch → Tool definitions: lists tools
- JSON-RPC dispatch → Prompts and resources: lists prompts/resources
- JSON-RPC dispatch → Tool validation: validates calls
- JSON-RPC dispatch → Workspace selection: selects workspace
- JSON-RPC dispatch → AnythingLLM MCP wrapper: calls tools
- Tool definitions → AnythingLLM MCP wrapper: fetches definitions
- Workspace selection → AnythingLLM API: fetches workspaces
- AnythingLLM MCP wrapper → AnythingLLM API: bridges API
- Operator → Interactive configuration: sets credentials
- Interactive configuration → Workspace selection: sets default
- Operator → Server lifecycle: starts or stops
- Server lifecycle → Structured logging: records events
- Server lifecycle → Restart supervisor: supports restarts
