fetch_example
Retrieve static example diagrams with content, learning objectives, and patterns to understand Ilograph diagram structure and usage.
Instructions
Retrieves a static example diagram with its content and learning context.
Args:
example_name: The filename of the example to fetch (e.g., 'serverless-on-aws.ilograph').
Returns:
A dictionary containing the example's content, metadata, learning objectives, and patterns.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| example_name | Yes |
Implementation Reference
- The main handler function `fetch_example_tool` that executes the tool logic: retrieves example metadata from the database, reads the diagram file content, handles missing files or errors, and returns the content with metadata.async def fetch_example_tool(example_name: str, ctx: Context) -> Dict[str, Any]: """ Retrieves a static example diagram with its content and learning context. Args: example_name: The filename of the example to fetch (e.g., 'serverless-on-aws.ilograph'). Returns: A dictionary containing the example's content, metadata, learning objectives, and patterns. """ await ctx.info(f"Attempting to fetch example: {example_name}") metadata = EXAMPLES_DATABASE.get(example_name) if not metadata: await ctx.error(f"Example '{example_name}' not found.") available = ", ".join(EXAMPLES_DATABASE.keys()) return { "error": "not_found", "message": f"Example '{example_name}' not found. Use the 'list_examples' tool to see available examples.", "available_examples": available.split(", "), } file_path = metadata.file_path if not file_path.is_file(): await ctx.error(f"Example file not found on disk: {file_path}") return { "error": "internal_error", "message": "The example file could not be found on the server, even though it is listed in the database.", } try: content = file_path.read_text(encoding="utf-8") await ctx.info(f"Successfully read example file: {example_name}") response = metadata.model_dump() response["content"] = content return response except Exception as e: await ctx.error(f"Failed to read example file '{example_name}': {e}") logger.exception(f"Error reading example file {file_path}") return { "error": "internal_error", "message": f"An unexpected error occurred while reading the example file: {e}", }
- src/ilograph_mcp/tools/register_example_tools.py:139-146 (registration)The `@mcp.tool` decorator registers the `fetch_example` tool on the FastMCP server instance, specifying its name, title, read-only hint, and description.@mcp.tool( name="fetch_example", annotations={ "title": "Get Example Diagram", "readOnlyHint": True, "description": "Retrieves a specific Ilograph example diagram with its content and rich metadata.", }, )
- Pydantic `BaseModel` `ExampleMetadata` defines the schema/structure for example metadata, which is included in the tool's response along with the diagram content.class ExampleMetadata(BaseModel): """Defines the metadata structure for an Ilograph example.""" name: str category: Literal["beginner", "intermediate", "advanced"] description: str learning_objectives: List[str] = Field(default_factory=list) patterns_demonstrated: List[str] = Field(default_factory=list) @property def file_path(self) -> Path: """Returns the full path to the example file.""" return EXAMPLES_DIR / self.name
- `EXAMPLES_DATABASE` is the in-memory manifest providing metadata for all available examples, used by the handler to lookup and validate requested examples.EXAMPLES_DATABASE: Dict[str, ExampleMetadata] = { "serverless-on-aws.ilograph": ExampleMetadata( name="serverless-on-aws.ilograph", category="intermediate", description="A comprehensive diagram of a serverless web application architecture on AWS, using services like Lambda, API Gateway, S3, and DynamoDB.", learning_objectives=[ "Understand how to model serverless architectures.", "Learn the relationships between API Gateway, Lambda, and DynamoDB.", "See how to represent S3 buckets for static content hosting.", ], patterns_demonstrated=[ "Serverless", "AWS", "API Gateway", "Lambda", "DynamoDB", "Microservices", ], ), "stack-overflow-architecture-2016.ilograph": ExampleMetadata( name="stack-overflow-architecture-2016.ilograph", category="advanced", description="The 2016 architecture of Stack Overflow, showcasing a high-traffic, resilient web application with a mix of .NET technologies, Redis, and SQL Server.", learning_objectives=[ "Analyze a real-world, high-scale web architecture.", "Understand patterns for redundancy, caching, and load balancing.", "Learn to model complex interactions between various services and data stores.", ], patterns_demonstrated=[ "Web Architecture", "High Availability", "Caching", "Load Balancing", "SQL", "Redis", ], ), "aws-distributed-load-testing.ilograph": ExampleMetadata( name="aws-distributed-load-testing.ilograph", category="advanced", description="A sophisticated AWS architecture for a distributed load testing solution, featuring containerized tasks, event-driven flows, and detailed networking.", learning_objectives=[ "Model complex, event-driven systems on AWS.", "Understand how to represent container orchestration with Fargate.", "Learn advanced networking concepts like VPCs, subnets, and security groups.", ], patterns_demonstrated=[ "Cloud Architecture", "Distributed Systems", "Event-Driven", "AWS Fargate", "Networking", "Scalability", ], ), }
- src/ilograph_mcp/server.py:67-68 (registration)In the main server setup, `register_example_tools(mcp)` is called to register the example tools group, which includes the `fetch_example` tool.register_example_tools(mcp) logger.info("Registered example_tools")