@cyanheads/guardian-mcp-server
by cyanheads
README.md
<div align="center">
<h1>@cyanheads/guardian-mcp-server</h1>
<p><b>Search, browse, and retrieve full article text from The Guardian's journalism archive (1999–present) via MCP. STDIO or Streamable HTTP.</b>
<div>3 Tools</div>
</p>
</div>
<div align="center">
[](./CHANGELOG.md) [](./LICENSE) [](https://github.com/users/cyanheads/packages/container/package/guardian-mcp-server) [](https://modelcontextprotocol.io/) [](https://www.npmjs.com/package/@cyanheads/guardian-mcp-server) [](https://www.typescriptlang.org/) [](https://bun.sh/)
</div>
<div align="center">
[](https://github.com/cyanheads/guardian-mcp-server/releases/latest/download/guardian-mcp-server.mcpb) [](https://cursor.com/en/install-mcp?name=guardian-mcp-server&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBjeWFuaGVhZHMvZ3VhcmRpYW4tbWNwLXNlcnZlciJdLCJlbnYiOnsiTUNQX1RSQU5TUE9SVF9UWVBFIjoic3RkaW8iLCJHVUFSRElBTl9BUElfS0VZIjoieW91ci1hcGkta2V5In19) [](https://vscode.dev/redirect?url=vscode:mcp/install?%7B%22name%22%3A%22guardian-mcp-server%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40cyanheads%2Fguardian-mcp-server%22%5D%2C%22env%22%3A%7B%22MCP_TRANSPORT_TYPE%22%3A%22stdio%22%2C%22GUARDIAN_API_KEY%22%3A%22your-api-key%22%7D%7D)
[](https://www.npmjs.com/package/@cyanheads/mcp-ts-core)
</div>
---
## Overview
The Guardian's journalism archive (1999–present), via the Guardian Open Platform API. Search full text, browse by section or tag, and fetch individual articles from any MCP client. Runs as a stdio process or a local Streamable HTTP server.
### Tools
| Tool | Description |
|:-----|:------------|
| `guardian_search` | Full-text search across The Guardian's archive with optional section, tag, contributor, and date filters |
| `guardian_get_article` | Fetch a single Guardian article by ID with body text and metadata |
| `guardian_browse` | Browse by section or tag, or discover available sections and tags, across four modes |
---
## Capability reference
### `guardian_search` <sub>tool</sub>
- Boolean `query` syntax (`AND`/`OR`/`NOT`, quoted phrases), optional `section`/`tag`/`contributor` and `from_date`/`to_date` (`YYYY-MM-DD`) filters; `order_by`: `relevance` (default), `newest`, or `oldest`; `page` + `page_size` (1–50, default 10)
- Articles carry metadata, HTML-stripped body text and a `truncated` flag; results include `total`, `page`, `pages`, `page_size`, and `order_by`
- Typed error reasons: `unauthorized`, `no_results`, `invalid_date`, `api_error` (retryable)
---
### `guardian_get_article` <sub>tool</sub>
- Required `article_id`: the path-slug `id` returned by `guardian_search` or `guardian_browse`
- Returns HTML-stripped body text, metadata, contributors, pillar/section classification, and `truncated`
- Typed error reasons: `unauthorized`, `not_found`, `api_error` (retryable)
---
### `guardian_browse` <sub>tool</sub>
- Four `mode` values: `section_latest` (requires `section_id`), `tag_latest` (requires `tag_id`), `list_sections`, `list_tags`; `page` + `page_size` (1–50, default 10) for articles and tags
- `list_tags` filters by optional `query` and `tag_type` (`keyword`, `contributor`, `blog`, `series`, `tone`, `type`, `publication`, `newspaper-book`, `newspaper-book-section`); output carries `mode`, `total`, and the matching `results`/`sections`/`tags` array
- Typed error reasons: `unauthorized`, `missing_section_id`, `missing_tag_id`, `section_not_found`, `tag_not_found`, `api_error` (retryable)
---
## Features
Built on [`@cyanheads/mcp-ts-core`](https://github.com/cyanheads/mcp-ts-core): stdio and Streamable HTTP transports, pluggable auth (`none` / `jwt` / `oauth`), swappable storage (`in-memory`, `filesystem`, `Supabase`, `Cloudflare KV/R2/D1`), structured logging with optional OpenTelemetry tracing.
Guardian-specific:
- Wraps the Guardian Open Platform API with a free non-commercial developer key
- Full body text extraction — HTML stripped, not just headlines or abstracts
- Contributor ID discovery via `guardian_browse` mode `list_tags` with `tag_type=contributor`
- Section and tag taxonomy browsing (`list_sections`, `list_tags`) for filter discovery before searching
- Free tier: 5,000 requests/day, 12 calls/second — the server applies no additional throttling
Agent-friendly output:
- Article bodies are capped at 2,000 words across all three tools; `truncated: true` signals a cut. Read the article's `web_url` for the full text.
- Typed error reasons across all three tools, each paired with a recovery hint
- `total` / `page` / `pages` on every paginated response so callers can track result scope
- Declared recovery hints on error responses, with a request ID for matching server logs
---
## Getting started
Add the following to your MCP client configuration file. Register for a free Guardian Open Platform API key at [open-platform.theguardian.com/access](https://open-platform.theguardian.com/access).
```json
{
"mcpServers": {
"guardian-mcp-server": {
"type": "stdio",
"command": "bunx",
"args": ["@cyanheads/guardian-mcp-server@latest"],
"env": {
"MCP_TRANSPORT_TYPE": "stdio",
"MCP_LOG_LEVEL": "info",
"GUARDIAN_API_KEY": "your-api-key"
}
}
}
}
```
Or with npx (no Bun required):
```json
{
"mcpServers": {
"guardian-mcp-server": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@cyanheads/guardian-mcp-server@latest"],
"env": {
"MCP_TRANSPORT_TYPE": "stdio",
"MCP_LOG_LEVEL": "info",
"GUARDIAN_API_KEY": "your-api-key"
}
}
}
}
```
Or with Docker:
```json
{
"mcpServers": {
"guardian-mcp-server": {
"type": "stdio",
"command": "docker",
"args": [
"run", "-i", "--rm",
"-e", "MCP_TRANSPORT_TYPE=stdio",
"-e", "GUARDIAN_API_KEY=your-api-key",
"ghcr.io/cyanheads/guardian-mcp-server:latest"
]
}
}
}
```
For Streamable HTTP, set the transport and start the server:
```sh
MCP_TRANSPORT_TYPE=http MCP_HTTP_PORT=3010 GUARDIAN_API_KEY=your-api-key bun run start:http
# Server listens at http://localhost:3010/mcp
```
### Prerequisites
- [Bun v1.4.0](https://bun.sh/) or higher (or Node.js v24+).
- A free Guardian Open Platform API key — register at [open-platform.theguardian.com/access](https://open-platform.theguardian.com/access). The non-commercial developer tier is free and instant.
### Installation
1. **Clone the repository:**
```sh
git clone https://github.com/cyanheads/guardian-mcp-server.git
```
2. **Navigate into the directory:**
```sh
cd guardian-mcp-server
```
3. **Install dependencies:**
```sh
bun install
```
4. **Configure environment:**
```sh
cp .env.example .env
# Edit .env and set GUARDIAN_API_KEY
```
---
## Configuration
| Variable | Description | Default |
|:---------|:------------|:--------|
| `GUARDIAN_API_KEY` | **Required.** Free developer key from [open-platform.theguardian.com/access](https://open-platform.theguardian.com/access). | — |
| `MCP_TRANSPORT_TYPE` | Transport: `stdio` or `http`. | `stdio` |
| `MCP_HTTP_PORT` | Port for HTTP server. | `3010` |
| `MCP_SESSION_MODE` | HTTP session mode: `stateless`, `stateful`, or `auto` (resolves to `stateful`). The server declares `stateless`; an exported value overrides it. | `stateless` |
| `MCP_AUTH_MODE` | Auth mode: `none`, `jwt`, or `oauth`. | `none` |
| `MCP_LOG_LEVEL` | Log level (RFC 5424). | `info` |
| `LOGS_DIR` | Directory for log files (Node.js only). | `<project-root>/logs` |
| `LOG_TOOL_FAILURE_PAYLOADS` | Log failed tool arguments and results, redacted by key name and capped by `LOG_TOOL_FAILURE_PAYLOAD_MAX_BYTES` (default `16384`). Secrets in free-form values remain visible. | `false` |
| `STORAGE_PROVIDER_TYPE` | Storage backend. | `in-memory` |
| `OTEL_ENABLED` | Enable [OpenTelemetry instrumentation](https://github.com/cyanheads/mcp-ts-core/tree/main/docs/telemetry) (spans, metrics, completion logs). | `false` |
| `OTEL_EXPORTER_OTLP_ENDPOINT` | Base OTLP URL; traces use `/v1/traces`, metrics use `/v1/metrics`. | — |
| `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` | Opt-in OTLP log endpoint, used as-is. | — |
See [`.env.example`](./.env.example) for the full list of optional overrides.
---
## Running the server
### Local development
- **Build and run:**
```sh
# One-time build
bun run rebuild
# Run the built server
bun run start:stdio
# or
bun run start:http
```
- **Run checks and tests:**
```sh
bun run devcheck # Lint, format, typecheck, security
bun run test # Vitest test suite
bun run lint:mcp # Validate MCP definitions against spec
```
### Docker
```sh
docker build -t guardian-mcp-server .
docker run --rm -e GUARDIAN_API_KEY=your-api-key -p 3010:3010 guardian-mcp-server
```
The Dockerfile defaults to HTTP transport, stateless session mode, and logs to `/var/log/guardian-mcp-server`. OpenTelemetry peer dependencies are installed by default — build with `--build-arg OTEL_ENABLED=false` to omit them.
---
## Project structure
| Directory | Purpose |
|:----------|:--------|
| `src/index.ts` | `createApp()` entry point — registers tools and initializes the Guardian service. |
| `src/config` | Server-specific environment variable parsing (`GUARDIAN_API_KEY`). |
| `src/mcp-server/tools` | Tool definitions (`*.tool.ts`): `guardian_search`, `guardian_get_article`, `guardian_browse`. |
| `src/services/guardian` | Guardian Open Platform API client, normalization, and type definitions. |
| `tests/` | Unit and integration tests. |
| `docs/` | Design document and directory tree. |
---
## Development guide
See [`CLAUDE.md`](./CLAUDE.md) / [`AGENTS.md`](./AGENTS.md) for development guidelines and architectural rules. The short version:
- Handlers throw, framework catches — no `try/catch` in tool logic
- Use `ctx.log` for request-scoped logging, `ctx.state` for tenant-scoped storage
- Register new tools in the `createApp()` `tools` array in `src/index.ts`
- Wrap external API calls: validate raw → normalize to domain type → return output schema; never fabricate missing fields
---
## Contributing
Issues are welcome. Run checks and tests before submitting:
```sh
bun run devcheck
bun run test
```
---
## License
Apache-2.0 — see [LICENSE](LICENSE) for details.
---
*Powered by [The Guardian](https://open-platform.theguardian.com/).*
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessSlow