Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions app/mcp/v1/tools/allergy_intolerance.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any, Literal

from fastmcp import FastMCP

from app.schemas.fhir_schemas import FhirError, FhirQueryRequest, FhirQueryResponse
Expand All @@ -8,7 +10,9 @@

@allergy_intolerance_router.tool
async def request_allergy_intolerance_resource(
request: FhirQueryRequest,
method: Literal["GET", "POST", "PUT", "DELETE"],
path: str,
body: dict[str, Any] | None = None,
) -> FhirQueryResponse | FhirError:
"""
Makes an HTTP request to the FHIR server.
Expand All @@ -19,7 +23,8 @@ async def request_allergy_intolerance_resource(
- Do not guess, auto-fill, or assume any missing data.
- When deleting an allergy intolerance, ask the user for confirmation with details
of the allergy intolerance and wait for the user's confirmation.
- Provide links to the app (not api) allergy intolerance resource in the final response.
- Provide links to the app (not api) allergy intolerance resource in the final
response.

Args:
method: HTTP method (GET, POST, PUT, DELETE)
Expand All @@ -30,6 +35,8 @@ async def request_allergy_intolerance_resource(
JSON response from the FHIR server
"""

request = FhirQueryRequest(method=method, path=path, body=body)

try:
response = fhir_client.request(
method=request.method,
Expand Down
11 changes: 9 additions & 2 deletions app/mcp/v1/tools/condition.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any, Literal

from fastmcp import FastMCP

from app.schemas.fhir_schemas import FhirError, FhirQueryRequest, FhirQueryResponse
Expand All @@ -8,13 +10,16 @@

@condition_router.tool
async def request_condition_resource(
request: FhirQueryRequest,
method: Literal["GET", "POST", "PUT", "DELETE"],
path: str,
body: dict[str, Any] | None = None,
) -> FhirQueryResponse | FhirError:
"""
Makes an HTTP request to the FHIR server.
Use this tool to perform CRUD operations only on the FHIR Condition resource.
Rules:
- When creating or updating a condition, use only the data explicitly provided by the user.
- When creating or updating a condition, use only the data explicitly provided by
the user.
- Do not guess, auto-fill, or assume any missing data.
- When deleting a condition, ask the user for confirmation with details of the
condition and wait for the user's confirmation.
Expand All @@ -29,6 +34,8 @@ async def request_condition_resource(
JSON response from the FHIR server
"""

request = FhirQueryRequest(method=method, path=path, body=body)

try:
response = fhir_client.request(
method=request.method,
Expand Down
9 changes: 7 additions & 2 deletions app/mcp/v1/tools/document_reference.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any, Literal

from fastmcp import FastMCP

from app.config import settings
Expand All @@ -17,7 +19,9 @@

@document_reference_router.tool
async def request_document_reference_resource(
request: FhirQueryRequest,
method: Literal["GET", "POST", "PUT", "DELETE"],
path: str,
body: dict[str, Any] | None = None,
) -> FhirQueryResponse | FhirError:
"""
Makes an HTTP request to the FHIR server.
Expand All @@ -40,6 +44,8 @@ async def request_document_reference_resource(

"""

request = FhirQueryRequest(method=method, path=path, body=body)

try:
response = fhir_client.request(
method=request.method,
Expand Down Expand Up @@ -166,7 +172,6 @@ async def search_pinecone(

# return text


# @document_reference_router.tool
# async def check_if_pinecone_document_exists(
# fhir_document_id: str,
Expand Down
11 changes: 9 additions & 2 deletions app/mcp/v1/tools/encounter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any, Literal

from fastmcp import FastMCP

from app.schemas.fhir_schemas import FhirError, FhirQueryRequest, FhirQueryResponse
Expand All @@ -8,13 +10,16 @@

@encounter_router.tool
async def request_encounter_resource(
request: FhirQueryRequest,
method: Literal["GET", "POST", "PUT", "DELETE"],
path: str,
body: dict[str, Any] | None = None,
) -> FhirQueryResponse | FhirError:
"""
Makes an HTTP request to the FHIR server.
Use this tool to perform CRUD operations only on the FHIR Encounter resource.
Rules:
- When creating or updating an encounter, use only the data explicitly provided by the user.
- When creating or updating an encounter, use only the data explicitly provided by
the user.
- Do not guess, auto-fill, or assume any missing data.
- When deleting an encounter, ask the user for confirmation with details of the
encounter and wait for the user's confirmation.
Expand All @@ -29,6 +34,8 @@ async def request_encounter_resource(
JSON response from the FHIR server
"""

request = FhirQueryRequest(method=method, path=path, body=body)

try:
response = fhir_client.request(
method=request.method,
Expand Down
14 changes: 10 additions & 4 deletions app/mcp/v1/tools/family_member_history.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any, Literal

from fastmcp import FastMCP

from app.schemas.fhir_schemas import FhirError, FhirQueryRequest, FhirQueryResponse
Expand All @@ -8,7 +10,9 @@

@family_member_history_router.tool
async def request_family_member_history_resource(
request: FhirQueryRequest,
method: Literal["GET", "POST", "PUT", "DELETE"],
path: str,
body: dict[str, Any] | None = None,
) -> FhirQueryResponse | FhirError:
"""
Makes an HTTP request to the FHIR server.
Expand All @@ -19,18 +23,20 @@ async def request_family_member_history_resource(
- Do not guess, auto-fill, or assume any missing data.
- When deleting a family member history, ask the user for confirmation with details
of the family member history and wait for the user's confirmation.
- Provide links to the app (not api) family member history resource in the final response.
- Provide links to the app (not api) family member history resource in the final
response.

Args:
method: HTTP method (GET, POST, PUT, DELETE)
path: Resource path (e.g., "/FamilyMemberHistory",
"/FamilyMemberHistory?patient=Patient/123")
path: Resource path (e.g., "/FamilyMemberHistory", "/FamilyMemberHistory?patient=Patient/123")
body: Optional JSON data for POST/PUT requests)

Returns:
JSON response from the FHIR server
"""

request = FhirQueryRequest(method=method, path=path, body=body)

try:
response = fhir_client.request(
method=request.method,
Expand Down
12 changes: 6 additions & 6 deletions app/mcp/v1/tools/generic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
"""
This module contains the tool for making generic requests to the FHIR server, when the
other tools are not applicable.
"""
from typing import Any, Literal

from fastmcp import FastMCP

Expand All @@ -13,13 +10,14 @@

@generic_router.tool
async def request_generic_resource(
request: FhirQueryRequest,
method: Literal["GET", "POST", "PUT", "DELETE"],
path: str,
body: dict[str, Any] | None = None,
) -> FhirQueryResponse | FhirError:
"""
Makes an HTTP request to the FHIR server.
Use this tool to perform CRUD operations on any FHIR resource ONLY if the other
tools are not applicable.

Rules:
- When creating or updating a resource, use only the data explicitly provided by
the user.
Expand All @@ -37,6 +35,8 @@ async def request_generic_resource(
JSON response from the FHIR server
"""

request = FhirQueryRequest(method=method, path=path, body=body)

try:
response = fhir_client.request(
method=request.method,
Expand Down
8 changes: 7 additions & 1 deletion app/mcp/v1/tools/immunization.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any, Literal

from fastmcp import FastMCP

from app.schemas.fhir_schemas import FhirError, FhirQueryRequest, FhirQueryResponse
Expand All @@ -8,7 +10,9 @@

@immunization_router.tool
async def request_immunization_resource(
request: FhirQueryRequest,
method: Literal["GET", "POST", "PUT", "DELETE"],
path: str,
body: dict[str, Any] | None = None,
) -> FhirQueryResponse | FhirError:
"""
Makes an HTTP request to the FHIR server.
Expand All @@ -30,6 +34,8 @@ async def request_immunization_resource(
JSON response from the FHIR server
"""

request = FhirQueryRequest(method=method, path=path, body=body)

try:
response = fhir_client.request(
method=request.method,
Expand Down
13 changes: 10 additions & 3 deletions app/mcp/v1/tools/medication.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any, Literal

from fastmcp import FastMCP

from app.schemas.fhir_schemas import FhirError, FhirQueryRequest, FhirQueryResponse
Expand All @@ -8,27 +10,32 @@

@medication_router.tool
async def request_medication_resource(
request: FhirQueryRequest,
method: Literal["GET", "POST", "PUT", "DELETE"],
path: str,
body: dict[str, Any] | None = None,
) -> FhirQueryResponse | FhirError:
"""
Makes an HTTP request to the FHIR server.
Use this tool to perform CRUD operations only on the FHIR Medication resource.
Rules:
- When creating or updating a medication, use only the data explicitly provided by the user.
- When creating or updating a medication, use only the data explicitly provided by
the user.
- Do not guess, auto-fill, or assume any missing data.
- When deleting a medication, ask the user for confirmation with details of the
medication and wait for the user's confirmation.
- Provide links to the app (not api) medication resource in the final response.

Args:
method: HTTP method (GET, POST, PUT, DELETE)
path: Resource path (e.g., "/Medication", "/Medication?code=aspirin")
path: Resource path (e.g., "/Medication", "/Medication?code=12345")
body: Optional JSON data for POST/PUT requests)

Returns:
JSON response from the FHIR server
"""

request = FhirQueryRequest(method=method, path=path, body=body)

try:
response = fhir_client.request(
method=request.method,
Expand Down
8 changes: 7 additions & 1 deletion app/mcp/v1/tools/observation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any, Literal

from fastmcp import FastMCP

from app.config import settings
Expand Down Expand Up @@ -71,7 +73,9 @@ async def get_loinc_codes(

@observation_router.tool
async def request_observation_resource(
request: FhirQueryRequest,
method: Literal["GET", "POST", "PUT", "DELETE"],
path: str,
body: dict[str, Any] | None = None,
) -> FhirQueryResponse | FhirError:
"""
Makes an HTTP request to the FHIR server.
Expand All @@ -98,6 +102,8 @@ async def request_observation_resource(
JSON response from the FHIR server
"""

request = FhirQueryRequest(method=method, path=path, body=body)

try:
response = fhir_client.request(
method=request.method,
Expand Down
8 changes: 7 additions & 1 deletion app/mcp/v1/tools/patient.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any, Literal

from fastmcp import FastMCP

from app.schemas.fhir_schemas import FhirError, FhirQueryRequest, FhirQueryResponse
Expand All @@ -8,7 +10,9 @@

@patient_router.tool
async def request_patient_resource(
request: FhirQueryRequest,
method: Literal["GET", "POST", "PUT", "DELETE"],
path: str,
body: dict[str, Any] | None = None,
) -> FhirQueryResponse | FhirError:
"""
Makes an HTTP request to the FHIR server.
Expand All @@ -29,6 +33,8 @@ async def request_patient_resource(
JSON response from the FHIR server
"""

request = FhirQueryRequest(method=method, path=path, body=body)

try:
response = fhir_client.request(
method=request.method,
Expand Down