<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: AI Wisdom</title>
    <description>The latest articles on DEV Community by AI Wisdom (aiwisdomdev).</description>
    <link>https://dev.to/aiwisdomdev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F13851%2F2c290f25-065f-4ccb-ab42-17f5d15776e0.png</url>
      <title>DEV Community: AI Wisdom</title>
      <link>https://dev.to/aiwisdomdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aiwisdomdev"/>
    <language>en</language>
    <item>
      <title>Amit Got Stuck Reviewing Agent Code: Green CI, Wrong Behaviour</title>
      <dc:creator>Amit Upadhyay</dc:creator>
      <pubDate>Sat, 14 Nov 2026 12:44:00 +0000</pubDate>
      <link>https://dev.to/aiwisdomdev/amit-got-stuck-reviewing-agent-code-green-ci-wrong-behaviour-27p9</link>
      <guid>https://dev.to/aiwisdomdev/amit-got-stuck-reviewing-agent-code-green-ci-wrong-behaviour-27p9</guid>
      <description>&lt;p&gt;Every check passed. Twelve new tests, green CI, two approvals. And the invoices were rounding down.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A story: the names and numbers are invented, the failure is real.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The pull request looked great. Tidy functions, good names, twelve new tests, all passing. An agent had written it. I read it, liked it, and approved it.&lt;/p&gt;

&lt;p&gt;Two weeks later a customer told us their invoices were rounding down. I dug in and found the bug in the new code. Then I opened the new test for it, and the test asserted the wrong value.&lt;/p&gt;

&lt;p&gt;I rebuilt what happened:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The agent wrote the code, and the code rounded down.&lt;/li&gt;
&lt;li&gt;The agent then wrote a test, and the test asserted what the code did.&lt;/li&gt;
&lt;li&gt;The two agreed with each other, so CI went green.&lt;/li&gt;
&lt;li&gt;I read a tidy diff and saw nothing that looked like a mistake. Because it did not look like one.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Green CI. Passing tests. A clean diff. And the wrong behaviour shipped anyway. I stared at the test for a long time.&lt;/p&gt;

&lt;p&gt;When I'm stuck, I open the one reference that does not hand out answers. AI Wisdom is not a friendly tutor. It is a guru, and it makes you earn the solution.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fns3b5lvxml4xol9njn3i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fns3b5lvxml4xol9njn3i.png" alt="Chat between AI Wisdom and Amit. AI Wisdom: Was the pull request good? Amit: Tidy, well named, twelve tests, all green. I approved it. AI Wisdom: You described how it looked. I asked if it was good." width="560" height="317"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I had no answer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkk29ndgdnjq2c7nq52eo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkk29ndgdnjq2c7nq52eo.png" alt="Chat between AI Wisdom and Amit. AI Wisdom: Before I give you a fix, tell me the problem in one sentence. A fix without a problem is how the same bug ships twice. Amit: The invoices were rounding down. AI Wisdom: That is what happened. I asked what the problem is. Amit: I should have caught it in review. AI Wisdom: Caught it how? With what?" width="560" height="551"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I sat with that one for a while.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqjfk227766dqc4n99qns.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqjfk227766dqc4n99qns.png" alt="Chat between AI Wisdom and Amit. Amit: Green CI only tells me the tests pass. The agent wrote the tests, so they prove very little. AI Wisdom: Now you have a problem. Until now you only had an incident." width="560" height="260"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Draw the problem
&lt;/h2&gt;

&lt;p&gt;Once I could say it in one sentence, I drew it. First the version I would have understood in my first year. Then the one for people who review pull requests for a living.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Beginner view: a student who marks their own exam.&lt;/strong&gt; The agent wrote the questions and the answers. Then it marked itself. Of course it got full marks.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;%%{init: {"themeVariables": {"fontSize": "16px", "lineColor": "#8B97A8"}, "flowchart": {"wrappingWidth": 180, "nodeSpacing": 20, "rankSpacing": 32, "padding": 10, "subGraphTitleMargin": {"top": 6, "bottom": 20}}}}%%
flowchart TD
  A(["The agent"]):::person --&amp;gt; W
  subgraph W["The student writes the exam"]
    direction TB
    Q["Writes the code: it rounds down"]:::bad --&amp;gt; K["Writes the test: it asserts the rounded-down value"]:::bad
  end
  subgraph M["Then marks their own paper"]
    direction TB
    G["Test passes. Full marks."]:::ok --&amp;gt; C["CI is green"]:::ok
  end
  W --&amp;gt; M
  M --&amp;gt;|looks fine to| R(["Amit, the reviewer"]):::person
  classDef ok fill:#DCFCE7,stroke:#16A34A,color:#14532D
  classDef bad fill:#FEE2E2,stroke:#DC2626,color:#7F1D1D
  classDef stop fill:#FEF3C7,stroke:#D97706,color:#78350F
  classDef note fill:#E0E7FF,stroke:#4F46E5,color:#1E1B4B
  classDef person fill:#FCE7F3,stroke:#DB2777,color:#831843
  style W fill:none,stroke:#A3AEC0,stroke-dasharray:5 4,color:#475569
  style M fill:none,stroke:#A3AEC0,stroke-dasharray:5 4,color:#475569&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;&lt;strong&gt;Technical view: the same pull request, step by step.&lt;/strong&gt; Both pieces came from one author, so they are consistent with each other. Consistent is not the same as correct.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;%%{init: {"themeVariables": {"fontSize": "16px", "lineColor": "#8B97A8"}, "flowchart": {"wrappingWidth": 180, "nodeSpacing": 20, "rankSpacing": 32, "padding": 10, "subGraphTitleMargin": {"top": 6, "bottom": 20}}}}%%
