Skip to content

Commit e4e0f83

Browse files
aperepela-s-g93
andauthored
Enhance MCP tool schemas and documentation for better LLM integration (#143)
* Enhance MCP tool schemas and documentation for better LLM integration - Add comprehensive Field descriptions to all Pydantic models (Entity, Relation, ObservationAddition, ObservationDeletion) - Include detailed docstrings with JSON examples for all 9 MCP tools - Fix return type annotations to match actual ToolResult implementation - Add validation constraints and usage examples - Improve parameter descriptions with specific guidance on data formats - Add warnings for destructive operations - Create CLAUDE.md with development guidance This improves LLM client understanding of expected input schemas and tool usage patterns. * Addressed review feedback. * Update CHANGELOG.md --------- Co-authored-by: alex <[email protected]>
1 parent 472da1a commit e4e0f83

File tree

3 files changed

+290
-32
lines changed

3 files changed

+290
-32
lines changed

servers/mcp-neo4j-memory/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Fixed
44

55
### Changed
6+
* Updated tool docstrings to better describe their function, inputs and outputs
67

78
### Added
89
* Add namespacing support for multi-tenant deployments with `--namespace` CLI argument and `NEO4J_NAMESPACE` environment variable

servers/mcp-neo4j-memory/src/mcp_neo4j_memory/neo4j_memory.py

Lines changed: 91 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Any, Dict, List
33

44
from neo4j import AsyncDriver, RoutingControl
5-
from pydantic import BaseModel
5+
from pydantic import BaseModel, Field
66

77

88
# Set up logging
@@ -11,26 +11,104 @@
1111

1212
# Models for our knowledge graph
1313
class Entity(BaseModel):
14-
name: str
15-
type: str
16-
observations: List[str]
14+
"""Represents a memory entity in the knowledge graph.
15+
16+
Example:
17+
{
18+
"name": "John Smith",
19+
"type": "person",
20+
"observations": ["Works at Neo4j", "Lives in San Francisco", "Expert in graph databases"]
21+
}
22+
"""
23+
name: str = Field(
24+
description="Unique identifier/name for the entity. Should be descriptive and specific.",
25+
min_length=1,
26+
examples=["John Smith", "Neo4j Inc", "San Francisco"]
27+
)
28+
type: str = Field(
29+
description="Category or classification of the entity. Common types: 'person', 'company', 'location', 'concept', 'event'",
30+
min_length=1,
31+
examples=["person", "company", "location", "concept", "event"]
32+
)
33+
observations: List[str] = Field(
34+
description="List of facts, observations, or notes about this entity. Each observation should be a complete, standalone fact.",
35+
examples=[["Works at Neo4j", "Lives in San Francisco"], ["Headquartered in Sweden", "Graph database company"]]
36+
)
1737

1838
class Relation(BaseModel):
19-
source: str
20-
target: str
21-
relationType: str
39+
"""Represents a relationship between two entities in the knowledge graph.
40+
41+
Example:
42+
{
43+
"source": "John Smith",
44+
"target": "Neo4j Inc",
45+
"relationType": "WORKS_AT"
46+
}
47+
"""
48+
source: str = Field(
49+
description="Name of the source entity (must match an existing entity name exactly)",
50+
min_length=1,
51+
examples=["John Smith", "Neo4j Inc"]
52+
)
53+
target: str = Field(
54+
description="Name of the target entity (must match an existing entity name exactly)",
55+
min_length=1,
56+
examples=["Neo4j Inc", "San Francisco"]
57+
)
58+
relationType: str = Field(
59+
description="Type of relationship between source and target. Use descriptive, uppercase names with underscores.",
60+
min_length=1,
61+
examples=["WORKS_AT", "LIVES_IN", "MANAGES", "COLLABORATES_WITH", "LOCATED_IN"]
62+
)
2263

2364
class KnowledgeGraph(BaseModel):
24-
entities: List[Entity]
25-
relations: List[Relation]
65+
"""Complete knowledge graph containing entities and their relationships."""
66+
entities: List[Entity] = Field(
67+
description="List of all entities in the knowledge graph",
68+
default=[]
69+
)
70+
relations: List[Relation] = Field(
71+
description="List of all relationships between entities",
72+
default=[]
73+
)
2674

2775
class ObservationAddition(BaseModel):
28-
entityName: str
29-
observations: List[str]
76+
"""Request to add new observations to an existing entity.
77+
78+
Example:
79+
{
80+
"entityName": "John Smith",
81+
"observations": ["Recently promoted to Senior Engineer", "Speaks fluent German"]
82+
}
83+
"""
84+
entityName: str = Field(
85+
description="Exact name of the existing entity to add observations to",
86+
min_length=1,
87+
examples=["John Smith", "Neo4j Inc"]
88+
)
89+
observations: List[str] = Field(
90+
description="New observations/facts to add to the entity. Each should be unique and informative.",
91+
min_length=1
92+
)
3093

3194
class ObservationDeletion(BaseModel):
32-
entityName: str
33-
observations: List[str]
95+
"""Request to delete specific observations from an existing entity.
96+
97+
Example:
98+
{
99+
"entityName": "John Smith",
100+
"observations": ["Old job title", "Outdated contact info"]
101+
}
102+
"""
103+
entityName: str = Field(
104+
description="Exact name of the existing entity to remove observations from",
105+
min_length=1,
106+
examples=["John Smith", "Neo4j Inc"]
107+
)
108+
observations: List[str] = Field(
109+
description="Exact observation texts to delete from the entity (must match existing observations exactly)",
110+
min_length=1
111+
)
34112

35113
class Neo4jMemory:
36114
def __init__(self, neo4j_driver: AsyncDriver):

0 commit comments

Comments
 (0)