Skip to main content
Glama
AbdessamadTzn

FastAPI Architect MCP

list_routes

Inspect all FastAPI routes defined in a file, including those on APIRouter instances.

Instructions

List all FastAPI routes defined in a file, including those on APIRouter instances.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The `list_routes` tool handler function. Decorated with @mcp.tool(), it parses a Python file with the `ast` module, walks the AST for function definitions, inspects decorators for FastAPI route decorators (get, post, put, patch, delete, head, options), and returns a list of routes with method, path, handler name, line number, and async flag.
    @mcp.tool()
    def list_routes(file: str) -> list[dict]:
        """List all FastAPI routes defined in a file, including those on APIRouter instances."""
        tree = _parse(file)
        routes = []
    
        for node in ast.walk(tree):
            if not isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
                continue
            for decorator in node.decorator_list:
                if not isinstance(decorator, ast.Call):
                    continue
                func = decorator.func
                if not isinstance(func, ast.Attribute):
                    continue
                if func.attr not in ("get", "post", "put", "patch", "delete", "head", "options"):
                    continue
                path = decorator.args[0].value if decorator.args else "unknown"
                routes.append({
                    "method": func.attr.upper(),
                    "path": path,
                    "handler": node.name,
                    "line": node.lineno,
                    "is_async": isinstance(node, ast.AsyncFunctionDef),
                })
    
        return routes
  • The `_parse` helper function used by `list_routes` to read and parse a Python file into an AST Module.
    def _parse(file: str) -> ast.Module:
        with open(file) as f:
            return ast.parse(f.read())
  • The @mcp.tool() decorator registers `list_routes` as a tool in the FastMCP server instance.
    @mcp.tool()
    def list_routes(file: str) -> list[dict]:
Behavior2/5

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

No annotations are provided, so the description carries full burden. It only states the action without disclosing behavioral traits like whether it performs static analysis, handles syntax errors, or requires imports. For a read operation, it is insufficiently transparent.

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

Conciseness4/5

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

The description is a single concise sentence without extraneous words. It front-loads the purpose, but could be slightly more structured (e.g., splitting into usage notes).

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

Completeness3/5

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

Given the tool has only one required parameter and an output schema (which presumably documents the route list format), the description covers the basic purpose. However, it lacks details on what kind of file is expected and how the output is structured, leaving some ambiguity.

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

Parameters2/5

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

The parameter 'file' has no description in the schema, and the tool description adds no clarification (e.g., whether it expects a file path, module name, or source code string). With 0% schema description coverage, the description fails to compensate.

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 tool lists FastAPI routes in a file, including APIRouter instances. It uses a specific verb and resource, and distinguishes itself from siblings like 'list_models' which lists models, or 'find_references' which finds references.

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 guidance on when to use this tool versus alternatives. There is no mention of prerequisites (e.g., file must be a valid Python file with FastAPI app) or exclusions. With siblings like 'go_to_definition', a user might not know when to choose this tool.

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