An MCP server that lets doctors question a patient’s follow-up from their AI tools: statistical analysis tools, not a thin layer over an API
The psychiatrist questions a patient’s follow-up in plain language, from their AI assistant: the server does the statistical analysis itself.
A psychiatrist has little time between two consultations, and a patient’s follow-up is several curves over several months. With this server, they ask the question as they would ask a colleague, in an AI assistant such as Claude: how has this patient been since the change of treatment?
I designed and built a server using MCP (Model Context Protocol), the protocol through which an AI assistant calls tools. A standard MCP server can be written in an afternoon: just wrap an existing API, and the model receives raw data to work with as it can. I took, however, a completely different approach, specifically designed for health data. The tools perform the statistics themselves and indicate when the data is not enough. Each caller comes in with their own identity and sees only their own patients. A text written by a patient cannot lead the model astray, and every call is logged. The model computes nothing and decides no right: it picks a tool, then writes from the result.
I designed and built this server at Emobot. The same core serves three kinds of caller, each with its own rights: practitioners, partner organisations, and Emobot’s team.
The result
What was done
01
The common core
One server for three kinds of caller, in the protocol AI assistants speak. It decides no right: each surface tells it what the caller may see.
Python · Flask · Model Context Protocol
02
The analysis tools
Tools to summarize a follow-up, follow a trend, compare two periods, relate two signals and read the effect of a treatment, each with its level of reliability.
Python
03
The sign-in
Everyone signs in from the assistant with their own account, and what it opens is of no use anywhere else.
04
The safeguards
Bounded answers, small groups masked, readings limited in time, and a person’s confirmation before any change.
05
The log
Every call recorded under its author’s name, refusals and failures included, to know at any time who read what.
06
The architecture rules
Rules checked with every change to the code: the partners’ access cannot reach the internal rights, even by mistake.
import-linter
07
The tests
Automated tests on every tool and every refusal, with invented patients.
pytest
How it works
Scroll: the drawing follows.
01 / 06
Ask a question in plain language
The psychiatrist types the question into the assistant, with no new tool to learn. The assistant does not answer by itself: it calls one of the server’s tools, which reads the follow-up data, does the computation and returns a result. The model picks the tool and writes the answer; the figures come out of tested code.
02 / 06
Come in under your own identity
Everyone signs in from the assistant with their own account, with no password handed to the model. A practitioner sees only their patients, by the same rule as the portal, and only those who share their data. For a patient who is not theirs as for a patient who does not exist, the answer is the same: there is no guessing who is being followed. And an access opened for one kind of caller opens nothing for the other two.
03 / 06
Tools written for a model
A model gets things wrong differently from a person: it makes up a parameter, asks for too much, insists. So each tool describes its parameters in a format checked before any computation, and that description comes from the same code as the check: the two cannot drift apart. An error names the faulty field, without ever sending back the data received. Answers are bounded and paged, so a question too wide does not bring back the whole database.
04 / 06
Compute rather than guess
To compare two periods, before and after a change of treatment for instance, the tool compares ranks rather than means: the method copes with short, irregular series and days out of the ordinary. To relate two signals, it compares them day for day, then shifted by a few days, and corrects for the risk of finding a link by chance from looking for so many. When too few days were measured, it answers “insufficient data”, and the assistant draws no conclusion.
05 / 06
Read without risk, write in two steps
For practitioners and partners, everything is read-only. For Emobot’s team, statistics mask the groups too small to hide a person, and a question put to the database is limited to one reading, within a set time and number of rows. The only change possible goes through two steps: a preview of what will change, then a person’s confirmation, good once and for a few minutes. If the data has moved in the meantime, it has to be done again.
06 / 06
Log everything
Every tool call leaves a line under its author’s name: who asked what, when, and what came of it. Refusals and failures are logged too: a computation that fails is rolled back, not its record. And a text written by a patient is always presented to the model as data to read, never as an instruction to follow.
Specifications
- Role
- Co-founder and chief product officer; design and development of the server and its tools
- Built with
- Python · Flask · Model Context Protocol