Skip to main content
Glama
MiltonPolanco

Clinic Laboratory MCP Server

Clinic Laboratory MCP Server

A local Model Context Protocol server for following laboratory results in a small medical clinic. It stores synthetic patients in SQLite and gives an MCP host tools to find patients, review their latest results, compare values over time, record a new result, and control pending exams.

This repository contains only the independent MCP server required by the first project milestone. The console chatbot that consumes it belongs in a separate private repository.

Academic demonstration project for CC3067 Redes using synthetic clinic laboratory data.

Features

  • Local stdio transport compatible with MCP hosts.

  • Persistent SQLite database with foreign keys and an audit trail for write operations.

  • Synthetic, repeatable demonstration dataset.

  • Validation for dates, patient ownership, reference intervals, and pending-exam completion.

  • Automated tests for the domain rules.

Related MCP server: sharp-on-fhir-mcp

Tools

Tool

Purpose

Required parameters

search_patients

Finds a patient before querying clinical data.

query

get_latest_lab_results

Returns the newest value for each test, or one requested test.

medical_record

compare_lab_results

Calculates absolute and percentage change between the first and last matching observations.

medical_record, test_code

record_lab_result

Stores a result and can close its corresponding pending exam.

medical_record, test_code, test_name, value, unit, collected_at

list_pending_exams

Lists pending or overdue exams for one patient or the whole clinic.

None

schedule_lab_exam

Adds a new pending exam with consistent order and due dates.

medical_record, test_code, test_name, ordered_at, due_date

Optional parameters and their types are exposed through each tool's MCP-generated JSON Schema. Dates use YYYY-MM-DD; result timestamps use ISO 8601.

The server also publishes the read-only resource clinic://catalog/lab-tests, which lists the codes used by the demonstration data.

Requirements

  • Python 3.11 or newer

  • uv (recommended)

  • Node.js only if the MCP Inspector will be used

Installation

Clone the repository and install the locked project environment:

git clone <repository-url>
cd clinic-lab-mcp-server
uv sync

Create the local demonstration database:

uv run clinic-lab-seed --reset

The database is written to data/clinic.db and is ignored by Git. To use another location, set the CLINIC_DB_PATH environment variable before running the server.

Running the server

Start it directly over standard input/output:

uv run clinic-lab-mcp

An MCP host normally starts this process itself. For example, use this server definition and replace the path with the absolute location of this repository:

{
  "mcpServers": {
    "clinic_labs": {
      "command": "uv",
      "args": [
        "--directory",
        "C:\\absolute\\path\\to\\clinic-lab-mcp-server",
        "run",
        "clinic-lab-mcp"
      ]
    }
  }
}

Do not print debugging text to standard output in a stdio server because protocol messages use that stream. Application diagnostics should go to standard error.

Testing with MCP Inspector

Initialize the sample database and open the official Inspector:

uv run clinic-lab-seed --reset
npx -y @modelcontextprotocol/inspector uv run clinic-lab-mcp

Useful demonstration calls:

  1. Call search_patients with {"query": "Ana"}.

  2. Call get_latest_lab_results with {"medical_record": "P-1001"}.

  3. Call compare_lab_results with {"medical_record": "P-1001", "test_code": "GLU"}.

  4. Call list_pending_exams with {"overdue_only": true}.

  5. Record a matching result with the returned pending exam ID and verify that it no longer appears as pending.

Running automated tests

uv run pytest

For a coverage report:

uv run pytest --cov=clinic_labs_mcp --cov-report=term-missing

Data model

patients identifies each fictional patient by medical record. lab_results stores dated numeric observations and their reference intervals. pending_exams tracks ordered, completed, or cancelled tests and can point to the result that completed an order. audit_log records every result or pending-exam creation.

SQLite is used for local storage with support for transactions, constraints, indexes, and durable records.

Project structure

src/clinic_labs_mcp/
  database.py   SQLite schema and connection setup
  service.py    Validation and domain operations
  server.py     MCP tools, resource, and stdio entry point
  seed.py       Repeatable synthetic demonstration data
