Metadata-Version: 2.4
Name: sane-mcp
Version: 0.1.0
Summary: MCP server for scanning (SANE), with previews and short-lived download links (S3-compatible storage), for any MCP client
Author: ispb88
License-Expression: MIT
Project-URL: Homepage, https://github.com/ispb88/sane-mcp
Project-URL: Issues, https://github.com/ispb88/sane-mcp/issues
Keywords: mcp,sane,scanning,scanner
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: End Users/Desktop
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Multimedia :: Graphics :: Capture :: Scanners
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: mcp<3,>=2.3
Requires-Dist: boto3>=1.35
Requires-Dist: python-sane>=2.9
Requires-Dist: pillow>=10.1
Dynamic: license-file

# sane-mcp

An MCP server that lets an AI assistant (any MCP client) use a scanner on your network through SANE.

## Why this one?

It works for assistants that run elsewhere, such as web or mobile clients, as well as local ones:

- **Results the AI can see.** Feeder or flatbed, multi-page PDFs or images. The client gets small
  watermarked previews to read and check.
- **No lost pages.** If nobody says where the pages are, it reads every page in the feeder, or scans the
  glass when the feeder is empty.
- **Full-quality files without exposing your disk.** Scans stay on your machine. When you want the actual
  file, that one file goes to *your* private S3-compatible bucket with a short-lived download link.
- **Works with quirky scanners.** The scanner, its sources and its modes are detected automatically, with
  overrides for devices that name them oddly.

## Tools

| Tool | What it does |
|---|---|
| `scan` | Scan from the feeder or the glass; returns the file name and previews |
| `list_scans`, `get_scan` | Saved scans: list, previews, download link |
| `list_scan_sources` | The scanner's sources and modes, and how the tool's names map to them |

## Install

Needs Linux with SANE and a supported scanner, and Python 3.11+. Installing builds `python-sane`, so it
also needs a C compiler and the SANE development headers (`libsane-dev` on Debian/Ubuntu; included with the `sane` package on Arch).

```sh
pipx install sane-mcp          # or: uv tool install sane-mcp
sane-mcp                       # stdio, for local clients
sane-mcp --http                # HTTP on 127.0.0.1:8711/mcp
```

For a local client that starts servers itself:

```json
{
  "mcpServers": {
    "scanner": {
      "command": "sane-mcp",
      "env": { "MCP_SCAN_DIR": "/home/me/Scans" }
    }
  }
}
```

To run it permanently over HTTP, see `examples/sane-mcp.service` and "Connecting remote clients" below.

## Settings (environment variables)

| Variable | Default | |
|---|---|---|
| `MCP_PORT`, `MCP_PATH` | `8711`, `/mcp` | HTTP listener (always 127.0.0.1) |
| `MCP_PUBLIC_HOST` | – | Public hostname(s) in front of it, comma-separated |
| `MCP_ALLOWED_ORIGINS` | – | Extra browser origins allowed to call it, comma-separated, e.g. `https://app.example.com` |
| `MCP_SCANNER` | first scanner found | SANE device name, e.g. `escl:https://192.0.2.10:443` |
| `MCP_SCAN_SOURCES`, `MCP_SCAN_MODES` | matched by name | JSON maps from the tool's names to the scanner's own, e.g. `{"adf": "ADF Front", "flatbed": "Flatbed"}` |
| `MCP_SCAN_NOTES` | – | Extra guidance for the client about your scanner's quirks |
| `MCP_SCAN_DIR` | `~/Documents/Scans` | Where scans are saved |
| `MCP_SCAN_LINK_MINUTES` | `5` | How long download links work, in minutes (up to 10080, 7 days) |
| `S3_ENDPOINT_URL`, `S3_REGION`, `S3_BUCKET`, `S3_ACCESS_KEY_ID`, `S3_SECRET_ACCESS_KEY`, `S3_ADDRESSING_STYLE` | – , `us-east-1`, …, `auto` | Storage for download links; see `examples/s3.env.example`. Scanning works without it |

If the automatic matching picks the wrong source or mode, `list_scan_sources` shows the scanner's own
names; `scan` accepts those too, or set `MCP_SCAN_SOURCES` / `MCP_SCAN_MODES`.

## Connecting remote clients

Remote (web) clients need a public HTTPS URL. **The server has no authentication of its own**: put it
behind a reverse proxy or tunnel that does (for example an OAuth-capable proxy or a zero-trust tunnel), and
set `MCP_PUBLIC_HOST` to that hostname. If the client calls it from a browser page, add that page's origin
to `MCP_ALLOWED_ORIGINS`. To use download links, the client must be able to reach your bucket's endpoint.

## Security

- Run it as a dedicated user; `examples/sane-mcp.service` shows a sandboxed systemd unit.
- Use a storage key limited to the one bucket, and a lifecycle rule that deletes old objects.
- Download links are only made for a scan the client asks for, and the server never downloads from URLs
  it's given.

## Known issues

- **Linux only.**

## Licence

MIT, see [LICENSE](LICENSE).
