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 | ||
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 | ||
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 | ||
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 | ||
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 | ||
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 | ||
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
PatientNow MCP server: book appointment, reschedule appointment, find free slots, list patients.
311Hosted MCP server for the Healthie EHR & telehealth API: patients, appointments, charting, tasks.
Securely access and track personal blood test results.
MCP server for US nursing facility search and ownership lookup (NursingHomeDatabase).
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
- AlicenseCqualityDmaintenanceA 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
- FlicenseNot gradedqualityDmaintenanceAn MCP server that enables LLMs to securely query synthetic clinical data through validated, scoped tools (patient summaries, conditions, medications, lab trends, encounters) while maintaining audit logs and access controls.-