Skip to main content
Glama
PiSearch MCP Host

PiSearch MCP Host

README.md
# PiSearch MCP Host

Free-knowledge search router and [Model Context Protocol (MCP)](https://modelcontextprotocol.io) server. Turns public APIs into a zero-key search endpoint (`GET /search`) and AI tool host (`POST /mcp`) built to run on a Raspberry Pi.

## What It Connects

| Route | Sources | Protocol / Format |
|---|---|---|
| `wiki` | Wikipedia Search & REST Summary | MediaWiki JSON + REST v1 |
| `data` | Wikidata Entity & SPARQL | Wikibase JSON + SPARQL 1.1 |
| `news` | Tagesschau, GDELT, Hacker News | JSON (5s timeout per source) |
| `web` | SearXNG (self-hosted on Pi) | SearXNG JSON (`settings.yml`) |

Outputs normalized JSON: `[{ source, title, url, snippet, date }]`.

## Quick Start (Raspberry Pi)

### Docker Compose (MCP Host `:8000` + SearXNG `:8080`)

```bash
cd deploy/pi
WIKIMEDIA_CONTACT_EMAIL="you@example.com" docker compose up -d --build
```

### Native Node.js 22 + systemd

```bash
chmod +x deploy/pi/install.sh
./deploy/pi/install.sh
```

### Local Development

```bash
npm install
npm run dev
```

## Endpoints

| Endpoint | Purpose |
|---|---|
| `GET /search?q=<query>&type=<auto\|wiki\|data\|news\|web>` | Normalized JSON search array |
| `POST /mcp` | MCP Streamable HTTP (`tools`, `resources`, `prompts`) |
| `GET /sse` & `POST /messages` | Legacy MCP SSE transport |
| `GET /openapi.json` | OpenAPI 3.1.0 specification (Swagger UI at `/`) |
| `GET /api/metrics` | Live search throughput, latency, cache, and per-source stats |
| `GET /api/health-report` | Local subsystem & upstream adapter health check |
| `GET /llms.txt` | AI-readable service & tool map |

## Repository Layout

```text
├── server.ts                  # Express + MCP Streamable HTTP & SSE host
├── src/
│   ├── server/
│   │   ├── searchRouter.ts    # Routing rules, 5s timeouts, TTL cache, metrics
│   │   ├── mcpServer.ts       # MCP tools, resources, and prompts
│   │   ├── mcpStdio.ts        # Stdio MCP transport for SSH / local CLI
│   │   ├── openapiSpec.ts     # OpenAPI 3.1.0 generator
│   │   └── repoExport.ts      # Allowlisted bundle manifest
│   ├── components/            # Minimalistic console, Swagger UI, Health & Repo views
│   └── shared/types.ts        # Shared TypeScript contracts
├── deploy/pi/                 # Dockerfile, docker-compose, SearXNG, systemd, install.sh
├── public/                    # favicon.svg & llms.txt
├── AGENTS.md                  # Collaboration guide for AI coding agents
├── CONTRIBUTING.md            # Guide for human contributors
├── CITATION.cff               # Citation metadata (Open Knowledge format)
└── LICENSE                    # MIT License (Murilo Bell)
```

## Environment Variables

Configure via `.env` on your Raspberry Pi (or Secrets in cloud hosting):

- `PORT` — `8000` on Raspberry Pi (`3000` in AI Studio preview)
- `WIKIMEDIA_CONTACT_EMAIL` — Contact email for Wikimedia `User-Agent` (~200 req/min)
- `SEARXNG_URL` — e.g. `http://127.0.0.1:8080` (`json` enabled in `settings.yml`)
- `CACHE_TTL_MINUTES` — `5` to `15` (default `10`)
- `MCP_AUTH_TOKEN` — Optional Bearer token for `/mcp` and `/sse`

## Attribution & License

Created by **Murilo Bell** · Released under the [MIT License](LICENSE).  
Tagesschau `api2u` results are for private, non-commercial use only.