PTENES
Skip to content
MODULE 3-4

๐Ÿ—„๏ธ Database and API MCPs

Connect the agent to PostgreSQL, Redis, REST and GraphQL APIs. Learn to access real services securely and protect credentials.

6
Topics
~45
Minutes
M3.2
Prerequisite
Practical
Type
Progress:0%0 of 6
1

๐Ÿ˜ PostgreSQL MCP

The PostgreSQL MCP connects the agent to Postgres databases via a connection string. Tools: query (run SQL), list_tables, describe_table. The agent can analyze schemas, generate reports, debug data, and even suggest indexes.

The configuration passes the connection string as an environment variable: POSTGRES_URL=postgresql://user:pass@host:5432/db. Always prefer read-only access for production environments.

settings.json (postgres)
"postgres": {
  "command": "npx",
  "args": ["-y", "@modelcontextprotocol/server-postgres"],
  "env": { "POSTGRES_URL": "postgresql://user:pass@localhost:5432/mydb" }
}

In one sentence: PostgreSQL MCP = the agent runs SQL queries on real Postgres databases.

2

โšก Redis MCP

The Redis MCP exposes cache and key-value operations: get, set, keys, ttl, del. Useful for debugging cache, checking queues, and monitoring application status in real time.

Connection via REDIS_URL: redis://localhost:6379. The agent can inspect keys, check TTLs, and even clear the cache on demand.

In one sentence: Redis MCP = inspect and operate Redis caches/queues through an agent.

3

๐ŸŒ HTTP/REST MCP

The HTTP MCP is a generic connector for any REST API. You configure the base URL and auth headers, and the agent can make GET, POST, PUT, and DELETE requests to any endpoint. It's the Swiss Army knife of MCPs.

Each operation becomes a tool with parameters for path, query params, headers, and body. Ideal for connecting internal services that don't have a dedicated MCP.

In one sentence: HTTP MCP = connect the agent to any REST API with a config.

4

โ—ˆ GraphQL MCP

If your API is GraphQL, this MCP lets you run queries and mutations directly. The agent uses introspection to understand the schema and automatically build appropriate queries.

The configuration needs the GraphQL endpoint and optionally auth headers. The agent can explore the schema, list types, and run complex operations with variables.

In one sentence: GraphQL MCP = GraphQL queries and mutations via the agent, with schema introspection.

5

๐Ÿ”Œ Connecting to Real Services

Connecting MCPs to local services is easy. The challenge is connecting to real-world environments: staging, production. Common patterns: SSH tunnels for remote databases, project-specific env configs (local vs. global settings.json), and connection pools to avoid overload.

Golden rule: never give production write access via MCP without supervision. Use read-only for queries and analysis; use write only in staging or with an approval flow.

Never write directly to prod

The agent can execute DELETE or DROP without a second thought. Production environments should be read-only via MCP. Write only with approval or in staging.

In one sentence: connecting to staging/prod = SSH tunnel + read-only + per-project env.

6

๐Ÿ”’ Credential Security

MCPs with access to DBs and APIs need credentials: connection strings, tokens, passwords. These credentials are stored in settings.json or environment variables. The risk: if settings.json is committed to git, the credentials leak.

Best practices: (1) use env in settings.json instead of hardcoding in the args, (2) add .claude/settings.json to .gitignore, (3) for teams, use a secret manager and reference shell variables.

.gitignore
# Never commit settings with credentials
.claude/settings.json
.env
.env.local

In one sentence: credentials in env vars + gitignore + secret manager = basic security.

๐Ÿงพ Module Summary

โœ“
PostgreSQL, Redis, REST, GraphQL โ€” MCPs for each type of data source.
โœ“
Read-only in prod โ€” never write without supervision.
โœ“
Secure credentials โ€” env vars + gitignore + secret manager.

Next module:

3.5 โ€” Create Your Own MCP Server: from scratch to deployment.