Skip to content

fix(api-callers): give each client call to its most specific route - #134

Merged
spelech merged 2 commits into
mainfrom
fix/api-callers-route-specificity
Nov 12, 2026
Merged

spelech merged 2 commits into
mainfrom
fix/api-callers-route-specificity

Conversation

@spelech

@spelech spelech commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Problem

find_api_callers compares client calls with a route through match_route_and_call. A route parameter matches any segment. Thus a general route also gets the calls of a more specific route.

Example (ASP.NET API): GET api/v{version}/assistants/{id} matched the client calls GET /api/v2/Assistants/details, /drafts, and /system-tool-bundles. These calls belong to the routes api/v{version}/assistants/details, .../drafts, and .../system-tool-bundles. These routes also exist. ASP.NET and most other frameworks send a call to the most specific route.

trace_path had the same problem in external_callers and external_handlers.

Fix

  • A new module app/services/chunking/route_specificity.py applies the specificity rule. match_route_and_call does not change.
  • The rule compares two routes segment by segment from the left. A literal segment (details) beats a mixed segment (v{version}). A mixed segment beats a parameter ({id}). Routes of different length (base-relative calls) are compared by their number of literal segments. Equal routes are a tie, and both routes keep the call.
  • Only routes of the same repository and a compatible HTTP method compete. A route in an unrelated repository cannot take a call away. Routes in test files do not compete.
  • find_api_callers first resolves path to its own route in each repository. Then it keeps a call only when that route is also the most specific route for the call. When no known route matches path, the tool keeps every matching call, as before.
  • trace_path uses the same rule for external_callers and external_handlers.
  • Base-relative client URLs (for example /{baseUrl}/api/v2/Assistants/{id}) continue to match.
  • docs/mcp-tools-and-resources.md describes the rule.

Tests

  • New file tests/test_route_specificity.py (15 test cases). It covers the rule, base-relative URLs, method and repository separation, find_api_callers on a seeded database, and trace_path.
  • REQUIREMENTS.md is regenerated.
  • Full local suite: the branch and origin/main have the same failures. These failures come from packages that are not installed locally (fastembed, qdrant_client, tree-sitter grammars). The branch adds no new failures.

🤖 Generated with Claude Code

Steve Pelech and others added 2 commits November 12, 2026 15:40
# Conflicts:
#	REQUIREMENTS.md
#	app/mcp/handlers/route_handlers.py
#	app/services/graph_traversal.py
@spelech
spelech merged commit b975619 into main Nov 12, 2026
15 checks passed
@spelech
spelech deleted the fix/api-callers-route-specificity branch November 12, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant