chore: fix pre-commit hook failures and formatting

pull/1203/head
Carlos Barbero 8 months ago
parent 57433dc2e2
commit adb8661cb7

@ -2,4 +2,4 @@
line_length = 120
multi_line_output = 3
include_trailing_comma = True
known_third_party = graphviz,jinja2
known_third_party = graphviz,inspection,jinja2,mcp

@ -1,11 +1,13 @@
import pkgutil
import importlib
import inspect
import pkgutil
import sys
from collections import defaultdict
import diagrams
from diagrams import Node
def get_all_nodes():
"""
Dynamically inspects the diagrams package and returns a dictionary of all available Nodes.
@ -39,8 +41,8 @@ def get_all_nodes():
# Skip internal modules if any (base, etc are actually useful, but we focus on providers)
if short_provider in ['base', 'custom']:
# 'custom' and 'base' might be treated differently, but for now we scan them
pass
# 'custom' and 'base' might be treated differently, but for now we scan them
pass
try:
provider_module = importlib.import_module(provider_name)
@ -63,7 +65,8 @@ def get_all_nodes():
# or at least is defined in the diagrams package
if obj.__module__.startswith("diagrams"):
# Ensure the object actually belongs to this service (or a submodule of it)
# This prevents listing imported classes from other services (e.g. Trace in operations vs devtools)
# This prevents listing imported classes from other services (e.g. Trace
# in operations vs devtools)
if not obj.__module__.startswith(service_name):
continue

@ -1,14 +1,15 @@
import base64
import contextlib
import os
import sys
import tempfile
import contextlib
import base64
from pathlib import Path
from mcp.server.fastmcp import FastMCP
from diagrams import Diagram, Cluster, Edge, Node
# Import our helper
from inspection import get_all_nodes
from mcp.server.fastmcp import FastMCP
from diagrams import Cluster, Diagram, Edge, Node
# Initialize FastMCP
mcp = FastMCP("diagrams-mcp")
@ -18,6 +19,7 @@ print("Loading diagram nodes...", file=sys.stderr)
ALL_ICONS, NODE_REGISTRY = get_all_nodes()
print(f"Loaded {len(NODE_REGISTRY)} nodes.", file=sys.stderr)
@mcp.tool()
def list_icons(provider_filter: str = None, service_filter: str = None):
"""
@ -41,10 +43,14 @@ def list_icons(provider_filter: str = None, service_filter: str = None):
return provider_data
if service_filter not in provider_data:
return {"error": f"Service '{service_filter}' not found in '{provider_filter}'. Available: {list(provider_data.keys())}"}
return {
"error": f"Service '{service_filter}' not found in '{provider_filter}'. Available: {
list(
provider_data.keys())}"}
return {service_filter: provider_data[service_filter]}
@mcp.tool()
def get_diagram_examples(diagram_type: str = "all"):
"""
@ -92,6 +98,7 @@ with Diagram("Custom", show=False):
return {diagram_type: examples.get(diagram_type, "No example found for this type.")}
@mcp.tool()
def generate_diagram(code: str, filename: str = None, timeout: int = 90):
"""
@ -134,7 +141,9 @@ def generate_diagram(code: str, filename: str = None, timeout: int = 90):
generated_files = list(Path(".").glob("*.png"))
if not generated_files:
return {"status": "error", "message": "No diagram image was generated. Did you call with Diagram(..., show=False)?"}
return {
"status": "error",
"message": "No diagram image was generated. Did you call with Diagram(..., show=False)?"}
# Use the most recently modified file or the first one
generated_files.sort(key=lambda f: f.stat().st_mtime, reverse=True)
@ -172,5 +181,6 @@ def generate_diagram(code: str, filename: str = None, timeout: int = 90):
finally:
os.chdir(original_cwd)
if __name__ == "__main__":
mcp.run()

Loading…
Cancel
Save