Recommended Free Tools
Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
To connect an MCP server to a database, configure the server to use the database’s own driver or client library, then expose carefully scoped database operations to MCP clients as tools or read-only information as resources. There are two separate connections: the AI host or client connects to the MCP server using an MCP transport, and the MCP server connects to the database using that database’s driver. MCP standardizes the first connection; it does not supply a universal database driver, connection string, or database authentication method.
Understand the two connections
An MCP server sits between an AI application and systems or data that the application may use. The host communicates with the server using MCP. Separately, code inside the server communicates with a database using that database’s client library or driver. For example, an MCP server written in TypeScript could use a PostgreSQL driver, but MCP itself does not require PostgreSQL or TypeScript.
The server exposes a deliberate interface to the host. Tools are appropriate for actions the model may request, such as retrieving a report or, when explicitly authorized, making a change. Resources are suitable for read-only information such as database schema details. Prompts are reusable interaction templates; they are not a substitute for database access controls. See the MCP TypeScript SDK v2 overview and the MCP TypeScript SDK v1 overview for the distinction between these primitives.
Choose the database, server stack, and deployment shape
First identify the database engine, the language in which the MCP server will run, the MCP host or client, and where the server will run. These determine which driver to install and how to configure credentials, network access, pooling, and encryption. There is no connection string or host registration command that applies to every combination.
#1 Best Overall
For a local server, the MCP host commonly launches the server as a process. For a separately hosted server, the client connects to a remote endpoint. In either case, the database connection is configured by the server application, not by the MCP transport.
Choose an MCP transport
| Deployment situation | Transport | What it means |
|---|---|---|
| The host starts a local server process | stdio | The client launches the process and exchanges JSON-RPC over standard input and output. Standard output must remain reserved for protocol traffic. |
| The client connects to a separately hosted server | Streamable HTTP | The client connects to the server endpoint and performs the MCP initialization handshake. |
| A server supports only the older HTTP+SSE approach | SSE compatibility fallback | Use a fresh client configured for SSE when compatibility with that older server is needed. |
These are choices for the MCP client-to-server link; none replaces the database driver. The current TypeScript SDK connection guide describes connecting clients, inspecting negotiated capabilities, and closing connections. Check the server’s advertised capabilities before asking it to perform operations. For Streamable HTTP, terminate the session when applicable before closing the client.
Build a server that exposes a narrow database operation
The following TypeScript example shows the shape of a PostgreSQL-backed server using the TypeScript SDK v2 conventions documented in the v2 overview and first-server guide. It exposes one fixed, read-only operation rather than accepting arbitrary SQL from the model. The MCP SDK and database driver are separate dependencies: the SDK handles MCP, while pg handles PostgreSQL. Adapt and verify imports and startup details against the versions you install; the SDK guide’s getting-started sample uses a weather API, not a database, and is not an end-to-end database test.
Free tools Windows power users keep installed
One-click scans. No signup required.
Rank #2
Install the v2 server package, Zod, and the PostgreSQL driver in your TypeScript project. Keep DATABASE_URL in the server process environment, not in a prompt or tool argument. The example assumes a PostgreSQL table named orders with a numeric total column.
import { McpServer } from "@modelcontextprotocol/server";
import { z } from "zod";
import pg from "pg";
const { Pool } = pg;
const connectionString = process.env.DATABASE_URL;
if (!connectionString) throw new Error("DATABASE_URL is required");
const pool = new Pool({ connectionString });
const server = new McpServer({
name: "orders-database",
version: "1.0.0",
});
server.registerTool(
"get_order_total",
{
description: "Return the total for one order by its ID.",
inputSchema: { orderId: z.string().min(1).max(64) },
},
async ({ orderId }) => {
try {
const result = await pool.query(
"SELECT total FROM orders WHERE id = $1 LIMIT 1",
[orderId],
);
if (result.rows.length === 0) {
return { content: [{ type: "text", text: "Order not found." }] };
}
return {
content: [{ type: "text", text: String(result.rows[0].total) }],
};
} catch (error) {
console.error("Database tool failed", error);
return {
isError: true,
content: [{ type: "text", text: "Could not retrieve the order." }],
};
}
},
);
// Connect the server to the transport used by your host.
// For a local process, use the v2 SDK's stdio serving pattern.
// On shutdown, close the database pool as well as the MCP connection.
The database handler uses a parameterized query: the model supplies an order ID, not SQL text. The inputSchema validates the argument before the handler runs, as described by the official first-server guide. A schema check is useful but does not replace authorization, query design, or database permissions.
The snippet focuses on the database boundary and tool registration; the transport setup is intentionally left as a deployment choice rather than mixing local stdio and remote HTTP into one misleading runnable configuration. The v2 guide describes the server construction sequence as registering server functionality, creating a transport, and connecting the transport. For a local stdio deployment, apply the guide’s stdio pattern and configure the host to launch the built server process. For remote deployment, provide an HTTP server adapter and endpoint appropriate to your hosting environment. Test against the SDK version you pin before exposing the endpoint.
Keep database access constrained
Use a dedicated database identity for the MCP server, separate from an administrator or application-owner account. Grant only the privileges the exposed tools need. For a read-only PostgreSQL integration, grant SELECT on the specific required tables or schema; PostgreSQL also supports table- and column-level grants. If a tool must write, give it only the specific write privileges its task requires. These examples are PostgreSQL-specific; other database engines have their own permission models. See PostgreSQL 15 GRANT documentation.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →- Keep credentials in the server’s deployment environment or an appropriate secret-management system. Do not pass them as tool arguments or include them in logs.
- Expose task-shaped tools such as “get order status” or “list recent invoices” instead of making unrestricted SQL the only interface.
- Set practical result limits and validate inputs before querying. Decide how the tool handles missing records, slow queries, and database errors.
- Use non-sensitive test data when inspecting tools and responses, then confirm that the production role cannot perform operations outside its intended scope.
Configure and test the host connection
- Build the server and confirm that it can reach the database independently, using the same deployment environment and database identity it will use in production.
- Configure the MCP host to launch the server command for stdio, or to connect to the remote endpoint for Streamable HTTP. Host-specific registration fields vary, so use the documentation for the chosen host rather than copying a generic config block.
- Use the MCP Inspector to launch a stdio server, inspect its tool list, and call the read-only tool with a known test record. The official first-server guide warns that “stdout is the protocol channel.” Send diagnostic logs to stderr so they do not corrupt protocol messages.
- Verify that the tool returns the expected result, handles a missing record, and reports a controlled failure when the database is unavailable. Check that the host sees only the intended tools and that the database identity has only the intended access.
When a client’s connect() succeeds, it has negotiated protocol information and can inspect the server version, capabilities, and instructions. Avoid assuming that a connected server supports every possible method: inspect what it advertises and request only supported operations.
Common connection problems and fixes
| Symptom | Likely cause | What to check |
|---|---|---|
| The host cannot start or initialize the MCP server | Wrong launch command, runtime, environment, or transport configuration | Run the configured command in the same environment, inspect stderr, and confirm the host is configured for the transport the server actually provides. |
| stdio connection fails or protocol messages are malformed | Logs or other output were written to stdout | Move diagnostic output to stderr; reserve stdout for MCP protocol traffic. |
| The MCP tool appears, but calls fail against the database | Missing or invalid credentials, inaccessible host, unavailable database, or insufficient database privileges | Check the server process environment and network route, then test the database connection using the same server identity. Confirm the minimum required grants. |
| The client connects to a remote server but sees no usable tools | Initialization or capability negotiation did not complete as expected, or the server does not register the intended tools | Inspect the client’s negotiated capabilities and tool listing, then check server registration and logs. |
| Arguments are rejected before the handler runs | The request does not match the declared input schema | Compare the host’s argument names and types with the tool schema; reject or correct invalid input rather than weakening validation without a reason. |
| Queries are slow or return too much data | The operation lacks suitable limits or its database query is too broad for the use case | Narrow the tool’s purpose, bound results, and review the query and database behavior for the selected engine. |
SDK versions and database-specific choices
Keep SDK generations consistent. The TypeScript v2 documentation uses split packages such as @modelcontextprotocol/server and @modelcontextprotocol/client; v1 documentation uses the monolithic @modelcontextprotocol/sdk package and older import paths. Do not combine v1 imports with v2 method names. The v2 overview identifies its stable TypeScript SDK line as implementing the 2026-07-28 MCP specification. Because package APIs and database behavior can change, pin the versions used by your project and check the relevant documentation when upgrading.
Rank #4
The database example above is PostgreSQL-specific. Driver selection, connection parameters, pooling, TLS, authentication, and host configuration depend on the chosen engine, language, network boundary, and deployment environment. The title alone does not establish those details. If your database is not PostgreSQL, retain the design principles—separate MCP and database connections, validate tool inputs, and limit database privileges—but use that engine’s official driver and access-control documentation.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
ScreenshotNeo is a separate tool for website screenshots, not a database connector. If your broader workflow also needs a clean screenshot of a web page, its API takes a URL and returns an image or PDF. See ScreenshotNeo and the API documentation. For example, this cURL request captures a page:
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
- Cookie or consent banners, newsletter popups, and chat widgets are removed before capture; each cleanup step can be turned off.
- Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; responses include page-verdict and billing headers.
- An MCP server offers the tools
take_screenshot,get_page_info, andcapture_pdffor AI agents and MCP clients. - The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.
Sign up for ScreenshotNeo’s free plan: 1,000 screenshots a month, no card required.
Best Value
- Used Book in Good Condition
Frequently Asked Questions
Does MCP connect directly to a database?
No. The MCP server uses the database’s driver or client library; MCP defines the separate host-to-server interface.
Can I use an MCP server with a database other than PostgreSQL?
Yes. Use a driver and permission model for the database engine you chose; the PostgreSQL example is not universal.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

