mcp_core.tools¶
The MCP tool surface: each function decorated with @mcp_tool is registered with the FastMCP server at startup. Pydantic schemas in schemas.py validate inputs before any rendering happens.
mcp_core.tools.diagram_tools¶
mcp_core.tools.diagram_tools ¶
MCP tools for diagram generation using the decorator pattern
list_diagram_types ¶
Return the uml://types payload as a structured dict.
Keys are diagram type names (e.g. class, mermaid, c4plantuml); each value has backend, description, and formats.
generate_uml_batch ¶
generate_uml_batch(
items: List[Dict[str, Any]],
output_dir: Optional[str] = None,
) -> Dict[str, Any]
Render multiple diagrams; failures are collected per index without stopping the batch.
generate_uml ¶
generate_uml(
diagram_type: str,
code: str,
output_dir: Optional[str] = None,
output_format: str = "svg",
theme: Optional[str] = None,
scale: float = 1.0,
) -> Dict[str, Any]
Generate a diagram using the specified diagram type.
Use when you need a diagram of any supported type. For complex diagrams the default prompt guides planning first (type, elements, relationships), then you call this tool with the final code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diagram_type | str | Type of diagram (class, sequence, activity, mermaid, d2, etc.) | required |
code | str | Diagram code in the syntax for the chosen type | required |
output_dir | Optional[str] | Directory to save the image. Omit or None for URL, playground, and content_base64 only (no file write; use in serverless / read-only). | None |
output_format | str | svg, png, pdf, jpeg, txt, or base64 (default: svg). See uml://formats per type. | 'svg' |
theme | Optional[str] | PlantUML theme for UML diagrams (e.g. cerulean) | None |
scale | float | Scale factor for SVG only (default 1.0, min 0.1). Ignored for other formats. | 1.0 |
Returns:
| Type | Description |
|---|---|
Dict[str, Any] | Dict with code, url, playground; local_path when output_dir set; content_base64 when not saving; or error. |
validate_uml ¶
validate_uml(
diagram_type: str,
code: str,
output_format: str = "svg",
strict: bool = False,
) -> Dict[str, Any]
Check inputs and light structure without rendering.
Use to catch unsupported types, bad output_format for the type, empty code, or obvious PlantUML/Mermaid/D2 issues before calling generate_uml.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diagram_type | str | Same as generate_uml (see uml://types). | required |
code | str | Diagram source text. | required |
output_format | str | Intended output format (default svg); must be allowed for the type. | 'svg' |
strict | bool | When True, apply extra Mermaid/D2 checks (no extra PlantUML rules). | False |
Returns:
| Type | Description |
|---|---|
Dict[str, Any] | Dict with valid (bool), errors, suggestions, backend, diagram_type, prepared_code, |
Dict[str, Any] | optional corrected_code when only trivial wrapping changed the text, and strict. |
register_diagram_tools ¶
Register all diagram generation tools with the MCP server
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server | Any | The MCP server instance | required |
Returns:
| Type | Description |
|---|---|
List[str] | List of registered tool names |
get_tool_info ¶
Get information about all registered tools
Returns:
| Type | Description |
|---|---|
Dict[str, Dict[str, Any]] | Dictionary mapping tool names to their information |
mcp_core.tools.schemas¶
mcp_core.tools.schemas ¶
Pydantic schemas for MCP tool inputs and outputs.
mcp_core.tools.tool_decorator¶
mcp_core.tools.tool_decorator ¶
Decorator system for MCP tools
mcp_tool ¶
mcp_tool(
name: Optional[str] = None,
description: Optional[str] = None,
category: str = "default",
required_params: Optional[List[str]] = None,
example: Optional[str] = None,
annotations: Optional[Dict[str, Any]] = None,
) -> Callable[[F], F]
Decorator for registering a function as an MCP tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | Optional[str] | Tool name (defaults to function name if not provided) | None |
description | Optional[str] | Tool description (defaults to function docstring if not provided) | None |
category | str | Tool category for organization | 'default' |
required_params | Optional[List[str]] | List of required parameter names | None |
example | Optional[str] | Example usage of the tool | None |
annotations | Optional[Dict[str, Any]] | MCP tool hints (readOnlyHint, destructiveHint, idempotentHint, openWorldHint) | None |
Returns:
| Type | Description |
|---|---|
Callable[[F], F] | Decorated function |
Example
@mcp_tool(description="Generate a class diagram", category="uml") def generate_class_diagram(code: str, output_dir: str) -> Dict[str, Any]: # Implementation return {"code": code, "url": "..."}
register_tools_with_server ¶
Register all decorated tools with the MCP server
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server | Any | The MCP server instance | required |
Returns:
| Type | Description |
|---|---|
List[str] | List of registered tool names |
get_tool_registry ¶
Get the registry of all tools registered with the decorator
Returns:
| Type | Description |
|---|---|
Dict[str, Dict[str, Any]] | Dictionary of tool metadata |
get_tool_categories ¶
Get tools organized by category
Returns:
| Type | Description |
|---|---|
Dict[str, List[str]] | Dictionary mapping categories to tool names |