flowchart TD
  S(["Amit opens the pull request"]):::person --&amp;gt; PR
  subgraph PR["What was in the pull request"]
    direction TB
    c1["New code: fluent, tidy, wrong"]:::bad --&amp;gt; c2["Twelve new tests, written by the same agent"]:::note
  end
  PR --&amp;gt; CI
  subgraph CI["What CI proved"]
    direction TB
    t1["The tests pass"]:::ok --&amp;gt; t2["That is all it proved"]:::stop
  end
  CI --&amp;gt; AP["Two approvals: nobody read the tests against the spec"]:::stop
  AP --&amp;gt; X["Two weeks later: a customer finds the wrong invoices"]:::bad
  classDef ok fill:#DCFCE7,stroke:#16A34A,color:#14532D
  classDef bad fill:#FEE2E2,stroke:#DC2626,color:#7F1D1D
  classDef stop fill:#FEF3C7,stroke:#D97706,color:#78350F
  classDef note fill:#E0E7FF,stroke:#4F46E5,color:#1E1B4B
  classDef person fill:#FCE7F3,stroke:#DB2777,color:#831843
  style PR fill:none,stroke:#A3AEC0,stroke-dasharray:5 4,color:#475569
  style CI fill:none,stroke:#A3AEC0,stroke-dasharray:5 4,color:#475569&lt;/code&gt;&lt;/pre&gt;



&lt;h2&gt;
  
  
  Do you have this problem?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2kxccluoenoubyhvbeit.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2kxccluoenoubyhvbeit.png" alt="Chat between AI Wisdom and Amit. AI Wisdom: Do not ask me. Open your last agent-written pull request and ask yourself." width="560" height="143"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your team merges agent code and you are not sure how closely it's being read&lt;/li&gt;
&lt;li&gt;Reviews feel like skimming because the volume went up&lt;/li&gt;
&lt;li&gt;Tests pass, and bugs still get through&lt;/li&gt;
&lt;li&gt;You approved a pull request without reading its tests against the spec&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I ticked all four. How many do you tick?&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it hid
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F61cg6rhfdzehqcjccotg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F61cg6rhfdzehqcjccotg.png" alt="Chat between AI Wisdom and Amit. AI Wisdom: When a colleague makes a mistake, what does it usually look like? Amit: Awkward code. A confused comment. You can see them struggling. AI Wisdom: And when the agent makes one? Amit: It looks exactly like the right code. Same confident style. Same tidy names." width="560" height="434"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Agent-written code fails differently from a junior engineer's, and my review habits were built for the junior engineer. An agent's mistakes are fluent, so the cues I had learned to rely on were gone. And there was a lot more of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix that is a trap
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fj8ix5ri3nfw3hx500xkx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fj8ix5ri3nfw3hx500xkx.png" alt="Chat between AI Wisdom and Amit. AI Wisdom: Fix it. Amit: Easy. I ask the agent whether its code is correct. AI Wisdom: What will it say? Amit: Yes. Very sure of itself. AI Wisdom: Then you asked the student whether he deserves his marks. A judge who wrote the exam is not a judge." width="560" height="521"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An agent grading its own work is a poor judge. It will usually say yes, and it will sound convinced. Ask a fresh session to find problems instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: read the tests first
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fro12oqlv4cnomfhyvezv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fro12oqlv4cnomfhyvezv.png" alt="Chat between AI Wisdom and Amit. AI Wisdom: You read the code and then trusted the tests. Turn it around. Read the tests first, against the spec. Would they fail if the feature were broken?" width="560" height="173"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I changed the order I read an agent's pull request in, because the risk sits in different places:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The spec or ticket.&lt;/strong&gt; Know what should have happened before you see what did.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The diff summary.&lt;/strong&gt; Do the touched files make sense? Anything unexpected is the first question.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The tests.&lt;/strong&gt; Read these before the code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;New dependencies, config and migrations.&lt;/strong&gt; These have the largest blast radius.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error handling and boundaries.&lt;/strong&gt; This is where fluent code hides its mistakes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The rest of the code.&lt;/strong&gt; By now I know what to look for.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Then I make the tests prove something. The strongest check for a test is to break the code and see whether it fails. Mutation testing automates that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Does the test suite notice when the code is wrong?&lt;/span&gt;
&lt;span class="c"&gt;# First time only: npm init stryker  (installs the test-runner plugin and writes a config)&lt;/span&gt;
npx stryker run --mutate &lt;span class="s2"&gt;"src/billing/**/*.ts"&lt;/span&gt;