tests/          Automated domain tests

Protocol notes

The implementation uses the official Python MCP SDK and the stdio transport. During initialization, the host and server negotiate capabilities through JSON-RPC 2.0. Tool discovery uses tools/list; calls use tools/call; each request is matched to a response by its JSON-RPC identifier. The SDK serializes these messages, while the functions in server.py implement the actual clinic operations.

License

This academic project is provided for demonstration and evaluation purposes.

Available Tools

6 tools
compare_lab_resultsB

Compare the earliest and latest result of one test in an optional YYYY-MM-DD range.

ParametersJSON Schema
NameRequiredDescriptionDefault
end_dateNo
test_codeYes
start_dateNo
medical_recordYes

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

B3.3/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description bears the full burden of disclosing behavior. It does explain the core behavior (comparing earliest vs latest result) and the optional date range, but it does not disclose edge-case behavior such as what happens when no results exist, how dates are interpreted, or whether the range is inclusive. This is moderate transparency for a read-style comparaison tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

One sentence with no filler. It front-loads the comparison action and includes the key scoping detail (date range) in the same breath. Every word contributes, and the length is proportionate to the simplicity of the operation.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Although an output schema exists and may explain return values, the input side is incomplete: the required medical_record parameter is not described anywhere, and usage guidance is absent. The description alone does not give an agent enough context to confidently invoke this tool for a new patient or test, especially with four parameters and no annotated safety or behavior hints.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate for missing parameter documentation. It adds meaning for the date range ('optional YYYY-MM-DD range') and implies test_code via 'one test', but it never mentions the required medical_record parameter or clarifies how start_date/end_date individually behave. The core identity of the patient/record is left to the raw schema field name, which is insufficient at 0% coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a clear, specific action: compare the earliest and latest result of one test. It also scopes the comparison to an optional date range, which distinguishes it from sibling tools like get_latest_lab_results that only fetch latest results. The verb 'compare' and resource 'earliest/latest result of one test' leave little ambiguity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies a use case but does not explicitly state when to choose this tool over alternatives such as get_latest_lab_results or list_pending_exams. There is no when-to-use/when-not-to-use guidance or mention of alternatives, so an agent must infer the appropriate context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_latest_lab_resultsA

Get the newest result for each test of a patient, or for one test code.

ParametersJSON Schema
NameRequiredDescriptionDefault
test_codeNo
medical_recordYes

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A3.8/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden of behavioral disclosure. It reveals that results are grouped by test and optionally filtered by test code, but does not specify what 'newest' means (e.g., collection time vs result time) or any other limitations. The read-only nature is implied by 'get'.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence, front-loaded with verb and resource, zero redundant words. It communicates both execution modes without clutter.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a two-parameter retrieval tool with an output schema, the description is adequate for correct invocation. It conveys the main behavior and the two modes. Adding a note about timestamp semantics or a pointer to alternative tools would raise completeness, but it is sufficient for typical use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description compensates by associating medical_record with the patient and clarifying that test_code filters to one specific test. It does not explain accepted values or formats for either parameter, but it adds meaning beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses a specific verb (get) with a clear resource (lab results) and scope (newest per test for a patient, or one test code). This clearly distinguishes it from siblings such as record_lab_result, schedule_lab_exam, compare_lab_results, and search_patients.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies two usage modes (with and without a test_code) but provides no explicit guidance on when to choose this tool over its siblings. An agent must infer that it is the right tool for fetching latest results rather than comparing or listing pending exams.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

list_pending_examsA

List pending exams for every patient or one medical record, optionally overdue only.

ParametersJSON Schema
NameRequiredDescriptionDefault
overdue_onlyNo
medical_recordNo

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A4.2/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must carry behavioral context. It conveys a read-only listing action and the filtering semantics, but it does not describe edge cases, ordering, grouping, or what 'pending' means in terms of status transitions. Still, the basic behavior is neither misleading nor opaque.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

