Skip to main content
Glama
secheaders-mcp

secheaders-mcp

by hellonimen
README.md
# secheaders-mcp

An **MCP (Model Context Protocol) server** that lets an AI assistant check a website's HTTP security headers. Ask it something like *"How secure are the headers on example.com?"* and the assistant calls this server, gets back a grade from A to F, and explains which headers are missing and how to fix them.

I built it to learn MCP hands-on, combining it with my background in web application security.

## Tools

| Tool | What it does | Network? |
|---|---|---|
| `check_url(url)` | Fetches a public http(s) URL with one GET and grades its security headers | Yes, a single passive request |
| `analyze_raw_headers(raw_headers)` | Grades headers you paste as text (`Name: value` per line) | No |
| `explain_header(header)` | Explains what a header protects against and gives a safe example value | No |

**What it checks:** HSTS, Content-Security-Policy, X-Frame-Options, X-Content-Type-Options, Referrer-Policy and Permissions-Policy. It also flags version leaks (`Server`, `X-Powered-By`), an HSTS max-age under 180 days, and a CSP that allows `unsafe-inline` or `unsafe-eval`.

## Security design

Giving an AI agent a tool that fetches URLs is risky. A prompt-injection attack could trick the agent into calling the tool against `http://127.0.0.1/admin` or the cloud metadata endpoint `169.254.169.254`. This is **SSRF** (server-side request forgery). To prevent it, `check_url`:

- only accepts `http://` and `https://` URLs, so `file://`, `ftp://` and `gopher://` are rejected
- resolves the hostname first and **refuses private, loopback, link-local and reserved IPs**
- sends one passive GET with a 10-second timeout, so it does no scanning or fuzzing

These rules are covered by tests.

## Quick start

```bash
git clone https://github.com/hellonimen/secheaders-mcp.git
cd secheaders-mcp
python -m venv .venv && source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install -e ".[dev]"
pytest -v            # 17 tests
```

### Use it with Claude Desktop (or any MCP client)

Add this to `claude_desktop_config.json`, then restart Claude Desktop:

```json
{
  "mcpServers": {
    "secheaders": {
      "command": "python",
      "args": ["-m", "secheaders_mcp.server"]
    }
  }
}
```

If you installed it in a virtual environment, use the full path to that environment's `python`.

### Try it with the MCP Inspector

```bash
mcp dev src/secheaders_mcp/server.py
```

## How it's built

```
src/secheaders_mcp/
  checks.py   # pure logic: grading + SSRF guard (no MCP code, easy to unit test)
  server.py   # MCP layer: 3 tools registered with @mcp.tool(), stdio transport
tests/
  test_checks.py  # unit tests for grading and SSRF blocking
  test_server.py  # end-to-end: a real MCP client lists and calls the tools in-process
```

- Built on the official MCP Python SDK (`MCPServer`, v2).
- The business logic is kept separate from the MCP layer, so the same checks could be reused in a CLI or a CI job.
- GitHub Actions runs the test suite on Python 3.11 and 3.12 for every push.

## Scoring

The score is the percentage of the 6 recommended headers present, minus 5 points for each version leak and each weak setting. Grades: A ≥ 90, B ≥ 75, C ≥ 50, D ≥ 25, otherwise F.

## Ideas for next steps

- A TLS certificate tool (expiry date, protocol version)
- Cookie flag checks (`Secure`, `HttpOnly`, `SameSite`)
- A Streamable HTTP transport, so a team can share one server

## Disclaimer

Only scan sites you own or have permission to test. `check_url` makes one ordinary request, the same as a browser visit.

## License

MIT

TDQS

A3.7/5.0

Scored across 3 tools

Disambiguation5/5

Although check_url and analyze_raw_headers both grade security headers, their boundary is explicit: one fetches a live URL while the other processes pasted header text. explain_header is clearly educational and separate from grading.

Naming Consistency5/5

All three tool names use a consistent snake_case verb_noun pattern: check_url, analyze_raw_headers, explain_header. The naming is predictable and easy to infer.

Tool Count5/5

Three tools are well-scoped for a security-header grading service: live scan, offline scan, and header explanation. Each tool covers a distinct workflow with no filler.

Completeness4/5

The surface covers the core tasks of grading a live URL, grading pasted headers, and explaining individual headers. Minor gaps exist, such as no consolidated reference/list of supported headers or explicit remediation output for analyze_raw_headers, but these are workable.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues