Homespun

How to connect Claude to a database

There are three different questions hiding in this one, with three different answers. If you want Claude to query a database you already have, connect it over MCP: Claude talks to a database MCP server and can read, and if you allow it, write. If you want an artifact Claude built to store data, artifacts do have persistent storage, but it is 20 MB, text only, and works only once published. If you want an app with a database behind it that other people log into, an artifact cannot do that at all and you need somewhere to host it.

Last checked against Anthropic's documentation on . Claude changes often. If something here no longer matches the help centre, the help centre is right.

Which of the three questions are you asking

Getting this wrong is why the search results for this are so unsatisfying: the three intents get answered interchangeably. Find your row first.

What you wantThe answerWhere it runs
Claude should query my existing databaseAn MCP server for that databaseOn your machine or your network, alongside Claude
The artifact Claude built should remember thingsArtifact persistent storageInside the published artifact, 20 MB, text only
I need an app with a database that people log intoA hosted app platformOn a host, at its own URL, with accounts

Option 1: let Claude query your own database over MCP

The Model Context Protocol is the standard way to give a model access to a system it does not otherwise know about, and databases were one of the first things people wired up with it. In practice you run a small MCP server that holds the connection, and Claude calls it.

What this gives you is a very good analyst and a very fast way to answer a question about data you already have. What it does not give you is anything the people you work with can use: the connection lives on your machine, in your client, under your credentials. Nobody else can open it.

The security part almost every guide skips

Connecting a model to a database means an agent will compose statements against it. That is fine, and it needs the same care you would apply to any other automated account.

Option 2: storage inside the artifact Claude built

If what you meant was that the little app in the chat should remember things, artifacts do have persistent storage. The limits are documented and they matter more than they sound:

Persistent storage for artifacts is available on Pro, Max, Team, and Enterprise plans on Claude web and desktop.

Persistent storage for artifacts, Claude Help Center

Persistent storage is only available for published artifacts. During development and testing, storage operations will not succeed until the artifact is published.

Persistent storage for artifacts, Claude Help Center

The CSP blocks scripts, stylesheets, fonts, and images loaded from any other host, along with fetch, XHR, and WebSocket calls.

Share session output as artifacts, Claude Code documentation

So an artifact cannot connect to your database, and this is by design rather than an oversight: with no outbound requests possible from the page, there is nothing for a connection string to do. Full detail on the storage side is in can Claude Artifacts store data.

Option 3: an app with a database that other people use

This is the intent behind most of the questions, once you scratch at them. Somebody wants a small internal tool: an intake form, a stock list, a booking sheet, a request tracker. They want Claude to build it, they want it to keep its data, and they want their colleagues to open it.

Homespun is where the same agent that built the thing can host it. People sign in with their email, so the app can tell who is who and every row remembers who created it; permissions are set per collection, so some people can approve and others can only submit; and the agent keeps read and write access to the collections it is allowed, so it can keep working on the data instead of handing you a page and walking away. It is free today, and there is no paid plan to buy.

MCP database serverArtifact storageHosted app
Uses a database you already haveYesNoNo, it gets its own
Other people can use itNo, it is your client onlyYes, anonymouslyYes, signed in
Knows who each person isNot applicableNoYes, once they sign in
Query languageYes, your own SQLNo, key and value onlyFiltered queries over collections, no SQL
Files and imagesWhatever your database holdsNo, text onlyYes, images, PDFs, audio and video
Survives you closing your laptopNoYesYes
Agent can keep working on the dataYes, while you are thereNoYes, on its own
Best forAnswering questions about existing dataA small self-contained toolA tool a group uses every week

These are not competitors. A perfectly reasonable setup is all three: an MCP server so Claude can read your warehouse, an artifact for the one-off chart you wanted from it, and a hosted app for the thing your team fills in every Monday.

Questions people ask next

Can Claude connect directly to a SQL database?

Not by itself. Claude connects through an MCP server that holds the database connection and exposes tools Claude can call. The credential lives in that server's configuration, and Claude sees only the tools, never the connection string.

Can a Claude Artifact connect to my database?

No. A published artifact is a static page under a strict content policy that blocks fetch, XHR and WebSocket calls, so it cannot reach any external service at all. Its only storage option is the built-in artifact storage, capped at 20 MB of text.

Is it safe to give Claude access to a production database?

Only with care. Create a dedicated role rather than reusing your own, grant read-only access to start, scope it to the schema it needs, and prefer a replica or a restored dump over production. Keep the credential in the MCP server's configuration, never in a chat message.

What database does Claude use for artifacts?

Artifacts do not use a database in the usual sense. They have a key-value persistent storage feature with a 20 MB per-artifact limit that accepts text only, available on paid plans, and only once the artifact is published.

How do I build an app with a database that my team can log into?

You need somewhere to host it, because an artifact cannot authenticate anyone. An agent-hosted app platform lets the agent deploy the app, provision the data behind it, and give each colleague their own sign-in, then keep reading and writing that data afterwards.

Can Claude write to a database, not just read from it?

Yes, if the MCP server it is connected to exposes write tools and the database role has permission. Start read-only and widen deliberately, because a model composing statements against live data can be wrong in ways that are expensive to undo.

Primary sources

Every claim about Claude on this page comes from Anthropic's own documentation, quoted rather than summarised so you can check it yourself.