A single sentence that is concise, front-loaded, and contains no filler. It efficiently communicates both the primary action and the optional filters.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple read-only listing tool with two optional parameters and an output schema, the description is largely adequate. It does not define 'pending' precisely or specify ordering/grouping, but the core invocation logic is complete enough to act on.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It successfully gives meaning to both parameters: 'medical_record' corresponds to 'every patient or one medical record', and 'overdue_only' is explained as 'optionally overdue only'. It does not give format details, but the semantic coverage is strong for a two-parameter tool.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'List' and the resource 'pending exams', and specifies the two scoping options: every patient or a single medical record, plus the optional overdue-only filter. This distinguishes it from sibling tools that record, schedule, or compare lab results.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description offers a clear context for use: retrieving pending exams, with a clear choice between all patients and one record. It does not explicitly name alternatives or exclusion conditions, but the scope is clear enough for an agent to decide when to invoke it.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

record_lab_resultC

Record a laboratory result and optionally complete the matching pending exam.

ParametersJSON Schema
NameRequiredDescriptionDefault
unitYes
notesNo
valueYes
test_codeYes
test_nameYes
collected_atYes
reference_maxNo
reference_minNo
medical_recordYes
pending_exam_idNo

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full responsibility for behavioral disclosure. It mentions the side effect of optionally completing a pending exam, but does not explain what 'complete' means, whether it creates or overwrites data, what happens if pending_exam_id is invalid, or any other behavioral traits. This is thin for a mutating tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence that front-loads the primary action and then states the optional behavior. There is no wasted wording. However, for a tool with 10 parameters and no other documentation, this brevity, while clean, leaves substantial gaps—so it is not perfect.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 10 parameters, 0% schema coverage, and no annotations, the description is severely incomplete. It does not define how parameters relate (e.g., pending_exam_id matching, reference ranges), how to construct a valid request, or any output behavior. The output schema exists, but the input semantics are almost entirely unspecified, so an agent cannot reliably call this tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0% and the description does not explain any of the 10 parameters, including required ones like test_code, value, unit, or medical_record. The only hint is 'pending exam' which maps to pending_exam_id, but even that is not explicit. The description adds almost no semantic meaning beyond the schema titles.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Record a laboratory result') and the resource, with an additional optional behavior ('complete the matching pending exam'). This distinguishes it from all siblings, which are about scheduling, searching, retrieving, comparing, or listing. An agent can easily tell this is the write/record tool.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The verb 'Record' implies the tool is for entering lab results, and the mention of completing a pending exam gives some context for when to use it. However, there is no explicit guidance about when not to use it or which sibling to choose instead. The usage context is implied rather than stated directly.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

schedule_lab_examC

Schedule a laboratory exam using YYYY-MM-DD order and due dates.

ParametersJSON Schema
NameRequiredDescriptionDefault
due_dateYes
test_codeYes
test_nameYes
ordered_atYes
medical_recordYes

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

C2.6/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It only states the basic action and a date format hint, without disclosing side effects, whether the schedule can be modified, required permissions, or what the response indicates. This is a scheduling/mutation operation, and the behavior is largely opaque.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single short sentence with no filler words, and the core action is front-loaded. However, the phrasing 'YYYY-MM-DD order and due dates' is confusing and poorly structured, and the sentence omits important context that would make it genuinely useful.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With five required parameters, zero schema descriptions, no annotations, and an output schema that the description does not illuminate, this description is not complete enough. It lacks parameter explanations, behavioral details, and usage context. While it is a relatively simple scheduling action, the agent is left with major gaps in how to call the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate for the five undocumented string parameters. It only hints that ordered_at and due_date should use YYYY-MM-DD format, but gives no meaning for medical_record, test_code, or test_name. This is insufficient for an agent to construct a correct invocation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description names a specific verb and resource ('Schedule a laboratory exam'), which clearly identifies the tool's core action. However, the phrase 'using YYYY-MM-DD order and due dates' is awkwardly worded and could confuse an agent, and it does not explicitly differentiate from the sibling tools that also relate to lab exams.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

There is no guidance on when to use this tool versus siblings like record_lab_result or list_pending_exams. The date format hint is a formatting instruction, not a usage context. An agent receives no information about prerequisites, exclusions, or alternative tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

search_patientsA

Find a patient by medical record or partial name before requesting clinical data.

ParametersJSON Schema
NameRequiredDescriptionDefault
queryYes

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A4.2/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description must carry the behavioral burden. It conveys read-oriented search behavior via 'Find' and constrains what can be searched, but it does not disclose match multiplicity, no-match behavior, or access requirements. No contradiction is present, but some gaps remain.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

A single front-loaded sentence that packs verb, resource, query semantics, and usage timing with no filler. Every word contributes to selecting and invoking the tool.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple one-parameter lookup tool with an output schema available, the description covers what to pass and when to call it. It does not cover edge-case behavior, but that is not critical at this complexity level and the output schema can describe return values.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema provides only a bare 'query' property with 0% description coverage, so the tool description is the sole source of parameter semantics. It states that the query accepts a medical record or partial name, which meaningfully compensates for the schema gap, though it omits format specifics such as minimum length or exact MRN syntax.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a clear verb ('Find'), a specific resource ('patient'), and the accepted query forms ('medical record or partial name'). It also frames the tool as a preliminary step before clinical data requests, distinguishing it from the sibling lab-result tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It explicitly says to use this tool 'before requesting clinical data,' which tells the agent this is the prerequisite lookup step. It does not enumerate exclusions or name an alternative, but the context is clear enough for routing among the sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. 6 tool updatesv0.1.0
    • First observedcompare_lab_results
    • First observedget_latest_lab_results
    • First observedlist_pending_exams
    • First observedrecord_lab_result
    • First observedschedule_lab_exam
    • First observedsearch_patients

TDQS

A3.6/5.0
Disambiguation5/5

Each tool targets a distinct action in the lab workflow: scheduling, recording, searching, retrieving, comparing, and listing pending exams. There is no meaningful overlap between tool purposes, so an agent can reliably select the right tool.

Naming Consistency5/5

All tool names follow a consistent snake_case verb_noun pattern, such as record_lab_result, schedule_lab_exam, and list_pending_exams. Modifiers like 'latest' and 'pending' are used uniformly and do not break the convention.

Tool Count5/5

Six tools is a well-scoped count for a laboratory-focused server. Each tool covers a clear part of the domain without unnecessary duplication or bloat.

Completeness4/5

The core lab workflow is well covered: search patients, schedule exams, record results, list pending exams, and retrieve/compare results. Minor gaps exist, such as no explicit update/cancel flow for scheduled exams or recorded results, but agents can work around these for typical lab tasks.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    An MCP server and web application that enables natural language medical queries and patient data analysis powered by Gemini AI. It allows users to track and analyze patient biometrics, including vitals, sleep patterns, and laboratory results, through a comprehensive set of automated medical tools.
    -
  • A
    license
    Not graded
    quality
    C
    maintenance
    A clean-room SHARP-on-MCP compliant FHIR R4 MCP server that enables AI agents to interact with any FHIR R4 endpoint using SHARP context headers, without server-side OAuth. It provides clinical tools, lab results, imaging, and interactive MCP-UI dashboards.
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables interaction with FHIR R4 healthcare data through SHARP-on-MCP tools, including search, read, and clinical context aggregation, with built-in Chart.js dashboards for visualizing lab trends, vitals, and patient data.
    8
    3
    MIT
  • A
    license
    B
    quality
    B
    maintenance
    A local-first, model-agnostic MCP server that stores personal health data in a SQLite file and provides analysis-ready views for any AI client to log, retrieve, and reason over health records.
    79
    MIT

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/MiltonPolanco/clinic-lab-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server