Skip to content

Health Software Common Practices

HSCP-R-039 · recipe · Digital sobriety

Make an MCP server sober: tools by task, a token budget per definition, a measurement before and after

Written entry, version 0.1, checked on 2026-12-04.

At a glance

ImplementsHSCP-G-234 Digital sobriety of AI models
CaseInstantiates: applies an existing practice to a context.
Contexta health software product exposes its functions to language models through an MCP server, and wants to reduce what each conversation costs in tokens, round trips and energy, without losing accuracy
Verificationopen test · review

Implements HSCP-G-234, Digital sobriety of AI models. Case: instantiates the practice for the case of an MCP server, where consumption depends less on the model chosen than on what the server makes it read and on the number of turns it imposes. Complemented by HSCP-R-017 for choosing the tier on which each task runs, by HSCP-R-009 for tools loaded upfront or deferred, by HSCP-R-038 for tool fingerprints, and by HSCP-R-018 for converting the measurement into a footprint.

When

An MCP server modelled on the product's REST API exposes one tool per endpoint. To prepare a consultation, the model then chains three or four calls, rereads the definition of every tool at each turn, and receives complete results (hundreds of lines of lab results) of which it uses only a few. Each turn rereads the whole context: the cost grows with the number of round trips and with the size of what is returned.

How

  1. Design tools by task. Start from the user's tasks (preparing a consultation, finding a test result) rather than from the API endpoints. A task tool calls the API itself as many times as needed and returns a single result.
  2. Keep large results on the server side. The tool returns to the model what serves the task (the abnormal values, a count, a summary) and a reference to the detail, kept in the session for the duration of the conversation, never beyond. The model asks for the detail only if it needs it.
  3. Few tools, short descriptions. Aim for a short list: the accuracy of tool selection drops beyond thirty to fifty tools. A description says what the tool does and when to use it, without repetition or superfluous examples. The parameter schema keeps only what the model must provide.
  4. Give each definition a token budget. Count the tokens of each definition (name, description, schema) with the tokenizer of the target model, set a budget, and freeze the count with a snapshot test: a definition that grows makes the build fail, as does a definition modified without review.
  5. Measure before and after. On a fixed set of typical conversations, record the tokens read and produced, the number of model calls and tool calls, and the latency. Keep the measurement dated with the server version.
  6. Never pay for sobriety with accuracy. The measurement is made on conversations whose expected result is known: a more sober tool that returns an incomplete answer is a step backwards.

What changes between a server modelled on the API and a server designed by task:

MCP server modelled on the API compared with a server designed by task
On the left, the model calls three tools modelled on the API, one per endpoint, and receives each result in full, which makes three round trips. On the right, the model calls a single task tool, which calls the API three times on the server side, keeps the detail in the session and returns only what is useful with a reference to the detail.

Examples

Task tool, reduced result and frozen token budget (Python 3.13, run on 04/12/2026 with simulated business functions and tokens estimated at four characters: the result returned to the model is more than ten times shorter than the raw results, the definition stays within its budget, an inflated description is detected):

import json

def jetons(texte):
    """Rough estimate. In CI, use the tokenizer of the target model."""
    return max(1, len(texte) // 4)

def cout_definition(outil):
    return jetons(json.dumps(outil, ensure_ascii=False, sort_keys=True))

def controle_budget(outils, budgets, instantane):
    """Discrepancies: definition over its budget, or changed without updating the snapshot."""
    ecarts = []
    for o in outils:
        n = cout_definition(o)
        if n > budgets[o["name"]]:
            ecarts.append(f"{o['name']} : {n} jetons > budget {budgets[o['name']]}")
        if instantane.get(o["name"]) != n:
            ecarts.append(f"{o['name']} : {n} jetons, instantané {instantane.get(o['name'])}")
    return ecarts

CACHE_SESSION = {}  # emptied at the end of the session

def preparer_consultation(patient_id, lire_dossier, lire_resultats, lire_ordonnances):
    """One model call; three API calls on the server side; the detail stays in the session."""
    dossier = lire_dossier(patient_id)
    resultats = lire_resultats(patient_id)
    ordonnances = lire_ordonnances(patient_id)
    ref = f"sess-{patient_id}"
    CACHE_SESSION[ref] = {"resultats": resultats}
    anormaux = [r for r in resultats if r["anormal"]]
    return {"motif": dossier["motif"], "traitements": [o["dci"] for o in ordonnances],
            "resultats_anormaux": anormaux[:5], "nb_resultats": len(resultats), "detail": ref}

The four-characters-per-token estimate is enough for the example. In continuous integration, the budget is counted with the tokenizer of the target model, and the snapshot keeps that count.

Verification

  • CI test: the token count of each tool definition is frozen by a snapshot and stays within its budget. A definition that grows, or that changes without review, makes the build fail.
  • Test at each version: the measurement on typical conversations stays at the level of the previous version or below (tokens read, model calls), and the expected result of each conversation is reached.
  • Review: each tool corresponds to a user task, no tool returns a complete result when a summary and a reference are enough, and the list of tools stays short.

Evidence produced

Register of tools with the token cost and budget of each definition, snapshot test report, dated before-and-after measurement on typical conversations.

Evidence items

Each item attests the recipe at a given date. Frequency given for a product in service.

  • Register Register of the tools served, with the token cost of each definition and its budgetFrequency: at each release
  • Test report Report of the snapshot test of tool definitions, token budget includedFrequency: at each release
  • Test report Dated before-and-after measurement on typical conversations: tokens read and produced, model calls, tool calls, latencyFrequency: at each release

Own mappings

None beyond those of the practice.

References outside the catalogue

  • WorkOS, "What an MCP server costs you in tokens", 18/09/2026.
  • Pydantic, "Engineering MCP tools for token efficiency", 16/04/2026.

Versions

Versions of the entry (French reference), most recent first
VersionStatusDate
0.1Draft2026-12-04

How to cite: “Health Software Common Practices”, HSCP-R-039, version 0.1, https://healthtechpractices.org/en/recettes/hscp-r-039/, under the CC BY-NC-SA 4.0 licence. Licence