API Reference¶
This section provides detailed documentation for all enrichmcp components.
Core Components¶
EnrichMCP¶
The main application class that manages entities, relationships, and resources.
EnrichModel¶
Base class for all entities, extending Pydantic's BaseModel with relationship support.
from enrichmcp import EnrichModel
from pydantic import Field
@app.entity
class User(EnrichModel):
id: int = Field(description="User ID")
name: str = Field(description="Username")
Relationship¶
Defines connections between entities with automatic resolver registration.
from enrichmcp import Relationship
class User(EnrichModel):
orders: list["Order"] = Relationship(description="User's orders")
EnrichContext¶
Placeholder for future context functionality (currently minimal implementation).
Errors¶
Currently uses standard Python exceptions and Pydantic validation.
Key Concepts¶
Entity Registration¶
Entities must be registered with the app using the @app.entity
decorator:
@app.entity
class Product(EnrichModel):
"""Product in our catalog."""
id: int = Field(description="Product ID")
name: str = Field(description="Product name")
Relationship Resolution¶
Every relationship needs a resolver function:
@User.orders.resolver
async def get_user_orders(user_id: int) -> list["Order"]:
"""Fetch orders for a user."""
return fetch_orders_for_user(user_id)
Resource Creation¶
Resources are the entry points for AI agents:
@app.resource
async def list_users() -> list[User]:
"""List all users in the system."""
return fetch_all_users()
Type Safety¶
enrichmcp enforces strict type checking:
- Entity Validation: All fields must have descriptions
- Resolver Validation: Return types must match relationship types exactly
- Runtime Validation: Pydantic validates all data at runtime
Schema Introspection¶
AI agents can explore your data model using the built-in explore_data_model()
resource:
# Automatically available to AI agents
result = await explore_data_model()
# Returns comprehensive schema information
Best Practices¶
- Always include descriptions - Every entity, field, and relationship needs a description
- Use meaningful names - Clear, descriptive names help AI agents understand your model
- Keep resolvers simple - Each resolver should do one thing well
- Handle missing data gracefully - Return sensible defaults rather than errors when possible