|
| 1 | +import json |
1 | 2 | import logging |
2 | 3 | from typing import Any, Literal |
3 | 4 |
|
|
10 | 11 | Property, |
11 | 12 | Relationship, |
12 | 13 | ) |
13 | | -from .static import DATA_INGEST_PROCESS |
| 14 | +from .models import ExampleDataModelResponse |
| 15 | +from .static import ( |
| 16 | + DATA_INGEST_PROCESS, |
| 17 | + PATIENT_JOURNEY_MODEL, |
| 18 | + SUPPLY_CHAIN_MODEL, |
| 19 | + SOFTWARE_DEPENDENCY_MODEL, |
| 20 | + OIL_GAS_MONITORING_MODEL, |
| 21 | + CUSTOMER_360_MODEL, |
| 22 | + FRAUD_AML_MODEL, |
| 23 | + HEALTH_INSURANCE_FRAUD_MODEL, |
| 24 | +) |
14 | 25 |
|
15 | 26 | logger = logging.getLogger("mcp_neo4j_data_modeling") |
16 | 27 |
|
@@ -52,6 +63,48 @@ def neo4j_data_ingest_process() -> str: |
52 | 63 | logger.info("Getting the process for ingesting data into a Neo4j database.") |
53 | 64 | return DATA_INGEST_PROCESS |
54 | 65 |
|
| 66 | + @mcp.resource("resource://examples/patient_journey_model") |
| 67 | + def example_patient_journey_model() -> str: |
| 68 | + """Get a real-world Patient Journey healthcare data model in JSON format.""" |
| 69 | + logger.info("Getting the Patient Journey healthcare data model.") |
| 70 | + return json.dumps(PATIENT_JOURNEY_MODEL, indent=2) |
| 71 | + |
| 72 | + @mcp.resource("resource://examples/supply_chain_model") |
| 73 | + def example_supply_chain_model() -> str: |
| 74 | + """Get a real-world Supply Chain data model in JSON format.""" |
| 75 | + logger.info("Getting the Supply Chain data model.") |
| 76 | + return json.dumps(SUPPLY_CHAIN_MODEL, indent=2) |
| 77 | + |
| 78 | + @mcp.resource("resource://examples/software_dependency_model") |
| 79 | + def example_software_dependency_model() -> str: |
| 80 | + """Get a real-world Software Dependency Graph data model in JSON format.""" |
| 81 | + logger.info("Getting the Software Dependency Graph data model.") |
| 82 | + return json.dumps(SOFTWARE_DEPENDENCY_MODEL, indent=2) |
| 83 | + |
| 84 | + @mcp.resource("resource://examples/oil_gas_monitoring_model") |
| 85 | + def example_oil_gas_monitoring_model() -> str: |
| 86 | + """Get a real-world Oil and Gas Equipment Monitoring data model in JSON format.""" |
| 87 | + logger.info("Getting the Oil and Gas Equipment Monitoring data model.") |
| 88 | + return json.dumps(OIL_GAS_MONITORING_MODEL, indent=2) |
| 89 | + |
| 90 | + @mcp.resource("resource://examples/customer_360_model") |
| 91 | + def example_customer_360_model() -> str: |
| 92 | + """Get a real-world Customer 360 data model in JSON format.""" |
| 93 | + logger.info("Getting the Customer 360 data model.") |
| 94 | + return json.dumps(CUSTOMER_360_MODEL, indent=2) |
| 95 | + |
| 96 | + @mcp.resource("resource://examples/fraud_aml_model") |
| 97 | + def example_fraud_aml_model() -> str: |
| 98 | + """Get a real-world Fraud & AML data model in JSON format.""" |
| 99 | + logger.info("Getting the Fraud & AML data model.") |
| 100 | + return json.dumps(FRAUD_AML_MODEL, indent=2) |
| 101 | + |
| 102 | + @mcp.resource("resource://examples/health_insurance_fraud_model") |
| 103 | + def example_health_insurance_fraud_model() -> str: |
| 104 | + """Get a real-world Health Insurance Fraud Detection data model in JSON format.""" |
| 105 | + logger.info("Getting the Health Insurance Fraud Detection data model.") |
| 106 | + return json.dumps(HEALTH_INSURANCE_FRAUD_MODEL, indent=2) |
| 107 | + |
55 | 108 | @mcp.tool() |
56 | 109 | def validate_node( |
57 | 110 | node: Node, return_validated: bool = False |
@@ -180,6 +233,96 @@ def get_constraints_cypher_queries(data_model: DataModel) -> list[str]: |
180 | 233 | ) |
181 | 234 | return data_model.get_cypher_constraints_query() |
182 | 235 |
|
| 236 | + @mcp.tool() |
| 237 | + def get_example_data_model( |
| 238 | + example_name: str = Field( |
| 239 | + ..., |
| 240 | + description="Name of the example to load: 'patient_journey', 'supply_chain', 'software_dependency', 'oil_gas_monitoring', 'customer_360', 'fraud_aml', or 'health_insurance_fraud'", |
| 241 | + ), |
| 242 | + ) -> ExampleDataModelResponse: |
| 243 | + """Get an example graph data model from the available templates. Returns a DataModel object and the Mermaid visualization configuration for the example graph data model.""" |
| 244 | + logger.info(f"Getting example data model: {example_name}") |
| 245 | + |
| 246 | + example_map = { |
| 247 | + "patient_journey": PATIENT_JOURNEY_MODEL, |
| 248 | + "supply_chain": SUPPLY_CHAIN_MODEL, |
| 249 | + "software_dependency": SOFTWARE_DEPENDENCY_MODEL, |
| 250 | + "oil_gas_monitoring": OIL_GAS_MONITORING_MODEL, |
| 251 | + "customer_360": CUSTOMER_360_MODEL, |
| 252 | + "fraud_aml": FRAUD_AML_MODEL, |
| 253 | + "health_insurance_fraud": HEALTH_INSURANCE_FRAUD_MODEL, |
| 254 | + } |
| 255 | + |
| 256 | + if example_name not in example_map: |
| 257 | + raise ValueError( |
| 258 | + f"Unknown example: {example_name}. Available examples: {list(example_map.keys())}" |
| 259 | + ) |
| 260 | + |
| 261 | + example_data = example_map[example_name] |
| 262 | + |
| 263 | + validated_data_model = DataModel.model_validate(example_data) |
| 264 | + |
| 265 | + return ExampleDataModelResponse( |
| 266 | + data_model=validated_data_model, |
| 267 | + mermaid_config=validated_data_model.get_mermaid_config_str(), |
| 268 | + ) |
| 269 | + |
| 270 | + @mcp.tool() |
| 271 | + def list_example_data_models() -> dict[str, Any]: |
| 272 | + """List all available example data models with descriptions. Returns a dictionary with example names and their descriptions.""" |
| 273 | + logger.info("Listing available example data models.") |
| 274 | + |
| 275 | + examples = { |
| 276 | + "patient_journey": { |
| 277 | + "name": "Patient Journey", |
| 278 | + "description": "Healthcare data model for tracking patient encounters, conditions, medications, and care plans", |
| 279 | + "nodes": len(PATIENT_JOURNEY_MODEL["nodes"]), |
| 280 | + "relationships": len(PATIENT_JOURNEY_MODEL["relationships"]), |
| 281 | + }, |
| 282 | + "supply_chain": { |
| 283 | + "name": "Supply Chain", |
| 284 | + "description": "Supply chain management data model for tracking products, orders, inventory, and locations", |
| 285 | + "nodes": len(SUPPLY_CHAIN_MODEL["nodes"]), |
| 286 | + "relationships": len(SUPPLY_CHAIN_MODEL["relationships"]), |
| 287 | + }, |
| 288 | + "software_dependency": { |
| 289 | + "name": "Software Dependency Graph", |
| 290 | + "description": "Software dependency tracking with security vulnerabilities, commits, and contributor analysis", |
| 291 | + "nodes": len(SOFTWARE_DEPENDENCY_MODEL["nodes"]), |
| 292 | + "relationships": len(SOFTWARE_DEPENDENCY_MODEL["relationships"]), |
| 293 | + }, |
| 294 | + "oil_gas_monitoring": { |
| 295 | + "name": "Oil & Gas Equipment Monitoring", |
| 296 | + "description": "Industrial monitoring data model for oil and gas equipment, sensors, alerts, and maintenance", |
| 297 | + "nodes": len(OIL_GAS_MONITORING_MODEL["nodes"]), |
| 298 | + "relationships": len(OIL_GAS_MONITORING_MODEL["relationships"]), |
| 299 | + }, |
| 300 | + "customer_360": { |
| 301 | + "name": "Customer 360", |
| 302 | + "description": "Customer relationship management data model for accounts, contacts, orders, tickets, and surveys", |
| 303 | + "nodes": len(CUSTOMER_360_MODEL["nodes"]), |
| 304 | + "relationships": len(CUSTOMER_360_MODEL["relationships"]), |
| 305 | + }, |
| 306 | + "fraud_aml": { |
| 307 | + "name": "Fraud & AML", |
| 308 | + "description": "Financial fraud detection and anti-money laundering data model for customers, transactions, alerts, and compliance", |
| 309 | + "nodes": len(FRAUD_AML_MODEL["nodes"]), |
| 310 | + "relationships": len(FRAUD_AML_MODEL["relationships"]), |
| 311 | + }, |
| 312 | + "health_insurance_fraud": { |
| 313 | + "name": "Health Insurance Fraud Detection", |
| 314 | + "description": "Healthcare fraud detection data model for tracking investigations, prescriptions, executions, and beneficiary relationships", |
| 315 | + "nodes": len(HEALTH_INSURANCE_FRAUD_MODEL["nodes"]), |
| 316 | + "relationships": len(HEALTH_INSURANCE_FRAUD_MODEL["relationships"]), |
| 317 | + }, |
| 318 | + } |
| 319 | + |
| 320 | + return { |
| 321 | + "available_examples": examples, |
| 322 | + "total_examples": len(examples), |
| 323 | + "usage": "Use the get_example_data_model tool with any of the example names above to get a specific data model", |
| 324 | + } |
| 325 | + |
183 | 326 | return mcp |
184 | 327 |
|
185 | 328 |
|
|
0 commit comments