Originally published in Portuguese on 4 December 2026: Portuguese version.
I put a C# MCP server in front of a synthetic FHIR Bundle and exposed the same data in two ways. In the first, the tool is a FHIR proxy: it returns the whole Patient, or a Bundle with the full Observation resources. In the second, the tool answers the question and returns only the field that matters. I asked both the same 10 questions.
Both got 10 of 10 right. The difference was in what came along. The raw results added up to 3,870 tokens; the lean ones, 257. The CPF and the CNS (Brazil’s taxpayer ID and national health card number, both synthetic here) went along in 2 of 10 raw answers, and the patient’s name in 10 of 10. In the lean answers, 0.
Code and real output: demos/21-mcp-fhir-tool-enxuta, in the nursia-research-lab repository. It runs on CPU, with no account, no API key and no model.
Why did I measure this?
When someone wires an agent to a FHIR server, the shortest path is to expose the API as it is. One tool for GET Patient/{id}, another for GET Observation?subject=..., and the model deals with the JSON. It works. The question is what ends up in the model’s context on that path.
FHIR is the REST of healthcare, and FHIR resources are generous. A Patient carries identifiers, name, phone, address and an HTML narrative. Each Observation carries the reference to the patient, and in my Bundle the name goes along in subject.display, an optional field in the spec. To learn the latest HbA1c, the model receives all of that.
I expected the cost to be only tokens. What caught me was the name repeated in every measurement.
How did I run it?
- Linux, CPU, .NET 8.0.134 and the
ModelContextProtocol.AspNetCore2.4.0 package, the official MCP SDK for C#, Apache-2.0 license. Server over HTTP on 127.0.0.1. - A FHIR R4 Bundle generated by a Python script with a fixed seed: 20 patients, 269
Observationresources (fasting glucose, HbA1c, systolic blood pressure and weight, with LOINC and UCUM) and 38Conditionresources (SNOMED CT). Names with the surname “Sintetico”, CPF and CNS valid by algorithm and marked as synthetic in the resource itself, phone numbers with area code 00. - Three raw tools:
fhir_ler_patient,fhir_buscar_observation(with a LOINC code filter) andfhir_buscar_condition. - Three lean tools:
paciente_resumo(age and sex),ultimas_medidas(date, value and unit of the n most recent) andcondicoes(SNOMED code, name and onset). - A Python script speaks raw JSON-RPC to the server, with no client SDK. For each question it calls the raw tool and the lean tool, reads the result with code and compares it with an answer key taken straight from the Bundle, without going through the server. Tokens counted with tiktoken (
o200k_baseandcl100k_base).
The lean measurements tool, trimmed, is this:
[McpServerTool(Name = "ultimas_medidas")]
[Description("As n medidas mais recentes de um código LOINC: data, valor e unidade, da mais nova pra mais velha.")]
public static string UltimasMedidas(string paciente, string loinc, int n = 1)
{
var medidas = Dados.DoPaciente("Observation", paciente)
.Where(o => Dados.TemCodigo(o, loinc))
.OrderByDescending(o => (string?)o["effectiveDateTime"])
.Take(Math.Clamp(n, 1, 10))
.Select(o => new
{
data = (string?)o["effectiveDateTime"],
valor = (double?)o["valueQuantity"]?["value"],
unidade = (string?)o["valueQuantity"]?["unit"],
});
return JsonSerializer.Serialize(medidas, Dados.Json);
}
The raw one does what a proxy would do: it builds a searchset Bundle with the full resources that match the patient and the code.
What came out?
Numbers from results/saida.txt, tokens in o200k_base:
| # | Question | Raw tokens | Lean tokens | CPF raw / lean |
|---|---|---|---|---|
| 1 | How old is pac-01? | 263 | 17 | 1 / 0 |
| 2 | What is pac-02’s sex? | 265 | 17 | 1 / 0 |
| 3 | Latest HbA1c for pac-03 | 898 | 23 | 0 / 0 |
| 4 | Latest systolic pressure for pac-03 | 746 | 26 | 0 / 0 |
| 5 | Most recent weight for pac-04 | 358 | 23 | 0 / 0 |
| 6 | Does pac-03 have active type 2 diabetes? | 190 | 34 | 0 / 0 |
| 7 | Does pac-01 have active type 2 diabetes? | 203 | 1 | 0 / 0 |
| 8 | Since when has pac-02 had hypertension? | 186 | 32 | 0 / 0 |
| 9 | Did pac-05’s glucose go up between the last two readings? | 558 | 47 | 0 / 0 |
| 10 | Has pac-01 ever had sinusitis? | 203 | 37 | 0 / 0 |
| Total | 3,870 | 257 | 2 / 0 |
Correct answers: 10 of 10 for both. With cl100k_base, 3,818 against 262. Question 7 cost 1 token on the lean side because the answer is []: pac-01 has no active condition.
Across the 10 raw results there were 2 CPFs, 2 CNS numbers, 2 phone numbers, 2 addresses, 4 birth-date occurrences and 20 occurrences of the name. The lean results carried none of these.
The CPF only went along in the two questions that read the Patient. The name went along in all of them, because every Observation and every Condition repeats subject.display. In the HbA1c question, 5 copies of the name went out to answer one number.
I also tested a likely agent mistake: forgetting the code filter. The raw Observation search without a filter, for pac-01 alone, returned 12 resources and 2,138 tokens. That is more than half of the 10 raw questions combined, in a single call.
What does the lean tool cost?
It has a cost, and it shows up before the first question. The definitions of the 3 lean tools, which the host sends to the model in tools/list, cost 255 tokens. The 3 raw ones cost 207. Better descriptions and two extra parameters cost 48 tokens in every conversation. Over the 10 questions the math favored the lean tools by a wide margin, and even in a one-question conversation the lean tool comes out ahead: by 106 to 827 tokens per question, after subtracting the 48.
The bigger cost is something else. The lean tool only answers what I designed it for. Allergies, medications, a test that is not one of the 4 LOINC codes: new tool. The 3 raw tools answer any question about Patient, Observation and Condition without a new tool, and a generic FHIR proxy would go further. Whoever picks lean takes on maintenance.
And responsibility moves. With the raw tool, the model gets birthDate and computes the age. With the lean tool, the server computes it against a fixed reference date. In my reading, date arithmetic is an easy place for a model to slip; taking it away looks good to me, but I didn’t measure it. And then the bug, if there is one, is mine.
What didn’t work?
The plan was to use patients from Synthea, MITRE’s open source synthetic patient generator. I downloaded the release .jar, but running it was not allowed in the environment where I ran the demo. I didn’t force it. I wrote a generator in Python, with less in it than Synthea: no Encounter, no extension, a short narrative. Resources from a real server are usually larger than mine. My bet is that the token gap grows, but I didn’t measure it.
tiktoken also got stuck: the address it downloads its vocabulary from was blocked on the network. I used the same files that ship inside the litellm 1.112.1 package, and tiktoken checked their SHA-256 before using them. This is noted in the demo’s README.
Who is this for, and when would I not use it?
It is for anyone wiring an agent to clinical data, in C# or any other language: the design is the same. In my view, the practical rule is to start lean for the questions that repeat, and keep the raw tool, if there is one, behind scopes and logging.
The code is the easy part: the lean tools file is 55 lines of C#. The hard part is deciding which questions deserve a tool, keeping that up when the FHIR profile changes, and remembering that a lean tool does not replace access control. Who can call the server, for which patient, and who gets recorded in the log is still your job. The SDK turns none of that on, as I measured in the C# MCP server test.
I would not use a raw tool with real patient data without a legal basis to send name and ID numbers to the model provider. Under the LGPD (Brazil’s General Data Protection Law, art. 5, II), health data is sensitive, and “the agent needed the field” is no justification if the question was the HbA1c value. I also would not use lean tools for open exploration, like “tell me this patient’s history”: there it turns into a huge list of tools or a raw tool in disguise.
How far does this test go?
- There is no model in the loop. What reads the tool result is code that knows where the field is. I measured what reaches the context, not whether an LLM would get it right with the raw resource.
- Tokens from tiktoken, not from Claude’s tokenizer. They are for comparing the two designs with each other.
- A simple Bundle, 20 patients, 10 questions I chose. The patients for each question come out of the Bundle by a fixed rule in the code.
- 100% synthetic data. One machine, one date (3 December 2026, at night).
Source and how to reproduce
MCP C# SDK, ModelContextProtocol.AspNetCore 2.4.0, Apache-2.0: github.com/modelcontextprotocol/csharp-sdk and NuGet. HL7 FHIR R4 (4.0.1): Observation and Patient. tiktoken 0.14.0, MIT: github.com/openai/tiktoken.
Code and real output: demos/21-mcp-fhir-tool-enxuta. You need the .NET 8 SDK and Python 3.11+. Three commands:
git clone https://github.com/rogeriorrodrigues/nursia-research-lab
cd nursia-research-lab/demos/21-mcp-fhir-tool-enxuta && dotnet build -c Release src && pip install -r requirements.txt
python3 gera_bundle.py && python3 demo.py && python3 -m pytest tests -q -s
The test checks that both designs get 10 of 10 right, that the lean one costs less than a tenth of the tokens and that it carries no identifier. Everything per question is in results/resultado.json.
So, do the tools you wired into your agent return the whole resource? How many copies of the patient’s name are going to the model right now?
Published on 4 December 2026. Changelog: 4 December 2026, publication.
The demo is part of the NursIA research repository (PPGINFOS/UFSC, FAPESC grant).

