musi.live
Nov 09, 2026

Building an MCP connector for Brainbank

If you’ve just learnt something in a chat with an AI, it knows exactly what you asked, where you got stuck and which examples made it click. That’s what good flashcards are made of. What the LLM lacks is a way to hand them over without you copying and pasting.

Brainbank is a spaced repetition app I’ve been building. A lot of what I learn now happens in long back-and-forths with Claude, and most of it is gone a week later because nothing schedules it for review. So I built an MCP connector: you ask Claude to save what you covered, it drafts the cards, you approve them in the chat, and the deck appears in the app on your phone. This is a log of how it’s built and what I picked up along the way.

The shape of it

The first decision was who writes the cards. Brainbank can already turn notes into cards with AI, so the obvious move was to send the conversation to Brainbank and generate there. I went the other way. The model in the chat has the full context - what you asked, what confused you, which examples landed - and anything I sent to a second model would be a lossy copy of that. It also means you can shape the cards in the same chat - fewer, simpler, more examples - before anything is saved. The connector only has to check, store and schedule them.

The connector is a small server at mcp.brainbank.space. It does three things: the standard sign-in steps AI apps expect, a Brainbank page where the user signs in, and five MCP tools: list_decks, get_deck, create_deck, add_cards and confirm_save. It writes to the same place the app reads from, so a new deck shows up on your phone within seconds.

The server keeps no session between requests. Every request carries a token that identifies the user, so each one can be handled on its own, by whichever instance picks it up. That keeps it simple to run and scale. The cost is that the server cannot push its own questions back to the AI mid-call, which ruled out MCP’s built-in pop-up forms for the approval step later on.

Linking an account

MCP clients like Claude and ChatGPT expect the server to handle sign-in the standard way, with OAuth 2.1, PKCE and dynamic client registration. The MCP SDK handles most of this. I added where clients and tokens are kept, and the Brainbank sign-in page.

When the user adds the connector, Claude registers itself, then opens a Brainbank page where the user signs in with the same Google, Apple or email account they use in the app and taps Allow. That sign-in is the account link. There is no API key to generate and nothing to paste, which matters for an app most people use on their phone rather than at a terminal. The sign-in also has to be recent, so an old session cannot be reused to link an account.

A few decisions here were about limiting what a leak could do. Tokens are never stored as they are, only as hashes, so a copy of the database holds nothing usable. Access tokens are short-lived, and refresh tokens rotate, so each one works exactly once. Every call also checks that the connection still exists, so a disconnect in the app removes the connection, and every token issued under it stops working on the next call. The connection is only created once the AI app actually holds tokens, so the app never lists one that was started and abandoned.

Asking before saving

The first version saved cards the moment Claude called create_deck. Trying it myself, I didn’t like that nothing was shown before it was saved. An AI writing straight into your study queue is a different level of trust from an AI writing in a chat window you can scroll back through, and I wanted to see the cards before they landed.

Saving is now two steps. create_deck and add_cards only preview: the cards are checked and stored as a draft that expires after a while, and the AI gets back a summary and a draft ID. Cloze cards are expanded at this stage - a sentence with two blanks becomes two cards - so what the user approves is exactly what gets saved. Only confirm_save writes, and it needs that draft ID. A draft can be saved once, only by its owner, and only before it expires. If the user wants changes, the AI previews again and a new draft replaces the old one.

I marked the preview tools as read-only. They do not change the user’s data, and marking them that way means Claude’s own permission prompt only appears for confirm_save.

In my first test, Claude took the summary and turned it into a short list of topics, which makes approving it meaningless. The fix was explicit wording in what the tool returns: nothing has been saved yet, show every card, do not summarise them into topics, and only call confirm_save after a clear yes from the user.

Cards that look native

The last piece was making cards from the connector indistinguishable from cards made in the app. They are saved exactly the way the app saves its own: in the right deck, in order, and scheduled as brand-new cards, so they enter the review queue like any other. Each card also records which AI app sent it, which will be useful later for seeing how much of the app’s content arrives this way.

The connector is a Premium feature, and the check runs on every tool call rather than once at connect. That way a free user can still connect and gets a clear “this is a Premium feature” reply from the AI, and a lapsed subscription stops working at once rather than at the next sign-in.

Index ↗