# dreak7/mcphub architecture

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

- Interactive diagram: https://gitdiagram.com/dreak7/mcphub
- Repository: https://github.com/dreak7/mcphub

## Overview

This is a local stdio MCP gateway that exposes fallback web search and page extraction to Hermes, delegating requests across configured online providers. The main workflow is Hermes → MCP tool dispatch → validated, ordered provider fallback → normalized results and failure warnings. Configuration discovery and persistent provider cooldowns support that workflow; URL validation protects extraction requests. Some documented capabilities, including Jina and dynamic provider discovery, are represented at subsystem level because their complete implementation was not sampled.

Main entry points: [`mcp_gateway/search.py`](https://github.com/dreak7/mcphub/blob/master/mcp_gateway/search.py) (Extraction fallback), [`mcp_gateway/config.py`](https://github.com/dreak7/mcphub/blob/master/mcp_gateway/config.py) (Config loader), [`mcp_gateway/server.py`](https://github.com/dreak7/mcphub/blob/master/mcp_gateway/server.py) (MCP server), [`mcp_gateway/__main__.py`](https://github.com/dreak7/mcphub/blob/master/mcp_gateway/__main__.py) (Package entry point)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["MCP runtime"]
  node_entry["Package entry point<br/>[__main__.py]"]
  node_server["MCP server<br/>[server.py]"]
  node_tools["Tool registry and dispatch<br/>[server.py]"]
end

subgraph group_config["Configuration"]
  node_config_loader["Config loader<br/>[config.py]"]
  node_gateway_config["Gateway configuration<br/>[gateway.json]"]
  node_provider_config["Search provider settings<br/>[search.json]"]
  node_env_template["API key template<br/>[.env.example]"]
  node_state_file[("Persisted provider state")]
end

subgraph group_search["Search and extraction"]
  node_search_gateway["Search fallback<br/>[search.py]"]
  node_extract_gateway["Extraction fallback<br/>[search.py]"]
  node_url_validation["Public URL validation<br/>[search.py]"]
  node_normalization["Result normalization<br/>[search.py]"]
  node_cooldown[("Provider cooldown state<br/>[search.py]")]
end

subgraph group_integrations["Provider integrations"]
  node_providers["Search and extraction adapters<br/>[search.py]"]
  node_online_apis{{"Online provider APIs"}}
end

node_hermes(("Hermes Desktop"))

node_hermes -->|"starts over stdio"| node_entry
node_entry -->|"calls main"| node_server
node_server -->|"loads configuration"| node_config_loader
node_config_loader -->|"reads"| node_gateway_config
node_config_loader -->|"discovers and merges"| node_provider_config
node_config_loader -.->|"loads keys from"| node_env_template
node_server -->|"registers tools"| node_tools
node_tools -->|"dispatches search"| node_search_gateway
node_tools -->|"dispatches extraction"| node_extract_gateway
node_search_gateway -->|"tries providers"| node_providers
node_extract_gateway -->|"validates URLs"| node_url_validation
node_extract_gateway -->|"tries providers"| node_providers
node_providers -->|"sends requests"| node_online_apis
node_search_gateway -.->|"normalizes results"| node_normalization
node_extract_gateway -.->|"normalizes content"| node_normalization
node_search_gateway -.->|"checks and updates"| node_cooldown
node_extract_gateway -.->|"checks and updates"| node_cooldown
node_cooldown -.->|"persists state"| node_state_file

click node_entry "https://github.com/dreak7/mcphub/blob/master/mcp_gateway/__main__.py"
click node_server "https://github.com/dreak7/mcphub/blob/master/mcp_gateway/server.py"
click node_tools "https://github.com/dreak7/mcphub/blob/master/mcp_gateway/server.py"
click node_config_loader "https://github.com/dreak7/mcphub/blob/master/mcp_gateway/config.py"
click node_gateway_config "https://github.com/dreak7/mcphub/blob/master/config/gateway.json"
click node_provider_config "https://github.com/dreak7/mcphub/blob/master/config/providers/search.json"
click node_env_template "https://github.com/dreak7/mcphub/blob/master/config/.env.example"
click node_search_gateway "https://github.com/dreak7/mcphub/blob/master/mcp_gateway/search.py"
click node_extract_gateway "https://github.com/dreak7/mcphub/blob/master/mcp_gateway/search.py"
click node_url_validation "https://github.com/dreak7/mcphub/blob/master/mcp_gateway/search.py"
click node_normalization "https://github.com/dreak7/mcphub/blob/master/mcp_gateway/search.py"
click node_cooldown "https://github.com/dreak7/mcphub/blob/master/mcp_gateway/search.py"
click node_providers "https://github.com/dreak7/mcphub/blob/master/mcp_gateway/search.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_entry,node_server,node_tools toneBlue
class node_config_loader,node_gateway_config,node_provider_config,node_env_template,node_state_file toneAmber
class node_search_gateway,node_extract_gateway,node_url_validation,node_normalization,node_cooldown toneMint
class node_providers,node_online_apis toneRose
class node_hermes toneIndigo
```

## Components

### MCP runtime

- [Package entry point](https://github.com/dreak7/mcphub/blob/master/mcp_gateway/__main__.py): `mcp_gateway/__main__.py`
- [MCP server](https://github.com/dreak7/mcphub/blob/master/mcp_gateway/server.py): `mcp_gateway/server.py`
- [Tool registry and dispatch](https://github.com/dreak7/mcphub/blob/master/mcp_gateway/server.py): `mcp_gateway/server.py`

### Configuration

- [Config loader](https://github.com/dreak7/mcphub/blob/master/mcp_gateway/config.py): `mcp_gateway/config.py`
- [Gateway configuration](https://github.com/dreak7/mcphub/blob/master/config/gateway.json): `config/gateway.json`
- [Search provider settings](https://github.com/dreak7/mcphub/blob/master/config/providers/search.json): `config/providers/search.json`
- [API key template](https://github.com/dreak7/mcphub/blob/master/config/.env.example): `config/.env.example`
- **Persisted provider state**

### Search and extraction

- [Search fallback](https://github.com/dreak7/mcphub/blob/master/mcp_gateway/search.py): `mcp_gateway/search.py`
- [Extraction fallback](https://github.com/dreak7/mcphub/blob/master/mcp_gateway/search.py): `mcp_gateway/search.py`
- [Public URL validation](https://github.com/dreak7/mcphub/blob/master/mcp_gateway/search.py): `mcp_gateway/search.py`
- [Result normalization](https://github.com/dreak7/mcphub/blob/master/mcp_gateway/search.py): `mcp_gateway/search.py`
- [Provider cooldown state](https://github.com/dreak7/mcphub/blob/master/mcp_gateway/search.py): `mcp_gateway/search.py`

### Provider integrations

- [Search and extraction adapters](https://github.com/dreak7/mcphub/blob/master/mcp_gateway/search.py): `mcp_gateway/search.py`
- **Online provider APIs**

### Other components

- **Hermes Desktop**

## Connections

- Hermes Desktop → Package entry point: starts over stdio (evidence: `README.md`)
- Package entry point → MCP server: calls main (evidence: `mcp_gateway/__main__.py`)
- MCP server → Config loader: loads configuration (evidence: `mcp_gateway/server.py`)
- Config loader → Gateway configuration: reads (evidence: `README.md`)
- Config loader → Search provider settings: discovers and merges (evidence: `README.md`)
- Config loader → API key template: loads keys from (evidence: `README.md`)
- MCP server → Tool registry and dispatch: registers tools (evidence: `mcp_gateway/server.py`)
- Tool registry and dispatch → Search fallback: dispatches search (evidence: `mcp_gateway/server.py`)
- Tool registry and dispatch → Extraction fallback: dispatches extraction (evidence: `mcp_gateway/server.py`)
- Search fallback → Search and extraction adapters: tries providers (evidence: `mcp_gateway/search.py`)
- Extraction fallback → Public URL validation: validates URLs (evidence: `mcp_gateway/search.py`)
- Extraction fallback → Search and extraction adapters: tries providers (evidence: `mcp_gateway/search.py`)
- Search and extraction adapters → Online provider APIs: sends requests (evidence: `mcp_gateway/search.py`)
- Search fallback → Result normalization: normalizes results (evidence: `mcp_gateway/search.py`)
- Extraction fallback → Result normalization: normalizes content (evidence: `mcp_gateway/search.py`)
- Search fallback → Provider cooldown state: checks and updates (evidence: `mcp_gateway/search.py`)
- Extraction fallback → Provider cooldown state: checks and updates (evidence: `mcp_gateway/search.py`)
- Provider cooldown state → Persisted provider state: persists state (evidence: `README.md`)
