Skip to content

Commit ef30f79

Browse files
committed
add logging to resources and tools
1 parent a48aa87 commit ef30f79

File tree

1 file changed

+19
-0
lines changed
  • servers/mcp-neo4j-data-modeling/src/mcp_neo4j_data_modeling

1 file changed

+19
-0
lines changed

servers/mcp-neo4j-data-modeling/src/mcp_neo4j_data_modeling/server.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,61 +20,77 @@ def create_mcp_server() -> FastMCP:
2020
@mcp.resource("resource://init")
2121
def init() -> DataModel:
2222
"""Create an empty data model."""
23+
logger.info("Creating an empty data model.")
2324
return DataModel(nodes=[], relationships=[])
2425

2526
@mcp.resource("resource://schema/node")
2627
def node_schema() -> dict[str, Any]:
2728
"""Get the schema for a node."""
29+
logger.info("Getting the schema for a node.")
2830
return Node.model_json_schema()
2931

3032
@mcp.resource("resource://schema/relationship")
3133
def relationship_schema() -> dict[str, Any]:
3234
"""Get the schema for a relationship."""
35+
logger.info("Getting the schema for a relationship.")
3336
return Relationship.model_json_schema()
3437

3538
@mcp.resource("resource://schema/property")
3639
def property_schema() -> dict[str, Any]:
3740
"""Get the schema for a property."""
41+
logger.info("Getting the schema for a property.")
3842
return Property.model_json_schema()
3943

4044
@mcp.resource("resource://schema/data_model")
4145
def data_model_schema() -> dict[str, Any]:
4246
"""Get the schema for a data model."""
47+
logger.info("Getting the schema for a data model.")
4348
return DataModel.model_json_schema()
4449

4550
@mcp.tool()
4651
def validate_node(node: Node) -> bool:
4752
"Validate a single node. Returns True if the node is valid, otherwise raises a ValueError."
53+
logger.info("Validating a single node.")
4854
try:
4955
Node.model_validate(node, strict=True)
5056
except ValidationError as e:
57+
logger.error(f"Validation error: {e}")
5158
raise ValueError(f"Validation error: {e}")
59+
logger.info("Node validated successfully.")
5260
return True
5361

5462
@mcp.tool()
5563
def validate_relationship(relationship: Relationship) -> bool:
5664
"Validate a single relationship. Returns True if the relationship is valid, otherwise raises a ValueError."
65+
logger.info("Validating a single relationship.")
5766
try:
5867
Relationship.model_validate(relationship, strict=True)
5968
except ValidationError as e:
69+
logger.error(f"Validation error: {e}")
6070
raise ValueError(f"Validation error: {e}")
71+
logger.info("Relationship validated successfully.")
6172
return True
6273

6374
@mcp.tool()
6475
def validate_data_model(data_model: DataModel) -> bool:
6576
"Validate the entire data model. Returns True if the data model is valid, otherwise raises a ValueError."
77+
logger.info("Validating the entire data model.")
6678
try:
6779
DataModel.model_validate(data_model, strict=True)
6880
except ValidationError as e:
81+
logger.error(f"Validation error: {e}")
6982
raise ValueError(f"Validation error: {e}")
83+
logger.info("Data model validated successfully.")
7084
return True
7185

7286
@mcp.tool()
7387
def visualize_data_model(data_model: DataModel) -> None:
7488
"Open an interactive graph visualization in the default web browser."
89+
logger.info("Validating the data model.")
7590
try:
7691
dm_validated = DataModel.model_validate(data_model, strict=True)
7792
except ValidationError as e:
93+
logger.error(f"Validation error: {e}")
7894
raise ValueError(f"Validation error: {e}")
7995

8096
def open_html_in_browser(html_content, filename="temp.html"):
@@ -91,16 +107,19 @@ def open_html_in_browser(html_content, filename="temp.html"):
91107
file_url = 'file://' + os.path.realpath(filename)
92108
webbrowser.open_new_tab(file_url)
93109

110+
logger.info("Opening an interactive graph visualization in the default web browser.")
94111
open_html_in_browser(dm_validated.to_nvl().render().data)
95112

96113
@mcp.tool()
97114
def load_from_arrows_json(arrows_data_model_dict: dict[str, Any]) -> DataModel:
98115
"Load a data model from the Arrows web application format. Returns a data model as a JSON string."
116+
logger.info("Loading a data model from the Arrows web application format.")
99117
return DataModel.from_arrows(arrows_data_model_dict)
100118

101119
@mcp.tool()
102120
def export_to_arrows_json(data_model: DataModel) -> str:
103121
"Export the data model to the Arrows web application format. Returns a JSON string."
122+
logger.info("Exporting the data model to the Arrows web application format.")
104123
return data_model.to_arrows_json_str()
105124

106125
return mcp

0 commit comments

Comments
 (0)