Skip to main content
Glama
AbdessamadTzn

FastAPI Architect MCP

get_dependencies

Retrieves the complete Depends() dependency injection tree for a specified FastAPI handler to understand all nested dependencies.

Instructions

Get the full Depends() injection tree for a FastAPI handler.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYes
handlerYes

Implementation Reference

  • The core handler function for the 'get_dependencies' MCP tool. Parses a Python file using AST, finds all functions with 'Depends(...)' default arguments, builds a dependency map, and returns a recursive tree of dependencies for the requested handler. Detects circular dependencies.
    @mcp.tool()
    def get_dependencies(file: str, handler: str) -> dict:
        """Get the full Depends() injection tree for a FastAPI handler."""
        tree = _parse(file)
    
        dep_map: dict[str, list[str]] = {}
        for node in ast.walk(tree):
            if not isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
                continue
            deps = []
            for default in node.args.defaults:
                if (
                    isinstance(default, ast.Call)
                    and isinstance(default.func, ast.Name)
                    and default.func.id == "Depends"
                    and default.args
                    and isinstance(default.args[0], ast.Name)
                ):
                    deps.append(default.args[0].id)
            dep_map[node.name] = deps
    
        def build_tree(name: str, seen: set[str] | None = None) -> dict:
            seen = seen or set()
            if name in seen:
                return {"name": name, "dependencies": [], "circular": True}
            seen.add(name)
            return {
                "name": name,
                "dependencies": [build_tree(dep, seen.copy()) for dep in dep_map.get(name, [])],
            }
    
        if handler not in dep_map:
            return {"error": f"Handler '{handler}' not found in {file}"}
    
        return build_tree(handler)
  • The tool is registered as an MCP tool via the @mcp.tool() decorator on line 122, which is the FastMCP instance created on line 6.
    @mcp.tool()
  • Helper function '_parse' used by get_dependencies to parse a Python file into an AST module.
    def _parse(file: str) -> ast.Module:
        with open(file) as f:
            return ast.parse(f.read())
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so the description carries full burden. It states 'Get' which implies a read operation but doesn't disclose side effects, required permissions, or what 'full' entails. Minimal behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence with no wasted words, but it omits essential details. It is concise at the expense of completeness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple 2-parameter tool with no output schema, the description should clarify parameter values and expected output format. It does not explain what 'file' path refers to, 'handler' name format, or what the returned tree structure looks like.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Input schema has 0% description coverage. The description does not explain the meaning of 'file' and 'handler' parameters beyond their names. With no schema descriptions, the description fails to add necessary semantics.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Get', the resource 'full Depends() injection tree', and the context 'for a FastAPI handler'. It distinguishes this tool from sibling tools like find_references or go_to_definition, which serve different purposes.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for retrieving dependency injection trees in FastAPI handlers but lacks explicit guidance on when to use this tool versus alternatives, no exclusions or prerequisites mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/AbdessamadTzn/fastapi-architect-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server