&lt;span class="c"&gt;# Every new dependency, for a human to check&lt;/span&gt;
git diff origin/main -- package.json pnpm-lock.yaml &lt;span class="o"&gt;|&lt;/span&gt; grep &lt;span class="s1"&gt;'^+'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; grep -v &lt;span class="s1"&gt;'^+++'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The cheap version is to ask a fresh agent session, with no memory of the implementation, to write the tests from the spec alone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The fix as a flow.&lt;/strong&gt; Generation and evaluation are separate sessions. A person still reads the tests, the risks and the diff.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;%%{init: {"themeVariables": {"fontSize": "16px", "lineColor": "#8B97A8"}, "flowchart": {"wrappingWidth": 170, "nodeSpacing": 20, "rankSpacing": 32, "padding": 10, "subGraphTitleMargin": {"top": 6, "bottom": 20}}}}%%
flowchart TD
  SP(["The spec"]):::note --&amp;gt; SE
  subgraph SE["Three separate sessions"]
    direction TB
    I["1. Implementing session: build this&amp;lt;br/&amp;gt;2. Fresh test session: tests from the spec only&amp;lt;br/&amp;gt;3. Fresh review session: the diff, no reasoning attached"]:::ok
  end
  SE --&amp;gt; CI
  subgraph CI["CI flags two things"]
    direction TB
    F["New dependencies and changed assertions"]:::stop
  end
  CI --&amp;gt; HU
  subgraph HU["Then a person reads"]
    direction TB
    H["The tests first, then the risks, then the diff"]:::note
  end
  classDef ok fill:#DCFCE7,stroke:#16A34A,color:#14532D
  classDef bad fill:#FEE2E2,stroke:#DC2626,color:#7F1D1D
  classDef stop fill:#FEF3C7,stroke:#D97706,color:#78350F
  classDef note fill:#E0E7FF,stroke:#4F46E5,color:#1E1B4B
  style SE fill:none,stroke:#A3AEC0,stroke-dasharray:5 4,color:#475569
  style CI fill:none,stroke:#A3AEC0,stroke-dasharray:5 4,color:#475569
  style HU fill:none,stroke:#A3AEC0,stroke-dasharray:5 4,color:#475569&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqpfxuu548wk5zkzt036i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqpfxuu548wk5zkzt036i.png" alt="Chat between AI Wisdom and Amit. AI Wisdom: A second session reviewing the change has seen none of the reasoning that led to it, so it is not anchored on it. Amit: So it replaces the human? AI Wisdom: It is a good first pass. It finds real things. It does not replace a person." width="560" height="347"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What else to look for
&lt;/h2&gt;

&lt;p&gt;Invented packages are worth a special mention. Models sometimes suggest package names that sound right and don't exist. Attackers register those names and wait, which is known as slopsquatting. The install succeeds, and CI stays green. So every new dependency gets checked by hand.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Failure&lt;/th&gt;
&lt;th&gt;What it looks like&lt;/th&gt;
&lt;th&gt;How to catch it&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Tests that prove nothing&lt;/td&gt;
&lt;td&gt;Asserts what the code does, or mocks the thing under test&lt;/td&gt;
&lt;td&gt;Read the tests first, against the spec&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Invented dependencies&lt;/td&gt;
&lt;td&gt;A package that doesn't exist, or one a squatter registered&lt;/td&gt;
&lt;td&gt;Check every new dependency by hand&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scope creep&lt;/td&gt;
&lt;td&gt;Unrelated refactors mixed into the change&lt;/td&gt;
&lt;td&gt;Compare the diff with the spec&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reinvented helpers&lt;/td&gt;
&lt;td&gt;A new utility that duplicates one you already have&lt;/td&gt;
&lt;td&gt;Search before accepting new helpers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Silent failure handling&lt;/td&gt;
&lt;td&gt;A broad catch that hides errors and returns a default&lt;/td&gt;
&lt;td&gt;Look hard at every catch and fallback&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Loosened checks&lt;/td&gt;
&lt;td&gt;A test or lint rule weakened to make things pass&lt;/td&gt;
&lt;td&gt;Flag any change to existing assertions&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Package hallucination is studied in &lt;a href="https://arxiv.org/abs/2605.17062" rel="noopener noreferrer"&gt;this research paper&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prove it with a checklist
&lt;/h2&gt;

