diff --git a/app/mcp/v1/tools/allergy_intolerance.py b/app/mcp/v1/tools/allergy_intolerance.py index 71a3e68..543f3b2 100644 --- a/app/mcp/v1/tools/allergy_intolerance.py +++ b/app/mcp/v1/tools/allergy_intolerance.py @@ -1,3 +1,5 @@ +from typing import Any, Literal + from fastmcp import FastMCP from app.schemas.fhir_schemas import FhirError, FhirQueryRequest, FhirQueryResponse @@ -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. @@ -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) @@ -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, diff --git a/app/mcp/v1/tools/condition.py b/app/mcp/v1/tools/condition.py index 54cb002..38b667d 100644 --- a/app/mcp/v1/tools/condition.py +++ b/app/mcp/v1/tools/condition.py @@ -1,3 +1,5 @@ +from typing import Any, Literal + from fastmcp import FastMCP from app.schemas.fhir_schemas import FhirError, FhirQueryRequest, FhirQueryResponse @@ -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. @@ -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, diff --git a/app/mcp/v1/tools/document_reference.py b/app/mcp/v1/tools/document_reference.py index eed8ef3..fb74c28 100644 --- a/app/mcp/v1/tools/document_reference.py +++ b/app/mcp/v1/tools/document_reference.py @@ -1,3 +1,5 @@ +from typing import Any, Literal + from fastmcp import FastMCP from app.config import settings @@ -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. @@ -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, @@ -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, diff --git a/app/mcp/v1/tools/encounter.py b/app/mcp/v1/tools/encounter.py index 1228f5d..a20ca73 100644 --- a/app/mcp/v1/tools/encounter.py +++ b/app/mcp/v1/tools/encounter.py @@ -1,3 +1,5 @@ +from typing import Any, Literal + from fastmcp import FastMCP from app.schemas.fhir_schemas import FhirError, FhirQueryRequest, FhirQueryResponse @@ -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. @@ -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, diff --git a/app/mcp/v1/tools/family_member_history.py b/app/mcp/v1/tools/family_member_history.py index b7a50b6..5aa5d3a 100644 --- a/app/mcp/v1/tools/family_member_history.py +++ b/app/mcp/v1/tools/family_member_history.py @@ -1,3 +1,5 @@ +from typing import Any, Literal + from fastmcp import FastMCP from app.schemas.fhir_schemas import FhirError, FhirQueryRequest, FhirQueryResponse @@ -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. @@ -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, diff --git a/app/mcp/v1/tools/generic.py b/app/mcp/v1/tools/generic.py index c6d421c..21335f5 100644 --- a/app/mcp/v1/tools/generic.py +++ b/app/mcp/v1/tools/generic.py @@ -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 @@ -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. @@ -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, diff --git a/app/mcp/v1/tools/immunization.py b/app/mcp/v1/tools/immunization.py index aa68f5c..14f90db 100644 --- a/app/mcp/v1/tools/immunization.py +++ b/app/mcp/v1/tools/immunization.py @@ -1,3 +1,5 @@ +from typing import Any, Literal + from fastmcp import FastMCP from app.schemas.fhir_schemas import FhirError, FhirQueryRequest, FhirQueryResponse @@ -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. @@ -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, diff --git a/app/mcp/v1/tools/medication.py b/app/mcp/v1/tools/medication.py index ff08ce8..ba45a0b 100644 --- a/app/mcp/v1/tools/medication.py +++ b/app/mcp/v1/tools/medication.py @@ -1,3 +1,5 @@ +from typing import Any, Literal + from fastmcp import FastMCP from app.schemas.fhir_schemas import FhirError, FhirQueryRequest, FhirQueryResponse @@ -8,13 +10,16 @@ @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. @@ -22,13 +27,15 @@ async def request_medication_resource( 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, diff --git a/app/mcp/v1/tools/observation.py b/app/mcp/v1/tools/observation.py index fcab1ee..b9a9f48 100644 --- a/app/mcp/v1/tools/observation.py +++ b/app/mcp/v1/tools/observation.py @@ -1,3 +1,5 @@ +from typing import Any, Literal + from fastmcp import FastMCP from app.config import settings @@ -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. @@ -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, diff --git a/app/mcp/v1/tools/patient.py b/app/mcp/v1/tools/patient.py index 410ec79..95f8f55 100644 --- a/app/mcp/v1/tools/patient.py +++ b/app/mcp/v1/tools/patient.py @@ -1,3 +1,5 @@ +from typing import Any, Literal + from fastmcp import FastMCP from app.schemas.fhir_schemas import FhirError, FhirQueryRequest, FhirQueryResponse @@ -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. @@ -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,