# yugaaank/needle-mcp architecture

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

- Interactive diagram: https://gitdiagram.com/yugaaank/needle-mcp
- Repository: https://github.com/yugaaank/needle-mcp

## Overview

Needle MCP exposes local Needle-model capabilities as read-only MCP tools over stdio. A client lists tools or calls one; the server dispatches extraction, classification, summarization, tool selection/ranking, and context filtering, returning structured JSON. Startup prepares the platform engine, and repeated identical requests use a local SQLite cache. The README documents chunking, JSON repair, and local-only operation; those details are not all visible in the sampled implementation, so their internal wiring is not asserted here.

Main entry points: [`src/needle_mcp/mcp.py`](https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/mcp.py) (Tool dispatch), [`src/needle_mcp/cache.py`](https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/cache.py) (Response cache)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mcp["MCP interface"]
  node_server["Stdio MCP server<br/>[mcp.py]"]
  node_tool_dispatch["Tool dispatch<br/>[mcp.py]"]
end

subgraph group_runtime["Local inference"]
  node_engine_setup["Engine setup<br/>[mcp.py]"]
  node_needle_model["Needle inference"]
end

subgraph group_features["Tool capabilities"]
  node_extract["Structured extraction<br/>[mcp.py]"]
  node_classify["Classification<br/>[mcp.py]"]
  node_summarize["Summarization<br/>[mcp.py]"]
  node_call_tools["Tool calling<br/>[mcp.py]"]
  node_route_tools["Tool ranking<br/>[mcp.py]"]
  node_filter_context["Context filtering<br/>[mcp.py]"]
  node_response_repair["JSON repair<br/>[mcp.py]"]
end

subgraph group_state["Local state"]
  node_cache[("Response cache<br/>[cache.py]")]
end

node_client(("MCP client"))
node_engine_source["Needle engine wheel"]

node_client -->|"sends MCP requests"| node_server
node_server -->|"dispatches calls"| node_tool_dispatch
node_server -->|"prepares at startup"| node_engine_setup
node_engine_setup -->|"downloads or reuses"| node_engine_source
node_tool_dispatch -->|"handles tool"| node_extract
node_tool_dispatch -->|"handles tool"| node_classify
node_tool_dispatch -->|"handles tool"| node_summarize
node_tool_dispatch -->|"handles tool"| node_call_tools
node_tool_dispatch -->|"handles tool"| node_route_tools
node_tool_dispatch -->|"handles tool"| node_filter_context
node_extract -->|"runs inference"| node_needle_model
node_classify -->|"runs inference"| node_needle_model
node_summarize -->|"runs inference"| node_needle_model
node_call_tools -.->|"runs inference"| node_needle_model
node_filter_context -.->|"selects relevant chunks"| node_needle_model
node_tool_dispatch -->|"reads and writes"| node_cache
node_tool_dispatch -.->|"repairs JSON"| node_response_repair

click node_server "https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/mcp.py"
click node_tool_dispatch "https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/mcp.py"
click node_engine_setup "https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/mcp.py"
click node_extract "https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/mcp.py"
click node_classify "https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/mcp.py"
click node_summarize "https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/mcp.py"
click node_call_tools "https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/mcp.py"
click node_route_tools "https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/mcp.py"
click node_filter_context "https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/mcp.py"
click node_response_repair "https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/mcp.py"
click node_cache "https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/cache.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_server,node_tool_dispatch,node_client toneBlue
class node_engine_setup,node_needle_model toneAmber
class node_extract,node_classify,node_summarize,node_call_tools,node_route_tools,node_filter_context,node_response_repair toneMint
class node_cache toneRose
class node_engine_source toneIndigo
```

## Components

### MCP interface

- [Stdio MCP server](https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/mcp.py): `src/needle_mcp/mcp.py`
- [Tool dispatch](https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/mcp.py): `src/needle_mcp/mcp.py`

### Local inference

- [Engine setup](https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/mcp.py): `src/needle_mcp/mcp.py`
- **Needle inference**

### Tool capabilities

- [Structured extraction](https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/mcp.py): `src/needle_mcp/mcp.py`
- [Classification](https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/mcp.py): `src/needle_mcp/mcp.py`
- [Summarization](https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/mcp.py): `src/needle_mcp/mcp.py`
- [Tool calling](https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/mcp.py): `src/needle_mcp/mcp.py`
- [Tool ranking](https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/mcp.py): `src/needle_mcp/mcp.py`
- [Context filtering](https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/mcp.py): `src/needle_mcp/mcp.py`
- [JSON repair](https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/mcp.py): `src/needle_mcp/mcp.py`

### Local state

- [Response cache](https://github.com/yugaaank/needle-mcp/blob/main/src/needle_mcp/cache.py): `src/needle_mcp/cache.py`

### Other components

- **MCP client**
- **Needle engine wheel**

## Connections

- MCP client → Stdio MCP server: sends MCP requests (evidence: `README.md`)
- Stdio MCP server → Tool dispatch: dispatches calls (evidence: `src/needle_mcp/mcp.py`)
- Stdio MCP server → Engine setup: prepares at startup (evidence: `README.md`)
- Engine setup → Needle engine wheel: downloads or reuses (evidence: `README.md`)
- Tool dispatch → Structured extraction: handles tool (evidence: `README.md`)
- Tool dispatch → Classification: handles tool (evidence: `README.md`)
- Tool dispatch → Summarization: handles tool (evidence: `README.md`)
- Tool dispatch → Tool calling: handles tool (evidence: `README.md`)
- Tool dispatch → Tool ranking: handles tool (evidence: `README.md`)
- Tool dispatch → Context filtering: handles tool (evidence: `README.md`)
- Structured extraction → Needle inference: runs inference (evidence: `src/needle_mcp/mcp.py`)
- Classification → Needle inference: runs inference (evidence: `src/needle_mcp/mcp.py`)
- Summarization → Needle inference: runs inference (evidence: `src/needle_mcp/mcp.py`)
- Tool calling → Needle inference: runs inference
- Context filtering → Needle inference: selects relevant chunks
- Tool dispatch → Response cache: reads and writes (evidence: `src/needle_mcp/mcp.py`)
- Tool dispatch → JSON repair: repairs JSON (evidence: `src/needle_mcp/mcp.py`)