&lt;p&gt;For a large agent-written change I use a short list, because fluent code makes it easy to lose focus:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Does this solve the problem in the ticket, or a slightly different one?&lt;/li&gt;
&lt;li&gt;Would each new test fail if the feature were broken?&lt;/li&gt;
&lt;li&gt;Is every new dependency real, maintained and needed?&lt;/li&gt;
&lt;li&gt;Are errors handled, or just caught and hidden?&lt;/li&gt;
&lt;li&gt;Does anything touch auth, money, or data deletion?&lt;/li&gt;
&lt;li&gt;Is there new code that duplicates something we already have?&lt;/li&gt;
&lt;li&gt;Could I debug this at 2 a.m.?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Which check catches which failure?&lt;/strong&gt; CI answers one question. A person has to answer the rest.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;%%{init: {"themeVariables": {"fontSize": "16px", "lineColor": "#8B97A8"}, "flowchart": {"wrappingWidth": 190, "nodeSpacing": 20, "rankSpacing": 32, "padding": 10, "subGraphTitleMargin": {"top": 6, "bottom": 20}}}}%%
flowchart TD
  subgraph CI["Green CI tells you one thing"]
    direction TB
    C["The tests pass"]:::ok
  end
  subgraph PE["Only a person can tell you"]
    direction TB
    P["Do the tests assert the right thing?&amp;lt;br/&amp;gt;Is every new dependency real?&amp;lt;br/&amp;gt;Is this the problem in the ticket?&amp;lt;br/&amp;gt;Could I debug this at 2 a.m.?"]:::bad
  end
  CI --&amp;gt; PE
  classDef ok fill:#DCFCE7,stroke:#16A34A,color:#14532D
  classDef bad fill:#FEE2E2,stroke:#DC2626,color:#7F1D1D
  classDef stop fill:#FEF3C7,stroke:#D97706,color:#78350F
  classDef note fill:#E0E7FF,stroke:#4F46E5,color:#1E1B4B
  style CI fill:none,stroke:#A3AEC0,stroke-dasharray:5 4,color:#475569
  style PE fill:none,stroke:#A3AEC0,stroke-dasharray:5 4,color:#475569&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;If the answer to the last question is no, send it back, even if everything else passes. Readability is a safety property. Code that nobody on the team understands is a liability that only looks finished. &lt;strong&gt;If you cannot say whether the tests would fail when the feature is broken, you have a pull request with a nice diff.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The guru's last word
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuxfancdud79nnae6h7ez.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuxfancdud79nnae6h7ez.png" alt="Chat between AI Wisdom and Amit. AI Wisdom: Scale review by risk. Auth, payments, data migrations and infrastructure: two people, line by line, and the design agreed first. Features and business logic: one person, in the order above. Docs, renames and test additions: automated checks and a quick read. AI Wisdom: Encode it with path-based code owners, so a change to the billing folder always gets the right reviewers. Do not try to detect who wrote the code. Hold every change to the same bar, and let risk set the depth. AI Wisdom: Understand the problem, and the solution becomes a small thing." width="560" height="578"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What I do first now: add a check that flags new dependencies and any change to existing test assertions, since those are the two cheapest catches. Set a size limit on pull requests, because nobody reviews 3,000 lines well. Then agree one rule as a team: whoever opens a pull request can explain every line of it, whoever or whatever wrote it. "The agent wrote that" is not an answer in an incident review.&lt;/p&gt;

&lt;p&gt;Be kind to your reviewers as well. If you opened the pull request, read it yourself first, and note where you're unsure. A reviewer shouldn't be the first human to see the code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Go deeper
&lt;/h2&gt;

