Skip to content

[Request]: Add an MCP review of generated projects for avoidable imperative plumbing #428

Closed

Description

@jimhoyd

Problem or use case

The declarative-first goal is not merely valid YAML: an agent should avoid reimplementing URLCode behavior in a trusted function when the compiled project already has a declarative capability, extension, or recipe for it. Existing MCP tools explain the project and individual routes, but none gives a focused post-build answer to: "which generated code looks like framework plumbing, and what is the supported alternative?"

In benchmark run test1, URLCode agents used custom functions for every form-rendering/validation flow, cookie session logic, stored-link lookup/counters, and webhook deduplication. Some are legitimate current capability gaps; others may have a supported composition or a discovery failure. A review tool should distinguish those cases without pretending custom code is wrong by default.

Proposed behavior

Add an opt-in, read-only MCP/CLI operation, provisionally review_project, which analyzes the compiled project plus a bounded static inventory of project-owned function/middleware source. It returns observations grouped as:

  • native-alternative: a concrete already-supported declarative handler, policy, schema, recipe, or extension composition appears to cover the behavior;
  • extension-alternative: a registered/locked extension can plausibly own the behavior, with required operator setup stated;
  • gap: the observed pattern is not supported and should remain focused application code, with an issue-ready sanitized finding;
  • manual-review: uncertain pattern or security-sensitive behavior that must not be inferred automatically.

Start with conservative static signals, such as hand-written JSON/body validation when request.body.schema could express it; routing/method-dispatch duplication; project-global mutable state; manually assembled auth/session cookies; outbound network calls; and route code that appears to reproduce a configured policy. Findings must include source locations, confidence/reason, relevant capability/recipe links, and target/security implications.

Safety and boundary requirements

  • Do not execute project code, read environment/secrets, make network calls, or load arbitrary imports beyond the existing root-confined static source graph.
  • Do not claim that a function is insecure solely because it is trusted; trusted Node functions are an explicit supported mode. Flag durable-state, auth, and egress patterns for human review with the real limitation (restart/multi-instance behavior, grants, sandbox incompatibility), not a generic warning.
  • Do not suggest an extension as executable merely because a project declares it. Respect operator registration, revision pins, locked artifacts, and target support.
  • Keep source excerpts bounded and treat source text as untrusted data.

Acceptance evidence

  • Fixtures prove positive and negative detection for JSON validation, method dispatch, global mutable state, cookie/session construction, egress, and legitimate application-specific functions.
  • Tests assert that sandboxed and trusted execution modes retain their existing semantics.
  • The tool produces no false claim that the current core supports generic forms, stored short links, durable counters, or webhook idempotency.
  • Rerun representative authoring tasks; measure whether the review catches avoidable plumbing and produces actionable gap reports without raising acceptance regressions.

What I did not verify

I did not inspect every benchmark function or establish a safe general-purpose static-analysis rule set. The initial scope should remain advisory and conservative; an uncertain observation is preferable to an incorrect automatic refactor.

Activity

  1. added
    enhancement
    ai-first
    important
    on Sep 22, 2026
  2. jimhoyd commented on Sep 22, 2026

    @jimhoyd
    CollaboratorAuthor

    This is a good direction but too broad to land in one PR — the full native/extension/gap/manual-review taxonomy presumes a general rule engine and an "extension alternative" catalog we don't have yet. Recommend scoping v1 to a single, unambiguous pattern and proving the plumbing before generalizing.

    v1 scope: detect hand-written JSON body validation that duplicates request.body.schema. Look for manual JSON.parse/typeof/Array.isArray-style checks on request.body inside function/middleware source, and flag them with the schema-based alternative. This is the easiest pattern to state precisely, has one unambiguous declarative replacement, and needs no understanding of business logic — just recognizing validation-shaped code near request.body. Save cookie/session code and "global mutable state" detection for v2+; those need much fuzzier heuristics and carry more false-positive risk.

    Existing infrastructure this should reuse, not duplicate:

    • collectSourcesFor/collectTrustedSources in src/function-sources.ts already loads function/middleware source safely (parsed via es-module-lexer, with per-module/total byte limits, no execution, no import of project code) — exactly the safe read primitive this needs.
    • searchDocs in src/agent-context.ts (from Add function-handler section to llms.txt and urlcode docs search CLI #432) is the house style for a bounded, deterministic, read-only MCP tool — small fixed inputs, lexical/structural matching, capped results. review_project should follow that shape.
    • src/body-schema.ts is the exact declarative target to point findings at.

    First-PR file list: a new detector module built on collectSourcesFor; register review_project as a read-only MCP tool (no authoring-gate needed, same tier as inspect); a matching urlcode review-project CLI command for parity with docs search; a test fixture with one hand-rolled validator to prove the detector fires and stays silent on schema-only routes; a short doc section stating the v1 scope and explicitly the non-goals (no execution, no other patterns yet, native-alternative findings only).

    Non-negotiables carried over from the issue, already structurally satisfied by function-sources.ts: never execute project code, never read env/secret bindings, never make network calls, stay within existing byte budgets.

  3. jimhoyd commented on Sep 22, 2026

    @jimhoyd
    CollaboratorAuthor

    This is already substantially covered: #437 merged review_project (MCP tool + urlcode review CLI) with 4 detection signals — manual-body-validation, manual-cookie-session, global-mutable-state, and outbound-network-call — each with positive/negative fixtures, following the conservative native-alternative/extension-alternative/gap/manual-review taxonomy from the original request. (A duplicate, narrower single-signal implementation was independently built in parallel and closed as redundant in #446.)

    Leaving this open for you to decide whether #437's scope satisfies the issue or whether it should stay open for the remaining signal types the original request mentioned but #437 didn't cover.

  4. added a commit that references this issue on Sep 22, 2026
  5. jimhoyd commented on Sep 22, 2026

    @jimhoyd
    CollaboratorAuthor

    All signal types from the original request are now implemented: #437 covered manual-body-validation, manual-cookie-session, global-mutable-state, and outbound-network-call; #449 added the remaining method-dispatch, policy-duplication (manual-rate-limit/manual-security-headers), and registered-vs-declared extension distinction signals, each with positive/negative fixtures following the same conservative native-alternative/extension-alternative/gap/manual-review taxonomy.

    The one item from the original acceptance checklist not done here is rerunning representative benchmark authoring tasks to measure real-world catch rate — that's a separate evaluation exercise, not a code change, and can be tracked separately if useful. Closing this as the tool itself is now feature-complete against the issue's scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-firstenhancementimportant

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions