Skip to main content
Glama
clinic-hr-mcp

clinic-hr-mcp

by iemaly
README.md
# clinic-hr-mcp

A small [Model Context Protocol](https://modelcontextprotocol.io) server that lets an AI agent work with clinic HR data, but only the parts it has been granted.

It is a public, demo-data version of a pattern I use at work. Every person and record in it is fictional.

## The idea

Giving an AI agent access to HR data is easy. Making sure it sees only what it should is the actual work. This server enforces two rules:

1. **Scopes decide which tools exist.** A tool is registered only when its scope is granted, so a read-only agent never even sees `request_leave`. It has nothing to try.
2. **Locations decide which records exist.** An agent scoped to one clinic gets staff, shifts and balances from that clinic only. A record from another clinic returns the same "not found" as an id that doesn't exist, so nothing leaks.

Writes are drafts. `request_leave` checks the balance and returns a request that a manager still has to approve. The agent never makes the final decision.

## Tools

| Tool | Scope | What it does |
|---|---|---|
| `list_staff` | `staff:read` | Staff at the visible clinics, optional role filter |
| `get_leave_balance` | `staff:read` | Remaining leave days for one person |
| `list_shifts` | `planning:read` | Shifts on a date at the visible clinics |
| `request_leave` | `leave:write` | Draft leave request, checked against the balance |

## Run it

```bash
npm install
npm run build
MCP_SCOPES=staff:read,planning:read MCP_LOCATIONS=amsterdam npm start
```

- `MCP_SCOPES`: comma-separated, from `staff:read`, `planning:read`, `leave:write`. Defaults to `staff:read`.
- `MCP_LOCATIONS`: comma-separated, from `amsterdam`, `zaandam`, `venlo`, `dubai`. Empty means no clinic is visible. Access is opt-in.

An unknown scope or location stops the server at startup instead of being ignored.

### Use it from an MCP client

```json
{
  "mcpServers": {
    "clinic-hr": {
      "command": "node",
      "args": ["/path/to/clinic-hr-mcp/dist/index.js"],
      "env": { "MCP_SCOPES": "staff:read,planning:read", "MCP_LOCATIONS": "amsterdam" }
    }
  }
}
```

## In production

Here the access context comes from environment variables so the demo runs anywhere. In a real deployment it comes from an OAuth 2.0 access token, issued through the authorization code flow with PKCE, and validated on every request. The tool code does not change: `createServer(ctx)` takes the same `AccessContext` either way.

## Tests

```bash
npm test
```

The tests connect a real MCP client to the server in memory and check that tools appear and disappear with scopes, that records from other clinics stay hidden, and that leave requests respect the balance.

## Stack

TypeScript · `@modelcontextprotocol/sdk` · Zod · Vitest

## License

MIT