Skip to main content
Glama

FHIR Progressive Discovery MCP Server

by CaseMark
test_server.py•5.18 kB
""" Quick test script to validate the FHIR MCP server functionality """ def test_discovery(): """Test progressive discovery functions""" print("šŸ” Testing Progressive Discovery...") # Import after ensuring dependencies are installed from fhir_mcp_server import ( discover_resource_groups, explore_resource_group, list_all_resource_groups, RESOURCE_GROUPS, ) # Test 1: Discover groups by intent print("\n1ļøāƒ£ Testing discover_resource_groups with intent 'patient care'") result = discover_resource_groups("patient care") print(f" Found {len(result['discovered_groups'])} relevant groups") for group in result["discovered_groups"][:3]: print(f" - {group['name']}: {group['resource_count']} resources") # Test 2: List all groups print("\n2ļøāƒ£ Testing list_all_resource_groups") result = list_all_resource_groups() print(f" Total groups: {result['total_groups']}") # Test 3: Explore specific group print("\n3ļøāƒ£ Testing explore_resource_group('clinical')") result = explore_resource_group("clinical") print(f" Group: {result['name']}") print(f" Resources: {', '.join(result['resources'][:5])}...") print("\nāœ… Discovery tests passed!") def test_resource_operations(): """Test FHIR resource operations""" print("\nšŸ„ Testing FHIR Resource Operations...") from fhir_mcp_server import get_resource_schema, create_resource, validate_resource # Test 1: Get schema print("\n1ļøāƒ£ Testing get_resource_schema('Patient')") result = get_resource_schema("Patient") if "schema" in result: print(f" Schema retrieved for {result['resource_type']}") print(f" FHIR version: {result.get('fhir_version', 'unknown')}") print(f" Required fields: {result.get('required_fields', [])[:3]}...") else: print(f" āš ļø Error: {result.get('error', 'Unknown error')}") # Test 2: Create a Patient resource print("\n2ļøāƒ£ Testing create_resource (Patient)") patient_data = { "resourceType": "Patient", "active": True, "name": [{"use": "official", "family": "TestPatient", "given": ["John"]}], "gender": "male", "birthDate": "1990-01-01", } result = create_resource("Patient", patient_data) if result.get("success"): print(f" āœ… Patient created successfully") print(f" Resource ID: {result.get('id', 'N/A')}") else: print(f" āš ļø Error: {result.get('error', 'Unknown error')}") # Test 3: Validate a resource print("\n3ļøāƒ£ Testing validate_resource") import json patient_json = json.dumps(patient_data) result = validate_resource(patient_json) if result.get("valid"): print(f" āœ… Resource is valid FHIR") else: print(f" āš ļø Validation failed: {result.get('error', 'Unknown error')}") print("\nāœ… Resource operations tests passed!") def test_format_conversion(): """Test format conversion""" print("\nšŸ”„ Testing Format Conversion...") from fhir_mcp_server import convert_between_formats import json patient_json = json.dumps( {"resourceType": "Patient", "id": "example", "gender": "male", "birthDate": "1990-01-01"} ) print("\n1ļøāƒ£ Testing JSON to XML conversion") result = convert_between_formats( resource_data=patient_json, input_format="json", output_format="xml" ) if result.get("success"): print(f" āœ… Converted {result['resource_type']} to XML") print(f" Output length: {len(result['output'])} chars") else: print(f" āš ļø Error: {result.get('error', 'Unknown error')}") print("\nāœ… Format conversion tests passed!") def test_utility_functions(): """Test utility functions""" print("\nšŸ› ļø Testing Utility Functions...") from fhir_mcp_server import get_fhir_version_info print("\n1ļøāƒ£ Testing get_fhir_version_info") result = get_fhir_version_info() if "error" not in result: print(f" Default version: {result.get('default_version', 'unknown')}") print(f" Supported versions: {result.get('supported_versions', [])}") print(f" Features: {len(result.get('features', []))} features") else: print(f" āš ļø Error: {result.get('error', 'Unknown error')}") print("\nāœ… Utility tests passed!") if __name__ == "__main__": print("=" * 60) print("FHIR Progressive Discovery MCP Server - Test Suite") print("=" * 60) try: test_discovery() test_resource_operations() test_format_conversion() test_utility_functions() print("\n" + "=" * 60) print("šŸŽ‰ ALL TESTS PASSED!") print("=" * 60) print("\nšŸ’” Next steps:") print(" 1. Run the server: python3 fhir_mcp_server.py") print(" 2. Configure your MCP client to connect") print(" 3. Start using progressive discovery!") except Exception as e: print(f"\nāŒ Test failed with error: {e}") import traceback traceback.print_exc()

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/CaseMark/FHIR-MCP'

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