A Secure Remote MCP Server for AI Agent Database Access
Oct 21, 2026 · 4 min read
Per-laptop database logins for an AI agent don’t scale. How I replaced them with one hosted MCP server in production, with permissions outside the model.

When a team lets an AI agent query production data, per-laptop installations and database logins can make onboarding hard to maintain. On a recent engagement, I replaced that arrangement with a hosted MCP server. Staff sign in centrally, and authorization is enforced outside the model.
- Problem
- Per-laptop setup made agent access difficult to maintain.
- What I changed
- A hosted MCP server with centralized sign-in, explicit authorization, read-only access, bounded results and attributable requests.
- Result
- In production for internal staff, replacing per-person database logins.
Where it started
I first built a local MCP setup with read-only database access. Moving it to a hosted service reduced the installation and credential-management work for each additional person.
What was failing: MCP server permissions on every laptop
The fragile part was where the security boundary sat. The login, the secret and the network path all lived on each laptop, so giving someone access meant provisioning a database account, and every new Claude surface meant another install that could drift.
Agent data access needs an explicit entitlement. A general administrative role can include responsibilities that do not require database access.
Before, the login, the secret and the network path all lived on each laptop. After, sign-in, the entitlement check and the database account sit outside the model.
Before: per-laptop setup
Each additional person needs a local setup.
After: hosted access
Access is managed centrally; requests remain attributable.
Check each supported client against the hosted connector and its authorization boundary.
One hosted MCP server in production
The core is a stateless MCP handler on AWS Lambda with schema-checked arguments and an audit record per request. The service provides bounded, read-only database access.
Every permission sits outside the model:
| Layer | What enforces it |
|---|---|
| Identity | Central sign-in and validated credentials |
| Entitlement | An explicit authorization check for data access |
| Database | Read-only permissions and restrictions on sensitive data |
| Bounds | Query deadlines and limits on result size |
| Audit | Attributable request records with sensitive content excluded |
A query deadline and a result limit address different risks. Stop consuming a result when its bound is reached, and return an explicit truncation indicator. Choose bounds for the workload rather than copying another system’s settings.
Provide tool guidance where the caller can retrieve it, and test that behavior in each supported client.
Test authorization through the actual caller identity. Exercise oversized results and cancellation as well as successful small queries.
The client's backend lead reviewed the design and the pull requests, and owns the shared database library the server calls. I wrote the server, the sign-in service, the authorizer, the Terraform and the rollout.
Results
| Before | After | |
|---|---|---|
| Onboarding | Local installation and database credentials | Central sign-in and explicit authorization |
| Database access | Per-person logins | Centrally managed read-only access |
| Client setup | Machine-specific dependencies | A hosted connector |
The server is in production for internal staff. The team can manage agent access centrally instead of maintaining a database login on every laptop.
I retired the replaced local setup and its per-person database credentials.
Keep expensive analysis out of interactive tool requests when it cannot fit the service’s workload budget. Improving data layout or using an asynchronous workflow may be more appropriate than increasing a deadline.
Customer-facing access needs a separate trust model: curated tools, server-enforced tenant scope and workload controls appropriate to each caller.
What I'd tell another team
A prompt can ask the model to behave. Only the database and the gateway can make it.
- Enforce access in the database and the gateway. Grants, column denies, a token authorizer and hard caps hold no matter what the model decides to try.
- Give agent access its own entitlement. Existing admin roles collect people for unrelated reasons.
- Test grants as the real login. An impersonation check and the real login can disagree.
- Don't rely on MCP server instructions. Put guidance in tool descriptions, tool results and a notes tool.
When this approach is wrong: a shared read-only account fits a trusted internal team only when every caller should have the same database rights. Where permissions differ, preserve per-caller authorization. For customer-facing access, use curated tools with tenant scope fixed on the server.