DRYCODEWORKS
← Case studies

A Secure Remote MCP Server for AI Agent Database Access

Daniel Young
Daniel YoungFounder, DRYCodeWorks

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.

Laptops, each with its own key, tangle into one cable that leads to a single locked door in front of a database.

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.

Case study: IoT sensor platformStatus: In production · internal
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.
Stack: Python on AWS Lambda, API Gateway, OAuth, SQL Server, ClickHouse, Terraform

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.

Where the security boundary sits

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

Agent clientmachine-specific configuration
On each laptop
Local MCP serviceinstalled and maintained locally
Local credentialsmanaged for each caller
Database accessprovisioned per person
Network configurationmaintained per machine
SQL Server and ClickHouse

Each additional person needs a local setup.

After: hosted access

Agent clientconnects to a hosted service
Outside the model
Central sign-invalidated caller identity
Authorizationexplicit data-access entitlement
MCP servicevalidated read-only requests
Database permissionsrestricted data and bounded results
SQL Server and ClickHouse

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:

LayerWhat enforces it
IdentityCentral sign-in and validated credentials
EntitlementAn explicit authorization check for data access
DatabaseRead-only permissions and restrictions on sensitive data
BoundsQuery deadlines and limits on result size
AuditAttributable 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

BeforeAfter
OnboardingLocal installation and database credentialsCentral sign-in and explicit authorization
Database accessPer-person loginsCentrally managed read-only access
Client setupMachine-specific dependenciesA 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.

I do this kind of work for clients.

AI that could leak company data, give wrong answers or run up the bill: I build AI assistants, MCP servers and models that are safe to ship.

AI systems →Book a call