MCP server starter: give AI agents secure access to internal systems
We use this starter when an agent needs access to internal systems such as a CRM, an ERP or a document store. It gives you a Model Context Protocol server in TypeScript, built on Effect, with sign-in, scoped permissions and a record of every call from the first commit.
What's inside
Sign-in with your identity provider
The server is an OAuth protected resource. MCP clients discover your identity provider from it, whether that is Keycloak, Auth0, Entra ID or Okta, and connect on behalf of a signed-in user. Hashed, revocable API keys cover jobs and services.
Scopes per tool
Each tool declares the scope it needs, and one guard checks it on every call, so no tool can skip the check.
Typed tools
Parameters, results and errors are Effect schemas. Clients get a JSON schema, bad input is rejected before it reaches your systems, and the agent receives errors it can act on.
Audit logging
Every tool call is written to Postgres with the caller, client, tool, arguments, outcome and duration. Refused calls are recorded too.
Rate limits and timeouts
Limits per caller and per tool, backed by Redis, and a time limit on every call, protect the systems behind the server from runaway agent loops.
Tests
Tests that drive the server through a real MCP client and cover sign-in, scopes, limits and the audit trail, plus Postgres tests that run in CI.
How it fits together
- 01
Connect
An MCP client, such as Claude, Cursor or an internal agent, connects over streamable HTTP. Without a token it is pointed to your identity provider and completes the OAuth flow there.
- 02
Authorise
The server verifies the token against the provider's published keys, or looks up the API key, and checks the scope the tool requires.
- 03
Execute
The tool calls the internal system through a small client that passes on who the caller is, with rate limits and timeouts applied.
- 04
Record
The call is written to the audit log, and a typed result goes back to the agent.
A look at the code
A read-only tool with a typed result, a scope check and an audit entry.