Skip to main content
Glama
AbdessamadTzn

FastAPI Architect MCP

find_model_usages

Locate every occurrence of a Pydantic model used as a type annotation in your FastAPI project. Trace model dependencies across files.

Instructions

Find all places a Pydantic model is used as a type annotation across the project.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYes
modelYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The find_model_usages tool handler: parses all Python files in the project, walks the AST looking for AnnAssign nodes (type annotations) and function argument annotations that match the given model name, returning a list of locations where the model is used as a type annotation.
    @mcp.tool()
    def find_model_usages(file: str, model: str) -> list[dict]:
        """Find all places a Pydantic model is used as a type annotation across the project."""
        project = _project(file)
        results = []
    
        for py_file in Path(str(project.path)).rglob("*.py"):
            try:
                tree = ast.parse(py_file.read_text())
            except SyntaxError:
                continue
            for node in ast.walk(tree):
                if isinstance(node, ast.AnnAssign):
                    if ast.unparse(node.annotation) == model:
                        results.append({"file": str(py_file), "line": node.lineno})
                if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
                    for arg in node.args.args:
                        if arg.annotation and ast.unparse(arg.annotation) == model:
                            results.append({"file": str(py_file), "line": arg.col_offset, "function": node.name})
    
        return results
  • Tool registration via @mcp.tool() decorator on the find_model_usages function. The FastMCP instance is created on line 6.
    @mcp.tool()
  • The _project helper function used by find_model_usages to locate the project root from a given file path by walking upward looking for marker files (pyproject.toml, requirements.txt, setup.py).
    def _project(file: str) -> jedi.Project:
        """Walk up from file to find the project root."""
        path = Path(file).resolve()
        for parent in [path.parent, *path.parents]:
            if any((parent / f).exists() for f in ("pyproject.toml", "requirements.txt", "setup.py")):
                return jedi.Project(path=str(parent))
        return jedi.Project(path=str(path.parent))
Behavior2/5

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

No annotations provided, so the description must disclose behavior. It states it finds usages but does not clarify scope (e.g., whole project, file types), whether it's read-only, performance implications, or side effects. The description is insufficient.

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

Conciseness5/5

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

The description is a single sentence with no unnecessary words. It is well-structured and front-loaded with the key action.

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?

Although an output schema exists, the description lacks crucial context: parameter semantics, usage guidelines, and behavioral details. For a tool with two undocumented required parameters, the description does not provide sufficient information for correct invocation.

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?

Schema description coverage is 0%, meaning parameters have no descriptions. The tool description does not explain the 'file' or 'model' parameters (e.g., format, required vs optional, interpretation). The agent has no guidance on what values to provide.

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 uses a specific verb+resource construction: 'Find all places a Pydantic model is used as a type annotation.' It clearly identifies the tool's purpose and distinguishes it from siblings like 'find_references' (more general) and 'go_to_definition'.

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

Usage Guidelines2/5

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

No explicit guidance on when to use this tool versus alternatives like 'find_references' or 'get_dependencies'. The description does not mention limitations or prerequisites.

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