&lt;p&gt;My problem is fixed. The rest is in the full guide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The full table of what agent mistakes look like and how to catch each one&lt;/li&gt;
&lt;li&gt;The reading order for a pull request and why the risk sits where it does&lt;/li&gt;
&lt;li&gt;How to keep generation and evaluation in separate sessions&lt;/li&gt;
&lt;li&gt;Review depth by risk tier, with path-based code owners (&lt;a href="https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners" rel="noopener noreferrer"&gt;how CODEOWNERS works&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Mutation testing to check that tests can fail (&lt;a href="https://stryker-mutator.io/docs/stryker-js/getting-started/" rel="noopener noreferrer"&gt;StrykerJS getting started&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  More from AI Wisdom
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.aiwisdom.dev/?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=reviewing-agent-written-code" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1jmh663vvktp4bnv192l.png" alt="AI Wisdom, aiwisdom.dev: the engineering reference for production AI. 179 in-depth articles, 18 topic tracks, and mock exams for AI certifications." width="800" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://www.aiwisdom.dev/articles/ai-coding/reviewing-agent-written-code?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=reviewing-agent-written-code" rel="noopener noreferrer"&gt;Read the full guide on AI Wisdom →&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Neighbouring problems, in the same library:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://www.aiwisdom.dev/articles/ai-coding/working-with-coding-agents?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=reviewing-agent-written-code" rel="noopener noreferrer"&gt;Working With Coding Agents: The Loop That Holds Up&lt;/a&gt;&lt;/strong&gt;: explore, plan, implement, verify and review, with small diffs and a spec first&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://www.aiwisdom.dev/articles/agentic-systems/testing-autonomous-coding-agents?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=reviewing-agent-written-code" rel="noopener noreferrer"&gt;Testing Autonomous Coding Agents&lt;/a&gt;&lt;/strong&gt;: a hands-on experiment comparing coding agents on real engineering tasks&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://www.aiwisdom.dev/articles/security-engineering/dependency-scanning-supply-chain?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=reviewing-agent-written-code" rel="noopener noreferrer"&gt;Dependency Scanning: Securing Your Software Supply Chain&lt;/a&gt;&lt;/strong&gt;: supply chain attacks, lockfile integrity and tools like Snyk and Dependabot&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://www.aiwisdom.dev/checklist?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=reviewing-agent-written-code" rel="noopener noreferrer"&gt;Production AI System Checklist&lt;/a&gt;&lt;/strong&gt;: a free 6-page PDF with 30 checks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Which Amit are you?&lt;/strong&gt; Open your last agent-written pull request and look at what you read first. Reply with which it was: "the tests", "the code", or "neither, CI was green".&lt;/p&gt;

</description>
      <category>ai</category>
      <category>programming</category>
      <category>codereview</category>
      <category>testing</category>
    </item>
    <item>
      <title>Amit Got Stuck in MCP: A Valid Token, the Wrong Tenant</title>
      <dc:creator>Amit Upadhyay</dc:creator>
      <pubDate>Wed, 11 Nov 2026 17:29:42 +0000</pubDate>
      <link>https://dev.to/aiwisdomdev/your-mcp-server-checks-the-token-does-it-check-the-tenant-5h3a</link>
      <guid>https://dev.to/aiwisdomdev/your-mcp-server-checks-the-token-does-it-check-the-tenant-5h3a</guid>
      <description>&lt;p&gt;Every check passed. Valid token, right scope, 200 OK. And Maya from Acme was reading Globex's deployments.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A story: the names and numbers are invented, the failure is real.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I shipped my MCP server on a Friday. Bearer token on &lt;code&gt;/mcp&lt;/code&gt;, a scope check, and I tested it both ways: the right token worked, a missing token got a 401. Green. I went home early.&lt;/p&gt;

&lt;p&gt;On Monday, Maya from Acme support sent me a screenshot. Her assistant had shown her deployments for &lt;code&gt;payments-globex&lt;/code&gt;. That is a Globex service. Maya works for Acme.&lt;/p&gt;

&lt;p&gt;I rebuilt what happened from the logs:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Maya's assistant connected with a valid token that carried the &lt;code&gt;mcp:devops&lt;/code&gt; scope.&lt;/li&gt;
&lt;li&gt;She asked, "What shipped to payments last night?" The model called &lt;code&gt;list_recent_deployments&lt;/code&gt; with &lt;code&gt;service: "payments"&lt;/code&gt;. Fine.&lt;/li&gt;
&lt;li&gt;Later, a pasted ticket mentioned &lt;code&gt;payments-globex&lt;/code&gt;. The model called the tool with that name.&lt;/li&gt;
&lt;li&gt;The endpoint saw a valid token with the right scope and let it through.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Valid token. Right scope. 200 OK. Every check had passed, and the wrong customer's data still came out. I stared at that for an hour.&lt;/p&gt;

&lt;p&gt;When I'm stuck, I open the one reference that does not hand out answers. AI Wisdom is not a friendly tutor. It is a guru, and it makes you earn the solution.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs4pmh0vvqgwzr5fh8fzg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs4pmh0vvqgwzr5fh8fzg.png" alt="Chat between AI Wisdom and Amit. AI Wisdom: Is your server secure? Amit: Token, scope, and a 401 for a missing token. I tested it. AI Wisdom: You tested the doors that should open. Which door should stay shut?" width="560" height="317"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I had no answer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpgxavmwmwuiffgxid64n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpgxavmwmwuiffgxid64n.png" alt="Chat between AI Wisdom and Amit. AI Wisdom: Before I give you a fix, tell me the problem in one sentence. A fix without a problem is how the same bug ships twice. Amit: The wrong customer's data came out. AI Wisdom: That is what happened. I asked what the problem is. Amit: The token is not enough. AI Wisdom: Not enough for what?" width="560" height="551"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I sat with that one for a while.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm7nqm5upf8axnig1cjok.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm7nqm5upf8axnig1cjok.png" alt="Chat between AI Wisdom and Amit. Amit: A valid token tells me who is calling. It does not tell me what the model is allowed to ask for. AI Wisdom: Now you have a problem. Until now you only had an incident." width="560" height="260"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Draw the problem
&lt;/h2&gt;

&lt;p&gt;Once I could say it in one sentence, I drew it. First the version I would have understood in my first year. Then the one for people who read tokens for a living.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Beginner view: a hotel key card.&lt;/strong&gt; The token is a key card. Door one asks, "is this a real card?" Mine passed. Door two asks, "does this card open this room?" I never built door two.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;%%{init: {"themeVariables": {"fontSize": "16px", "lineColor": "#8B97A8"}, "flowchart": {"wrappingWidth": 180, "nodeSpacing": 20, "rankSpacing": 32, "padding": 10, "subGraphTitleMargin": {"top": 6, "bottom": 20}}}}%%
flowchart TD
  M(["Maya, Acme support"]):::person --&amp;gt;|shows her assistant's key card| D1
  subgraph D1["Door 1: is this a real card?"]
    direction TB
    A["Valid token, scope mcp:devops"]:::ok --&amp;gt; B["The server says YES"]:::ok
  end
  subgraph D2["Door 2: does it open THIS room?"]
    direction TB
    C["The room is payments-globex, a Globex service. Nobody built this door."]:::bad --&amp;gt; D["Globex's deployments"]:::bad
  end
  D1 --&amp;gt; D2
  D2 --&amp;gt;|shown to| M2(["Maya, an Acme user"]):::person
  classDef ok fill:#DCFCE7,stroke:#16A34A,color:#14532D
  classDef bad fill:#FEE2E2,stroke:#DC2626,color:#7F1D1D
  classDef note fill:#E0E7FF,stroke:#4F46E5,color:#1E1B4B
  classDef person fill:#FCE7F3,stroke:#DB2777,color:#831843
  style D1 fill:none,stroke:#A3AEC0,stroke-dasharray:5 4,color:#475569
  style D2 fill:none,stroke:#A3AEC0,stroke-dasharray:5 4,color:#475569&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;&lt;strong&gt;Technical view: the same Monday, as requests.&lt;/strong&gt; The model chose the service name both times. The endpoint only sees the token, and the token was fine.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;%%{init: {"themeVariables": {"fontSize": "16px", "lineColor": "#8B97A8"}, "flowchart": {"wrappingWidth": 180, "nodeSpacing": 20, "rankSpacing": 32, "padding": 10, "subGraphTitleMargin": {"top": 6, "bottom": 20}}}}%%
flowchart TD
  M(["Maya, Acme support"]):::person --&amp;gt;|asks her assistant| R1
  subgraph R1["Request 1: payments"]
    direction TB
    a1["Endpoint: token valid, scope OK"]:::ok --&amp;gt;|tool runs| a2["Acme's deployments"]:::ok
  end
  R1 --&amp;gt; P["A pasted ticket mentions payments-globex.&amp;lt;br/&amp;gt;The model calls again, same token."]:::note
  P --&amp;gt; R2
  subgraph R2["Request 2: payments-globex"]
    direction TB
    b1["Endpoint: token valid, scope OK"]:::ok --&amp;gt;|tool runs| b2["Nobody asks: may THIS caller read it?"]:::bad
    b2 --&amp;gt; b3["Globex's deployments"]:::bad
  end
  R2 --&amp;gt;|reach| M2(["Maya, an Acme user"]):::person
  classDef ok fill:#DCFCE7,stroke:#16A34A,color:#14532D
  classDef bad fill:#FEE2E2,stroke:#DC2626,color:#7F1D1D
  classDef note fill:#E0E7FF,stroke:#4F46E5,color:#1E1B4B
  classDef person fill:#FCE7F3,stroke:#DB2777,color:#831843
  style R1 fill:none,stroke:#A3AEC0,stroke-dasharray:5 4,color:#475569
  style R2 fill:none,stroke:#A3AEC0,stroke-dasharray:5 4,color:#475569&lt;/code&gt;&lt;/pre&gt;



&lt;h2&gt;
  
  
  Do you have this problem?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fof11gw2r63dm2v9zbqwb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fof11gw2r63dm2v9zbqwb.png" alt="Chat between AI Wisdom and Amit. AI Wisdom: Do not ask me. Open your server and ask yourself." width="560" height="113"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A tool takes a &lt;code&gt;service&lt;/code&gt;, &lt;code&gt;tenant&lt;/code&gt;, &lt;code&gt;project&lt;/code&gt; or &lt;code&gt;id&lt;/code&gt; argument and passes it straight to a backend&lt;/li&gt;
&lt;li&gt;The only authorization code sits on the endpoint (&lt;code&gt;RequireAuthorization&lt;/code&gt;), and none inside the tools&lt;/li&gt;
&lt;li&gt;You have never run a test where a valid token asks for someone else's resource&lt;/li&gt;
&lt;li&gt;Some tools are "just read-only", so nobody looked at what they can leak&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I ticked three. How many do you tick?&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the demo never showed it
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx84hxk5gcs7t5gujnry7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx84hxk5gcs7t5gujnry7.png" alt="Chat between AI Wisdom and Amit. AI Wisdom: In your demo, the person asking owns everything they ask for, so every request passes. The gap opens only when the arguments point at something the caller does not own. Who chooses the arguments? Amit: The model." width="560" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix that is a trap
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1zsenk3b08rj8i0gktc7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1zsenk3b08rj8i0gktc7.png" alt="Chat between AI Wisdom and Amit. AI Wisdom: Fix it. Amit: Easy. I add a tenant argument to the tool and compare it with the tenant in the token. AI Wisdom: Who fills in tenant? Amit: The model does. AI Wisdom: Then you asked the visitor to print his own pass. A guard who accepts the visitor's pass is not a guard." width="560" height="551"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I never trust a tenant identifier that came from the model now. It is not permission.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: check inside the tool
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy82y7hu8s2v6up9bq10o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy82y7hu8s2v6up9bq10o.png" alt="Chat between AI Wisdom and Amit. AI Wisdom: The tool decides from who the caller is, never from what the caller says. Derive the caller from the validated identity, and authorize the specific resource before anything else." width="560" height="203"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Look at the first line of the method body:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;McpServerTool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"list_recent_deployments"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Description&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"List recent deployments for a service"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;ListDeployments&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Description&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Service name"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Description&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Number of deployments to return"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;callerAccess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;RequireServicePermissionAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"deployments:read"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        $&lt;span class="s2"&gt;"/api/deployments?service={Uri.EscapeDataString(service)}&amp;amp;top={count}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;EnsureSuccessStatusCode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReadAsStringAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;callerAccess&lt;/code&gt; is built from validated claims for HTTP, and from an explicit local policy for stdio. It never trusts a tenant or service name supplied by the model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The fix as a flow.&lt;/strong&gt; The check moves from the endpoint into the tool. It uses the caller from the validated identity, not anything the model wrote.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;%%{init: {"themeVariables": {"fontSize": "16px", "lineColor": "#8B97A8"}, "flowchart": {"wrappingWidth": 150, "nodeSpacing": 20, "rankSpacing": 32, "padding": 10, "subGraphTitleMargin": {"top": 6, "bottom": 20}}}}%%
flowchart TD
  R(["Request: token + a service name chosen by the model"]):::note --&amp;gt; EP
  subgraph EP["Endpoint"]
    direction TB
    E["Token valid? Scope present?"]
  end
  subgraph TL["Tool, first line"]
    direction TB
    T["May THIS caller read this service?&amp;lt;br/&amp;gt;deployments:read"]:::note
  end
  EP --&amp;gt;|no| X1["401 or 403"]:::stop
  EP --&amp;gt;|yes| TL
  TL --&amp;gt;|"may NOT"| X2["Refused: backend untouched"]:::stop
  TL --&amp;gt;|"may"| B["Backend returns the rows"]:::ok
  classDef ok fill:#DCFCE7,stroke:#16A34A,color:#14532D
  classDef bad fill:#FEE2E2,stroke:#DC2626,color:#7F1D1D
  classDef stop fill:#FEF3C7,stroke:#D97706,color:#78350F
  classDef note fill:#E0E7FF,stroke:#4F46E5,color:#1E1B4B
  style EP fill:none,stroke:#A3AEC0,stroke-dasharray:5 4,color:#475569
  style TL fill:none,stroke:#A3AEC0,stroke-dasharray:5 4,color:#475569&lt;/code&gt;&lt;/pre&gt;



&lt;h2&gt;
  
  
  Prove it with six tests
&lt;/h2&gt;

&lt;p&gt;I wrote these before I touched the second tool:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No token&lt;/li&gt;
&lt;li&gt;A token from the wrong issuer&lt;/li&gt;
&lt;li&gt;A token for the wrong audience&lt;/li&gt;
&lt;li&gt;An expired token&lt;/li&gt;
&lt;li&gt;A valid token with a missing scope&lt;/li&gt;
&lt;li&gt;A valid token asking for another tenant's resource&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Which layer stops which test?&lt;/strong&gt; The first five are about the token. Only the tool knows whose data a valid token is asking for.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;%%{init: {"themeVariables": {"fontSize": "16px", "lineColor": "#8B97A8"}, "flowchart": {"wrappingWidth": 190, "nodeSpacing": 20, "rankSpacing": 32, "padding": 10, "subGraphTitleMargin": {"top": 6, "bottom": 20}}}}%%
flowchart TD
  subgraph EP["The endpoint stops these five"]
    direction TB
    E["1. No token&amp;lt;br/&amp;gt;2. Wrong issuer&amp;lt;br/&amp;gt;3. Wrong audience&amp;lt;br/&amp;gt;4. Expired token&amp;lt;br/&amp;gt;5. Valid token, missing scope"]:::ok
  end
  subgraph TL["Only the tool can stop this one"]
    direction TB
    T["6. Valid token, another tenant's resource"]:::bad
  end
  EP --&amp;gt; TL
  classDef ok fill:#DCFCE7,stroke:#16A34A,color:#14532D
  classDef bad fill:#FEE2E2,stroke:#DC2626,color:#7F1D1D
  classDef stop fill:#FEF3C7,stroke:#D97706,color:#78350F
  classDef note fill:#E0E7FF,stroke:#4F46E5,color:#1E1B4B
  style EP fill:none,stroke:#A3AEC0,stroke-dasharray:5 4,color:#475569
  style TL fill:none,stroke:#A3AEC0,stroke-dasharray:5 4,color:#475569&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;On the sixth, my old server answered instead of refusing. &lt;strong&gt;If the sixth request gets an answer, you have a backdoor with a nice schema.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The guru's last word
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9c7b0hyfrkc0bhibgyaz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9c7b0hyfrkc0bhibgyaz.png" alt="Chat between AI Wisdom and Amit. AI Wisdom: Start with one read-only tool that a team actually wants, such as deployment status or scoped log search. Make it tenant-aware and tested before you add another. Read-only does not mean low risk: the risk comes from the data and permissions the tool exposes. AI Wisdom: And if you have one assistant and one tool, use a direct integration. MCP pays off once the same tool is copied across several assistants. AI Wisdom: Understand the problem, and the solution becomes a small thing." width="560" height="518"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Go deeper
&lt;/h2&gt;

&lt;p&gt;My problem is fixed. The rest of running an MCP server in production is in the full guide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The complete five-step .NET build: stdio, tools, VS Code &lt;code&gt;mcp.json&lt;/code&gt;, and Streamable HTTP with JWT bearer auth&lt;/li&gt;
&lt;li&gt;What the 2026-07-28 revision removed (the &lt;code&gt;initialize&lt;/code&gt; handshake and &lt;code&gt;Mcp-Session-Id&lt;/code&gt;), so any replica can answer a request&lt;/li&gt;
&lt;li&gt;Routing and rate limiting by tool with the new &lt;code&gt;Mcp-Name&lt;/code&gt; header&lt;/li&gt;
&lt;li&gt;Long-running tools that survive dropped connections and redeploys&lt;/li&gt;
&lt;li&gt;A completion checklist to run before you hand the server to another team&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  More from AI Wisdom
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.aiwisdom.dev/?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=mcp-servers-building-tool-using-ai-agents" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1jmh663vvktp4bnv192l.png" alt="AI Wisdom, aiwisdom.dev: the engineering reference for production AI. 179 in-depth articles, 18 topic tracks, and mock exams for AI certifications." width="800" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://www.aiwisdom.dev/articles/agentic-systems/mcp-servers-building-tool-using-ai-agents?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=mcp-servers-building-tool-using-ai-agents" rel="noopener noreferrer"&gt;Read the full MCP guide on AI Wisdom →&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Neighbouring problems, in the same library:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://www.aiwisdom.dev/articles/security-engineering/owasp-agentic-top-10?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=mcp-servers-building-tool-using-ai-agents" rel="noopener noreferrer"&gt;Securing Agents: The OWASP Agentic Top 10 in Practice&lt;/a&gt;&lt;/strong&gt;: least agency, per-agent identity and policy gates in code&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://www.aiwisdom.dev/articles/prompt-engineering/prompt-injection?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=mcp-servers-building-tool-using-ai-agents" rel="noopener noreferrer"&gt;Prompt Injection: Attack Vectors and Defence in Production&lt;/a&gt;&lt;/strong&gt;: direct and indirect injection, and a defence-in-depth architecture&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://www.aiwisdom.dev/articles/ai-engineering/guardrails?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=mcp-servers-building-tool-using-ai-agents" rel="noopener noreferrer"&gt;Guardrails: Input/Output Safety in Production&lt;/a&gt;&lt;/strong&gt;: input, output, schema, tool and cost guardrails, layered&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://www.aiwisdom.dev/checklist?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=mcp-servers-building-tool-using-ai-agents" rel="noopener noreferrer"&gt;Production AI System Checklist&lt;/a&gt;&lt;/strong&gt;: a free 6-page PDF with 30 checks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Which Amit are you?&lt;/strong&gt; Open your MCP server, find a tool that takes a &lt;code&gt;service&lt;/code&gt; or &lt;code&gt;tenant&lt;/code&gt; argument, and look at where the caller's access to that value is checked. Reply with where yours is: "endpoint only", "inside the tool", or "nowhere I can find".&lt;/p&gt;

</description>
      <category>ai</category>
      <category>programming</category>
      <category>mcp</category>
      <category>security</category>
    </item>
    <item>
      <title>Designing RAG Systems That Actually Scale</title>
      <dc:creator>Amit Upadhyay</dc:creator>
      <pubDate>Sun, 09 Aug 2026 18:16:42 +0000</pubDate>
      <link>https://dev.to/aiwisdomdev/designing-rag-systems-that-actually-scale-59dh</link>
      <guid>https://dev.to/aiwisdomdev/designing-rag-systems-that-actually-scale-59dh</guid>
      <description>&lt;p&gt;Retrieval-Augmented Generation is the workhorse pattern of production AI right now, and it's also one of the easiest things to get subtly wrong. A RAG pipeline that performs great in a demo can degrade badly once real documents, real query volume, and real edge cases show up, often without throwing a single error.&lt;/p&gt;

&lt;p&gt;This post walks through the parts that actually decide whether a RAG system holds up in production: how you chunk documents, how you pick and commit to an embedding model, what your retrieval pattern actually returns, and where all of this quietly breaks down once you're past the demo stage.&lt;/p&gt;

&lt;p&gt;Read the full deep dive on AI Wisdom -&amp;gt; &lt;a href="https://www.aiwisdom.dev/articles/ai-engineering/designing-rag-systems-that-actually-scale" rel="noopener noreferrer"&gt;https://www.aiwisdom.dev/articles/ai-engineering/designing-rag-systems-that-actually-scale&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>machinelearning</category>
      <category>architecture</category>
    </item>
  </channel>
</rss>
