Skip to main content
Glama
syrian963

django-chainsaw-mcp

by syrian963

serializer_nplusone

Read-onlyIdempotent

Identify N+1 query issues in DRF serializers and get the queryset fix, tracing nested relations to provide full lookup paths for each problem.

Instructions

N+1 queries in DRF serializers, with the queryset fix for each.

find_n_plus_one answers this for templates. Most Django written today
renders JSON, and there the N+1 comes from a nested serializer field: a list
of a hundred orders runs a hundred extra queries per nested relation.

Follows nested serializers, so the lookup it suggests is the full path.

Args:
    max_depth: how far to follow nested serializers.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
max_depthNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.3

TDQS

A4.2/5.0
Behavior4/5

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

With readOnlyHint and idempotentHint already covering safety, the description adds useful behavior: it follows nested serializers and suggests the full lookup path in the queryset fix. It doesn't fully spell out the output shape, but an output schema exists and annotations already cover side-effect concerns.

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 lean and front-loaded: it opens with the core purpose, then gives sibling context, traversal behavior, and the single argument. The opening is a fragment rather than an explicit sentence, but every line earns its place.

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

Completeness4/5

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

The description covers the analyzed context (nested DRF serializer fields), the rationale (JSON vs templates), the traversal behavior, and the one adjustable parameter. With safety annotations and an output schema present, no critical invocation context is missing.

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

Parameters4/5

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

The schema only provides 'max_depth' with a type and default, so the description's 'how far to follow nested serializers' adds meaningful semantics. For a single optional parameter and 0% schema description coverage, this is sufficient compensation.

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

Purpose4/5

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

The first line scopes the tool to 'N+1 queries in DRF serializers' and says a queryset fix accompanies each finding, which clearly separates it from template-oriented find_n_plus_one. It is clear and specific, though it relies on an implied verb rather than an explicit 'detects' or 'finds' statement.

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

Usage Guidelines5/5

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

The description explicitly names find_n_plus_one as the tool for templates, and frames this tool as the JSON/DRF serializer case with 'Most Django written today renders JSON'. This gives an agent clear when-to-use and alternative routing for the most relevant sibling.

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