Skip to main content
Glama
Read-only DynamoDB MCP

Read-only DynamoDB MCP

by gongarher

Read-only DynamoDB MCP: a small HTTP + auth demo

From “let me dig through DynamoDB JSON” to “ask an assistant for a record.” A self-contained Model Context Protocol example with synthetic data by default. No AWS account is needed to try it.

flowchart LR
    A["Person asks<br/>‘Show me a sample record’"] --> B["MCP client<br/>e.g. OpenCode"]
    B -- "JSON-RPC over Streamable HTTP<br/>Bearer access token" --> C["MCP server<br/>validates token + exposes read tools"]
    C --> D{"Data source"}
    D --> E["Synthetic records<br/>default"]
    D --> F["Your DynamoDB test table<br/>opt-in only"]
    E --> C
    F --> C
    C -- "Readable JSON" --> B
    B --> A

The problem it solves

DynamoDB returns typed attributes such as {"S":"value"}, and exploring a table usually means switching between a chat, the AWS console and CLI syntax. This MCP gives an assistant four narrow, read-only tools (describe_table, get_item, query_partition, sample_items) and returns plain JSON. A question becomes a specific tool call rather than arbitrary database access. Samples and limits keep the interaction small; read-only still permits disclosure, so access control matters.

This demo is a sanitized, standalone teaching version of a DynamoDB explorer built while working on mioapp.vip (Android app on Google Play). It includes no application data, production table names, credentials, or internal entity model. The fixture contains only invented records (DOC#sample-01, etc.).

Run locally in five minutes

Requires Node.js 22+ and npm.

npm ci
cp .env.example .env

Generate a fresh secret, then paste it into MCP_DEMO_SECRET= in your private .env file:

openssl rand -hex 32

Terminal 1: start the server (listens only on 127.0.0.1:3001):

npm start

Terminal 2: generate a short-lived JWT locally:

export MCP_TOKEN="$(npm run --silent token)"

No token → 401 Unauthorized:

curl -i http://127.0.0.1:3001/mcp

Valid token → initialize the MCP session:

curl -sS http://127.0.0.1:3001/mcp \
  -H "Authorization: Bearer $MCP_TOKEN" \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json, text/event-stream' \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"demo","version":"1"}}}'

Call a tool to read an invented record:

curl -sS http://127.0.0.1:3001/mcp \
  -H "Authorization: Bearer $MCP_TOKEN" \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json, text/event-stream' \
  -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"get_item","arguments":{"PK":"DOC#sample-01","SK":"META"}}}'

Try calling delete_item instead: the server returns a tool error; there is no write operation in the implementation. The fixture never accesses AWS.

Related MCP server: DB MCP Demo

Connect an MCP client

For example, add a remote MCP server in your OpenCode configuration (on the same computer). Store MCP_TOKEN in the environment before starting OpenCode; never put the token in a committed configuration file.

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "dynamodb-demo": {
      "type": "remote",
      "url": "http://127.0.0.1:3001/mcp",
      "oauth": false,
      "headers": { "Authorization": "Bearer {env:MCP_TOKEN}" }
    }
  }
}

Restart OpenCode after configuring it. Try asking “What example records can you show me?” Logs on the server show the verified subject, tool and outcome without printing tokens, inputs or returned records. Tokens generated by npm run token expire after 60 minutes.

Use your own test DynamoDB table (optional)

The default fixture requires no cloud permissions. For AWS, change .env to DATA_SOURCE=aws, set DYNAMODB_TABLE_NAME explicitly and provide AWS_REGION. Run AWS_PROFILE=your-read-only-profile npm start. This example assumes a table with string keys named PK and SK. It has no arbitrary table-name parameter: a caller cannot switch tables via a tool argument. Limit the server's IAM principal to dynamodb:DescribeTable, dynamodb:GetItem, dynamodb:Query and dynamodb:Scan for that table only. Do not use real customer records in a public demonstration.

The server only imports read commands, and tools cap query results at 20 and samples at 10. Code-level read-only is not an IAM restriction: another process using broad AWS credentials could still write. A narrowly scoped IAM identity is the second boundary. Scan limits cap returned pages, not necessarily total table read capacity or all data exposure.

What the auth demo does (and does not)

  • src/token.ts signs a local demonstration JWT using HS256 and a secret in .env. The server verifies signature, iss (issuer), aud (this server), exp (expiry), presence of sub (subject) and scope=records:read on every HTTP request. Missing or invalid token → 401; missing scope → 403. JWT payloads are readable, not encrypted.

  • The shared-secret script is not an OAuth authorization server or a login flow. For real OAuth, use an external identity provider: the optional MCP_JWKS_URL mode accepts RS256 JWTs from an HTTPS issuer, checks audience and scope, and exposes protected-resource metadata. A client needs its own registration and Authorization Code + PKCE flow. That provider integration is illustrative, not tested against a live tenant.

  • Never forward an MCP access token to AWS. The DynamoDB SDK uses separate AWS credentials. HTTP is deliberately loopback-only; to demo across machines, use SSH port forwarding or a properly configured HTTPS deployment. The server is not an Internet-facing deployment template.

  • An MCP token grants access to all four tools in this example. There is no per-user or per-tool policy. sub is an identity claim from the validated token; the fixture token does not prove a human logged in.

Verify

npm run typecheck
npm test

The tests use synthetic data and no AWS account. This repo should be created as a new repository without importing the original application repo's Git history.

License: MIT.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Exposes a SQLite database to AI assistants with structured, read-safe access. Includes five tools for schema exploration, querying, and sampling data.
      -
    • F
      license
      Not graded
      quality
      B
      maintenance
      Provides read-only database access for AI agents, enabling table listing, schema inspection, and filtered row queries through MCP tools.
      -
    • A
      license
      A
      quality
      C
      maintenance
      Enables Claude Desktop and Claude Code to inspect a Postgres schema and run read-only SQL queries against a demo database through the tools describe_schema and query_readonly. Every proposed query passes the same deterministic guardrails — SELECT-only, allow-listed tables, enforced row limits, statement timeouts and a read-only role — before execution.
      2
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to run read-only SQL against SQLite or MySQL databases through MCP tools for listing tables, describing schemas, and querying data. Wraps every call in guardrails such as statement allow-listing, row caps, query timeouts, PII masking, and audit logging.
      1
      MIT