Skip to content

mcp_core.core

Internals of the diagram pipeline. diagram_service.generate_from_request is the single entry point used by every tool.

mcp_core.core.diagram_service

mcp_core.core.diagram_service

Diagram generation entry for MCP tools: validate once, then render.

DiagramRequest dataclass

DiagramRequest(
    diagram_type: str,
    code: str,
    output_dir: Optional[str] = None,
    output_format: str = "svg",
    theme: Optional[str] = None,
    scale: float = 1.0,
)

Tool-level inputs for diagram generation.

generate_from_request

generate_from_request(
    req: DiagramRequest,
) -> Dict[str, Any]

Validate with GenerateUMLInput, ensure diagram_type is configured, then generate_diagram.

mcp_core.core.diagram_rendering

mcp_core.core.diagram_rendering

Kroki-first diagram rendering pipeline: try Kroki, then optional fallbacks by backend.

Synchronous steps with explicit functions; fallbacks are adapters keyed by backend type.

DiagramRenderContext dataclass

DiagramRenderContext(
    diagram_type: str,
    backend_type: str,
    prepared_code: str,
    output_format: str,
    output_dir: Optional[str],
    theme: Optional[str],
    scale: float,
)

Inputs needed after config resolution and code preparation.

prepare_diagram_code

prepare_diagram_code(
    code: str, backend_type: str, theme: Optional[str]
) -> str

Strip and wrap PlantUML when needed; TikZ snippets get standalone wrap; else strip only.

try_kroki_render

try_kroki_render(
    ctx: DiagramRenderContext, kroki_client: Any = None
) -> Tuple[Optional[Dict[str, Any]], Optional[Exception]]

Attempt Kroki render. Returns (result_dict, None) on success or (None, exception).

run_fallback_if_needed

run_fallback_if_needed(
    ctx: DiagramRenderContext, kroki_error: Exception
) -> Dict[str, Any]

Run backend-specific fallback after Kroki failure, or return aggregated error dict.

On error, the returned dict includes attempts and fallback_used. On success, returns the same shape as Kroki (no attempts; added by pipeline).

run_diagram_pipeline

run_diagram_pipeline(
    ctx: DiagramRenderContext, kroki_client: Any = None
) -> Dict[str, Any]

Kroki first, then optional fallbacks; returns the standard result dict.

mcp_core.core.diagram_validation

mcp_core.core.diagram_validation

Local validation for diagram code before render (no network calls).

Reuses GenerateUMLInput for type/format/length rules, then applies light structural checks.

validate_uml_inputs

validate_uml_inputs(
    diagram_type: str,
    code: str,
    output_format: str = "svg",
    strict: bool = False,
) -> Dict[str, Any]

Validate diagram inputs without calling Kroki or other renderers.

Returns a dict with valid, errors, suggestions, backend, diagram_type, and prepared_code (when schema validation passed).

mcp_core.core.diagram_catalog

mcp_core.core.diagram_catalog

Shared diagram type metadata for MCP resources and tools (single source of truth).

get_diagram_types_dict

get_diagram_types_dict() -> Dict[str, Any]

Return the same structure as the uml://types JSON object (before stringification).

mcp_core.core.config

mcp_core.core.config

Configuration settings for MCP server.

DiagramType

Bases: BaseModel

Configuration for a diagram type.

MCPSettings

Bases: BaseModel

Configuration settings for MCP server.

output_path property

output_path: Path

Output directory as a Path for file operations.