databasedmcp

← Articles

How to build a habit tracker with ChatGPT

Tell ChatGPT what you did today and it ticks the box. Ask how the week went and it counts.

6 min read

databasedmcp gives your AI assistant databases it keeps between conversations, so everything in this article works from the day you connect it. Free to start, no card.

Get started free

Why build it yourself

A habit tracker is a list of habits and a mark for each day you did one. Apps like Habitica or Streaks wrap that in reminders, widgets and games, and some people need exactly that. Others want to say "ran this morning" and see the week add up.

That's two tables. If you talk to ChatGPT during the day, the check-in is one sentence in a chat you have open anyway. The counting, the streaks and "how did October go" are queries, and ChatGPT writes them for you.

Connect ChatGPT to databasedmcp

databasedmcp is a remote MCP server that gives AI assistants private SQLite databases, with nothing to install.

ChatGPT connects to remote MCP servers as custom connectors in developer mode. That's on paid plans, on the web. Turn on developer mode in ChatGPT's settings, then create a connector: give it a name, enter https://databasedmcp.com/mcp as the URL and choose OAuth. When ChatGPT opens a databasedmcp page, sign in and select Allow. In a new chat, turn the connector on from the tools menu.

ChatGPT moves these menus between releases. If yours look different, search its settings for developer mode and custom connectors.

Any other MCP client works the same way; the docs have the details.

Copy this prompt to build it

Paste this into ChatGPT to set up the database, its tables and its guide in one go. The rest of this article walks through what it makes and how you use it.

prompt
Set up a habit tracker for me in databasedmcp, in one go.

1. Create a database called habits, described as "Habit tracker: habits with weekly targets and one check-in per habit per day, logged by ChatGPT from what I tell it".
2. Create two tables:
   - habits: id, name (required), target_per_week (how many days a week I'm aiming for, 1 to 7, defaults to 7), started_on (date, defaults to today), archived_at (NULL until I drop the habit).
   - checkins: id, habit_id (references habits), done_on (date as YYYY-MM-DD, defaults to today), note. One check-in per habit per day: make habit_id and done_on unique together.
3. Write the database a guide that says what each table is for, to archive habits instead of deleting them so old check-ins keep their habit, to match habits by name when I mention them, to use INSERT OR IGNORE so logging the same day twice does nothing, and the queries for "how's my week going against my targets" (weeks start Monday) and "my longest streak for a habit" (group consecutive dates by the date minus the row number).

From then on: when I tell you I did something, check it in for today unless I say another day, with anything I said about it as the note. When I drop a habit, set archived_at. Show me the tables when you're finished.

Ask for the database

You don't write the schema. Describe what you want:

Set up a habit tracker in databasedmcp. I want habits with a target number of days per week, and a check-in for each day I do one. When I tell you I did something, log it for today unless I say another day.

ChatGPT creates a database called habits and its tables:

schema
CREATE TABLE habits (
  id INTEGER PRIMARY KEY,
  name TEXT NOT NULL,
  target_per_week INTEGER NOT NULL DEFAULT 7 CHECK (target_per_week BETWEEN 1 AND 7),
  started_on TEXT NOT NULL DEFAULT (date('now')),
  archived_at TEXT
);

CREATE TABLE checkins (
  id INTEGER PRIMARY KEY,
  habit_id INTEGER NOT NULL REFERENCES habits(id),
  done_on TEXT NOT NULL DEFAULT (date('now')),
  note TEXT,
  UNIQUE (habit_id, done_on)
);

It also writes the database a guide on how the tables are meant to be used. The guide comes back with the schema whenever an assistant looks the database up. ChatGPT files things the same way next week as today, and so does any other assistant you connect.

guide
# habits: daily check-ins against weekly targets

- **habits**: one row per habit. `target_per_week` is how many days a week I'm aiming for. Set `archived_at` instead of deleting, so old check-ins keep their habit.
- **checkins**: one row per habit per day I did it. `done_on` is a date (YYYY-MM-DD), today unless I say otherwise. Use INSERT OR IGNORE: logging the same day twice is a no-op.

Match habits by name (LIKE) when I mention them.

This week against target (weeks start Monday): `SELECT h.name, h.target_per_week, count(c.id) AS done FROM habits h LEFT JOIN checkins c ON c.habit_id = h.id AND c.done_on >= date('now', 'weekday 0', '-6 days') WHERE h.archived_at IS NULL GROUP BY h.id ORDER BY h.id`

Longest streak for a habit: group consecutive `done_on` dates by `julianday(done_on) - row_number()`.

Use it

From here on you talk, and ChatGPT writes the rows. Each request below is one statement:

I want to run three times a week, read every day and meditate five days a week.
execute
INSERT INTO habits (name, target_per_week) VALUES (?, ?), (?, ?), (?, ?)
-- params: ["Run",3,"Read",7,"Meditate",5]
Did a 5k this morning, felt slow.
execute
INSERT OR IGNORE INTO checkins (habit_id, note) SELECT id, ? FROM habits WHERE name LIKE ? AND archived_at IS NULL
-- params: ["5k, felt slow","%run%"]
I forgot to tell you yesterday: I read and meditated.
execute
INSERT OR IGNORE INTO checkins (habit_id, done_on) SELECT id, date('now', '-1 day') FROM habits WHERE id IN (?, ?)
-- params: [2,3]

The UNIQUE constraint and INSERT OR IGNORE mean you can't count a day twice, however many times you mention it.

Drop meditation for now, it's not sticking.
execute
UPDATE habits SET archived_at = datetime('now') WHERE id = ?
-- params: [3]

Ask it questions

Once there's data, each report you'd pay for is a single query:

How's my week going?
query
SELECT h.name, h.target_per_week, count(c.id) AS done FROM habits h LEFT JOIN checkins c ON c.habit_id = h.id AND c.done_on >= date('now', 'weekday 0', '-6 days') WHERE h.archived_at IS NULL GROUP BY h.id ORDER BY h.id
What's my longest reading streak?
query
WITH d AS (SELECT done_on, julianday(done_on) - row_number() OVER (ORDER BY done_on) AS grp FROM checkins WHERE habit_id = ?) SELECT min(done_on) AS from_day, max(done_on) AS to_day, count(*) AS days FROM d GROUP BY grp ORDER BY days DESC LIMIT 1
-- params: [2]

Consecutive days share the same date minus row number, so each streak is one group.

How many days did I do each habit, month by month?
query
SELECT strftime('%Y-%m', c.done_on) AS month, h.name, count(*) AS days FROM checkins c JOIN habits h ON h.id = c.habit_id GROUP BY month, h.id ORDER BY month DESC, h.id

You can also open the database on the website, page through its rows and run read-only SQL yourself.

What you give up

Nothing nudges you. Habit apps remind you at the time you choose, and some sit on your home screen. Here, a habit gets logged because you opened a chat and said so. If the reminder is what keeps you going, stay with the app that sends it.

There's no game and no ticking a box with one tap. Habitica's whole point is that the habit feeds a game with other people. A database gives you the record and the questions, not the play. In return you get a log you can ask anything of, in words, and read yourself on the website.

Try it

databasedmcp is free to start, with no card. Free has 100 tool calls a week, enough to set this up and try it for a week. Starter has 1,000 for everyday use.

Create an account

More articles · databasedmcp · Docs