# Second Shift MCP server template

A small, read-only [MCP](https://modelcontextprotocol.io) server that lets Second Shift look things up in
your own systems while it investigates an incident: an order or fulfilment system, billing, a CRM, a
database, internal admin APIs. The investigation cites what it finds as evidence; nothing is changed.

It has two example tools. Keep the ones you need and edit the allow-lists at the top of `src/server.ts`:

| Tool | Reads | Configure |
|---|---|---|
| `lookup_record` | One row set from an allow-listed database view, by its key column | `VIEWS`, `DATABASE_URL` |
| `get_resource` | One record from an internal HTTP API, by ID | `RESOURCES`, `INTERNAL_API_URL`, `INTERNAL_API_TOKEN` |

Both are marked read-only (`readOnlyHint`), so Second Shift allows them by default.

## Run it

```sh
npm install
MCP_TOKEN=$(openssl rand -hex 24) \
DATABASE_URL=postgres://second_shift_readonly:...@db.internal/app \
INTERNAL_API_URL=https://admin.internal.example.com/api \
INTERNAL_API_TOKEN=... \
npm start
```

Deploy it anywhere that gives it an **https** address reachable from the internet (Fly.io, Railway,
Render, Cloud Run, a container behind your load balancer). Second Shift refuses plain http and
private network addresses.

## Connect it in Second Shift

1. **Projects** → the project → **Your own systems** → **Connect**.
2. Name: e.g. `Orders API`. URL: `https://<your host>/mcp`.
3. Auth value: `Bearer <MCP_TOKEN>` (stored encrypted; never shown again).
4. Check the tools the agent may use, then **Save**.

## Keep it read-only

- **Database:** a user with `SELECT` on the listed views only. Make the views leave out personal data
  the investigation doesn't need (names, addresses); Second Shift also masks emails and phone numbers
  in what it keeps.
- **APIs:** a token with read scopes only; `get_resource` only does GET on the listed paths.
- **Tool names and descriptions** are what the agent reads to choose a tool: say what each returns.
- Add a tool only when it just reads. Second Shift calls allowed tools without asking a person.

## Adapting to other systems

Any tool works the same way: `server.registerTool(name, { description, inputSchema, annotations: { readOnlyHint: true } }, handler)`.
Return text (JSON is fine). Keep results short; Second Shift shortens long ones.
