An MCP Server for StatelyDB

2 days ago 1

StatelyDB is the only database specifically optimized for change which makes it a natural fit for generative AI. We’re excited to announce our new Model Context Protocol (MCP) Server for StatelyDB that helps developers quickly build elastic schema definitions. Get ready to start vibe coding!

Let’s dive in!

Installing the MCP Server for StatelyDB

The first thing you’ll need to grab if you don’t have it already is our command line tool:

curl -sL https://stately.cloud/install | sh

Next you’ll need to download a copy of Claude Desktop. Once you’ve got Claude Desktop installed open up the MCP configuration by visiting Settings, then Developer and Edit Config. Add the following configuration snippet:

{ "mcpServers": { "statelydb": { "command": "npx", "args": ["-y", "@stately-cloud/statelydb-mcp-server"] } } }

Open up Claude Desktop and you’re ready to go!

What Can I Do With It?

Here’s a quick run-down of the available tools and some example prompts:

statelydb-attempt-login

This tool attempts to authenticate the MCP Server with your Stately Cloud account. If you haven’t ever used Stately Cloud you can open up the Console and an account will be created on your first visit.

Sample prompt:

statelydb-verify-login

This tool will verify that you are authenticated. If you are, it’ll return metadata about your account like the Stores, Schemas and Organizations you have access to. If you aren’t, the language model will likely offer to log you in.

Sample prompts:

Am I logged in to StatelyDB?
What StatelyDB Stores do I have access to?
Which StatelyDB Stores are available in the ACME Organization?

statelydb-validate-schema

This tool checks if a given elastic schema definition is valid. This simple tool provides a valuable feedback mechanism that an LLM can use to iterate towards a correct outcome because validation errors about the schema are returned to the LLM.

Sample prompts:

Is this a valid StatelyDB schema? import { itemType, string, uuid } from "@stately-cloud/schema"; itemType("RamenFlavors", { keyPath: "/ramens-:id", fields: { id: { type: uuid, initialValue: "uuid" }, name: { type: string } } });
My editor is showing me errors with my StatelyDB schema, can you fix issues and validate the fixes are correct? itemType("RamenFlavors", { keyPath: "/ramens-:id" fields: [ { id: uuid, initialValue: "uuid" }, { name: string } ], })

Note: The schema above is intentionally malformed in order to generate a corrective response from the LLM.

statelydb-validate-migrations

This tool ensures that any migrations defined in a proposed schema change are correct before publishing. This tool requires knowing about the ID of the published schema you want to make changes to.

Are the migrations for this StatelyDB schema valid? My target schema id is 12345 import { itemType, string, uuid, migrate } from "@stately-cloud/schema"; itemType("RamenFlavors", { keyPath: "/ramens-:id", fields: { id: { type: uuid, initialValue: "uuid" }, name: { type: string }, nickname: { type: string } } }); migrate(1, "Add nickname field", (m) => { m.changeType("RamenFlavors", (t) => { t.AddField("nickname") }) });

statelydb-schema-put

This tool publishes a schema definition to a given schema ID! Be careful about allowing Claude Desktop to “Always” have access to run this tool.

I want to publish the schema we've been developing to schema ID 12345.

statelydb-schema-generate

This tool generates files for use with the StatelyDB SDK using a given published schema ID and schema version (or the latest published if omitted).

I'm building a NextJS app. Generate typescript code for schema ID 12345 and add the StatelyDB SDK to my project.

Bringing It Together

Here’s an example of how you can use the MCP Server for StatelyDB to conversationally create a schema, validate it for errors, publish it and generate source code. This is just a high-level example which doesn’t include the LLM responses, so you’ll want to try this out for yourself.

I want to create an application for tracking my coffee intake. We'll use StatelyDB as our database, with a Store ID of 12345 and a Schema ID of 6789. Here's our plan: 1. Define a StatelyDB schema for tracking coffee intake. Learn about the StatelyDB schema format before attempting to create a schema definition. 2. Validate that the schema is valid. If it isn't, correct errors until it is. 3. Verify with me that we should publish the schema. If I agree, publish it. 4. Ask me which language I'd like to write my app in and then offer to generate code for use with the StatelySDK based on my schema. Documentation for StatelyDB is available at https://docs.stately.cloud
Read Entire Article