Measuring and containing debt from AI-written code with ast-grep and import-linter
MCPass is an MCP[1] gateway developed at Nowcast. It registers internal MCP servers and runs them through access control and audit logs. The first version was an MVP written quickly with generative AI to test its value. A two-day camp by seven people produced about 45,000 lines, or about 100,000 with earlier prototypes. The author says that by late November 2026, more than 80% of that code had been replaced.
The author tracked the debt with git history and git blame. Direct reads and writes of ORM[2] models in the routers grew to 375 places by April, from an average of 2.9 per API at the start. From late May, queries were moved into one shared place. Within four weeks, router DB operations fell to 18, and they stayed at 22 while the number of APIs rose from 155 to 221. From October, code-shape rules were written as ast-grep[3] patterns and checked in CI, and there are now nine of them.
Modules that did not own a table kept accessing it. Right after the camp there were 31 such pairs, and by September there were 141. At the end of September the team decided that each table has one owning module and that others call its public interface. This rule is enforced as an import-linter[4] contract. Over the next two months the number of pairs fell to 79, and the number of tables that no other module touched rose from 7 to 33. The author notes that mechanical checks are not perfect and generative AI can get around them, so people still need to review such mistakes and the overall design.
Sources
-
JPZenn JA
AIで膨らんだ負債を計測・抑制する: ast-grepとimport-linter





