Clinic Laboratory MCP Server
This server provides an MCP interface for managing a clinic's laboratory workflow, from patient lookup and lab result tracking to scheduling and completing pending exams.
search_patients: find patients by medical record or partial name.
get_latest_lab_results: retrieve the newest result for each test, or filter by one test code.
compare_lab_results: compare earliest vs latest result for a test, with optional date range, showing change and direction.
record_lab_result: add a lab result with reference ranges and optional notes; can complete a linked pending exam.
list_pending_exams: view pending exams, optionally filtered by patient or overdue status.
schedule_lab_exam: create a pending exam with order and due dates.
Publish a
clinic://catalog/lab-testsresource listing demonstration test codes (GLU, HBA1C, CHOL, CREA, TSH).
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Clinic Laboratory MCP ServerWhat are the latest lab results for P-1001?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Clinic Laboratory MCP Server
Local Model Context Protocol server for following laboratory results in a small medical clinic. It stores synthetic patient data in SQLite and exposes tools to search patients, review current results, compare measurements over time, record new results, and manage pending exams.
This is the independent public server developed for the first CC3067 Networks project milestone. The console host that consumes it is maintained in a separate private repository.
Features
Local MCP communication through the
stdiotransport.Persistent SQLite storage with foreign keys, indexes, constraints, and transactions.
Repeatable synthetic dataset for demonstrations.
Date, ownership, numeric value, reference interval, and pending-exam validation.
Audit entries for result and pending-exam creation.
Automated domain tests.
Related MCP server: sharp-on-fhir-mcp
MCP specification
The server is started as a local process. It does not expose an HTTP port or REST endpoints. During MCP initialization it publishes six tools and one resource.
Tools
Tool | Required parameters | Optional parameters | Result |
|
| None | Matching record numbers, names, and birth dates. |
|
|
| Latest result for each test or one selected code. |
|
|
| First and last observations, absolute change, percentage change, and direction. |
|
|
| Created result, reference status, and completed pending exam ID when supplied. |
| None |
| Pending exams ordered by due date with an overdue flag. |
|
| None | Created pending exam and its identifier. |
Dates use YYYY-MM-DD. collected_at accepts an ISO 8601 date or timestamp. Test codes are normalized to uppercase and medical record matching is case-insensitive.
Domain validation failures are returned by MCP as tool errors. Examples include an unknown patient, an invalid date range, a future collection date, an inverted reference interval, fewer than two observations for comparison, and a pending exam assigned to another patient.
Resource
URI | MIME type | Purpose |
|
| Lists the GLU, HBA1C, CHOL, CREA, and TSH codes used in the demonstration dataset. |
Requirements
Python 3.11 or newer
Node.js only when using MCP Inspector
Installation
Clone the public repository and install its locked environment:
git clone https://github.com/MiltonPolanco/clinic-lab-mcp-server.git
cd clinic-lab-mcp-server
uv sync --lockedCreate or restore the demonstration database:
uv run clinic-lab-seed --resetThe default database is data/clinic.db. It is generated locally and ignored by Git.
Configuration
Set CLINIC_DB_PATH before starting the server to use another SQLite file:
$env:CLINIC_DB_PATH = "C:\data\clinic-demo.db"
uv run clinic-lab-seed --reset
uv run clinic-lab-mcpWithout this variable, the server uses the database under the repository's data directory.
Running the server
Start it directly over standard input/output:
uv run clinic-lab-mcpAn MCP host normally starts this process. Example configuration:
{
"mcpServers": {
"clinic_labs": {
"command": "uv",
"args": [
"--directory",
"C:\\absolute\\path\\to\\clinic-lab-mcp-server",
"run",
"clinic-lab-mcp"
]
}
}
}Do not write diagnostic messages to standard output because MCP protocol messages use that stream. Application diagnostics should use standard error.
Demonstration
After resetting the database, a representative sequence is:
Call
search_patientswith{"query": "Ana"}. The returned record isP-1001.Call
get_latest_lab_resultswith{"medical_record": "P-1001"}.Call
compare_lab_resultswith{"medical_record": "P-1001", "test_code": "GLU"}. The seeded glucose values decrease from 112 to 104 mg/dL.Call
list_pending_examswith{"medical_record": "P-1001"}and retain the returned exam ID.Call
record_lab_resultwith the patient, GLU result data, and thatpending_exam_id.Call
list_pending_examsagain and verify that the completed exam is no longer returned.
MCP Inspector
Initialize the database and open the official Inspector:
uv run clinic-lab-seed --reset
npx -y @modelcontextprotocol/inspector uv run clinic-lab-mcpTests
Run all automated tests:
uv run pytestRun them with branch and line coverage:
uv run pytest --cov=clinic_labs_mcp --cov-report=term-missingData model
patientsidentifies each fictional patient by medical record.lab_resultsstores dated numeric observations and reference intervals.pending_examstracks pending, completed, or cancelled orders and can reference the result that completed an order.audit_logrecords creation operations and their associated entity.
SQLite connections enable foreign keys and use transactions so a result and its matching pending-exam update either complete together or are rolled back together.
Source 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/Protocol notes
The implementation uses the official Python MCP SDK. Initialization negotiates capabilities through JSON-RPC 2.0, tools/list publishes the tool catalog, and tools/call invokes individual operations. The SDK handles protocol serialization while the functions in server.py implement the clinic behavior.
License
This academic project is provided for demonstration and evaluation purposes.
Available Tools
6 toolscompare_lab_resultsB
Compare the earliest and latest result of one test in an optional YYYY-MM-DD range.
| Name | Required | Description | Default |
|---|---|---|---|
| end_date | No | ||
| test_code | Yes | ||
| start_date | No | ||
| medical_record | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
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.
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.
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.
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.
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.
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.
| Name | Required | Description | Default |
|---|---|---|---|
| test_code | No | ||
| medical_record | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
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.
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.
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.
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.
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.
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.
| Name | Required | Description | Default |
|---|---|---|---|
| overdue_only | No | ||
| medical_record | No |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
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.
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.
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.
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.
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.
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.
| Name | Required | Description | Default |
|---|---|---|---|
| unit | Yes | ||
| notes | No | ||
| value | Yes | ||
| test_code | Yes | ||
| test_name | Yes | ||
| collected_at | Yes | ||
| reference_max | No | ||
| reference_min | No | ||
| medical_record | Yes | ||
| pending_exam_id | No |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
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.
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.
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.
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.
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.
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.
| Name | Required | Description | Default |
|---|---|---|---|
| due_date | Yes | ||
| test_code | Yes | ||
| test_name | Yes | ||
| ordered_at | Yes | ||
| medical_record | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
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.
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.
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.
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.
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.
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.
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
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.
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.
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.
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.
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.
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.
6 tool updates
v0.1.0- First observed
compare_lab_results - First observed
get_latest_lab_results - First observed
list_pending_exams - First observed
record_lab_result - First observed
schedule_lab_exam - First observed
search_patients
TDQS
Scored across 6 tools
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.
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.
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.
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
Related MCP Connectors
Hosted MCP server for the Healthie EHR & telehealth API: patients, appointments, charting, tasks.
MCP server for US nursing facility search and ownership lookup (NursingHomeDatabase).
Read-only U.S. lab-test catalog, collection-site search, and reference-range context.
Synthetic EHR: medications, labs, conditions, allergies, immunizations, FHIR R4. No API key.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceAn 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.-
- AlicenseNot gradedqualityCmaintenanceA 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
- AlicenseNot gradedqualityDmaintenanceEnables 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.1 npm3MIT
- AlicenseCqualityBmaintenanceA 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.79MIT