Skip to main content
Glama
mcp-template-base

mcp-template-base

by dbranham20
README.md
# mcp-template-base

A starting point for read-only MCP servers that run on Railway and connect to Claude. It includes:

- **Sign-in:** Claude connects with OAuth. Each connection needs your `SETUP_SECRET`, so finding the URL
  isn't enough to get in.
- **One example tool** and an example API client to replace with your service.
- **Checks on every pull request:** lint with security rules, strict type checks, tests with a coverage
  minimum, Semgrep, a secret scan of the full history, and a dependency vulnerability audit.
- **`CLAUDE.md`:** the standards any AI assistant working in the repo must follow.

## Start a new server from this template

1. On GitHub: **Use this template -> Create a new repository**.
2. Follow "Adapting this template" in [`CLAUDE.md`](CLAUDE.md), or ask Claude to.
3. In the new repo's settings:
   - **Rules -> Rulesets:** add a rule for `main` that requires pull requests and the status checks
     `Lint, types and tests`, `Semgrep` and `Leaked secrets`.
   - **Advanced Security:** turn on Dependabot alerts and Dependabot security updates.
   - For a public repo, also turn on CodeQL (default setup), secret scanning and push protection. They're
     free for public repos.

## Deploy to Railway

1. Railway -> **New Project -> Deploy from GitHub repo**.
2. Add a **volume** with mount path `/data`. Connections are stored there; the server won't start on
   Railway without one.
3. **Settings -> Networking -> Generate Domain.**
4. Add the variables below, then check that `https://<your-domain>/health` returns `ok`.

| Variable | Value |
|---|---|
| `SETUP_SECRET` | 32+ random characters: `python -c "import secrets; print(secrets.token_urlsafe(32))"` |
| `MCP_NAME` | optional, shown on the connect page |
| `MCP_DOMAIN` | only for a custom domain; Railway's domain is used otherwise |
| `SERVICE_API_BASE` | base URL of the API this server reads from |
| `SERVICE_API_KEY` | that API's key |
| `SERVICE_CACHE_SECONDS` | optional, default 300; 0 turns caching off |

Until `SETUP_SECRET` and a domain are set, the server serves only `/health`.

## Connect from Claude

1. **Settings -> Connectors -> Add custom connector**, URL `https://<your-domain>/mcp`.
2. Click **Connect** and enter your `SETUP_SECRET` on the page that opens.

To disconnect everything, change `SETUP_SECRET` in Railway. Every existing connection ends on the next
deploy.

## Security

- Access tokens last an hour and refresh tokens rotate. Only hashes of tokens are stored.
- Only Claude's callback address and Claude Code's localhost callback can receive access.
- Requests addressed to any other host name are rejected.
- No access log is written, because request paths carry one-time codes.
- Anyone with access to your Railway project can read your variables and the volume.

## Development

    pip install -r requirements-dev.txt
    ruff check . && ruff format --check . && mypy && python -m pytest

Run locally with `DATA_DIR=.data MCP_DOMAIN=localhost SETUP_SECRET=... python server.py`. Claude can only
connect over HTTPS, so use Railway (or a tunnel) for end-to-end testing.

## License

MIT