cd /news/ai-agents/build-a-custom-ai-coding-agent-with-… · home topics ai-agents article
[ARTICLE · art-127903] src=promptcube3.com ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

Build a custom AI coding agent with Claude Code and MCP

Claude Code, Anthropic's terminal-based CLI coding agent, can be extended with Model Context Protocol (MCP) servers to let the agent query live data such as a PostgreSQL database, according to a hands-on walkthrough. The setup requires Node.js 18 or higher (the author ran v20.11.0) and installs via `npm install -g @anthropic-ai/claude-code`, with a 30-minute debugging session costing about $4.20 in API credits. The author reported the agent traced a NestJS circular dependency between UserService and AuthService in 45 seconds by running `grep -r "UserService" src/`, and self-corrected a hallucinated `npm run clean:cache` command to `npm run clear:cache` after reading the resulting error.

read5 min views2 publishedSep 12, 2026
Build a custom AI coding agent with Claude Code and MCP
Image: Promptcube3 (auto-discovered)

Forget the hype about "autonomous agents" for a second. I spent last Thursday fighting with a legacy TypeScript codebase that had zero documentation and a dependency tree from 2019. Standard Copilot autocomplete wasn't cutting it because the context window couldn't see the weird side effects happening in three different directories. I needed a tool that could actually run shell commands, read files, and iterate on its own mistakes without me copy-pasting logs back and forth.

That is where Claude Code and the Model Context Protocol (MCP) actually change the game. Instead of a chat box, you get a CLI that lives inside your terminal and can actually touch your filesystem.

Setting up Claude Code on a Mac or Linux box #

If you haven't installed it, you'll need Node.js 18 or higher. I'm running v20.11.0.

Run this to get the CLI:npm install -g @anthropic-ai/claude-code

Then initialize it:claude

It will ask you to authenticate with your Anthropic account. Be warned: this isn't free. It eats tokens fast because it's constantly reading your file structure to understand where it is. On a medium-sized project, a 30-minute debugging session cost me about $4.20 in API credits. That's the price for not having to manually explain the folder structure for the tenth time.

Connecting an MCP server for real-time data #

The real power isn't the LLM; it's the "hands" you give it via MCP. By default, Claude can read files. But what if you want it to query your actual database to see why a specific user record is corrupted?

I used the PostgreSQL MCP server to let the agent inspect my schema. Here is how you add a server to your config (usually located in ~/Library/Application Support/claude-code/config.json on Mac):

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/my_dev_db"]
    }
  }
}

Once you restart the CLI, you can literally tell the agent: "Check the users table and tell me why the email for ID 402 is null." It will execute the SQL, read the result, and then tell you which line of code in your API is failing to validate the input. This closes the loop between "guessing" and "knowing."

Solving a "Circular Dependency" bug without losing my mind #

I hit a wall last week with a Circular dependency error in a NestJS project. The logs were vague. Instead of hunting through 40 files, I gave Claude Code a specific set of instructions.

I typed:Find the circular dependency between UserService and AuthService, trace the imports, and suggest a refactor using a forward ref or a shared module.

The agent did something interesting. It didn't just suggest code. It ran grep -r "UserService" src/ to map every single import. It found a hidden import in a user.entity.ts file that I had completely forgotten about.

The fix it suggested was a simple move of the interface to a types.ts file.

// Before: circular import
import { UserService } from './user.service'; 

// After: import from a neutral leaf node
import { UserType } from './types';

It took 45 seconds. Doing that manually would have taken me 20 minutes of clicking through tabs.

When the agent hallucinates a command #

It's not perfect. At one point, the agent tried to run npm run clean:cache, which doesn't exist in my package.json. It got a command not found error.

The wild part is how it handles failure. It read the error, ran cat package.json, realized it had hallucinated the script name, and then corrected itself to npm run clear:cache.

If you find the agent looping on a mistake, don't keep saying "try again." Give it a hint. Tell it: "Check the scripts section of package.json first." This forces it to ground its logic in the actual filesystem before guessing.

Why you need an AI technology community like PromptCube #

Working in a vacuum is the slowest way to learn. I used to spend hours tweaking a prompt to get the LLM to stop adding "Here is the code..." fluff to every response. Then I joined the PromptCube community and realized people had already solved this using specific system prompts and versioned templates.

PromptCube isn't just a place to share prompts; it's where you find out which MCP servers actually work and which ones crash your terminal. When you join, you get access to a collective brain of devs who are hitting the same "context window full" walls you are.

You can dive into different Workflows to see how other seniors are chaining Claude Code with GitHub Actions or using it for automated PR reviews. It turns the "trial and error" phase of AI coding into a "copy and refine" phase.

Comparing the local AI experience #

I've tried Cursor, Windsurf, and Claude Code. Here is the raw truth from my experience:

| Feature | Cursor/Windsurf | Claude Code (CLI) |

| :--- | :--- | :--- |

| Context | Great (Index-based) | Better (Real-time shell access) |

| Execution | Terminal is separate | Terminal is the interface |

| Speed | Fast UI | Fast iteration on file changes |

| Risk | Low (You accept changes) | Moderate (It can run rm -rf if you're not watching) |

If you want a cozy IDE experience, stay with Cursor. If you are a terminal rat who wants an agent that can actually "operate" the machine, go with the CLI.

If you're starting today, don't overcomplicate it. Use this setup:

  1. Claude Code for heavy lifting and refactoring.

  2. MCP Postgres/Filesystem servers to give the AI sight.

  3. PromptCube to stop guessing which prompts work for complex TypeScript logic.

Stop treating the AI like a search engine. Treat it like a junior dev who is incredibly fast but occasionally forgets where he is. Give it tools, give it a restricted scope, and for god's sake, keep your git commits frequent so you can revert when it decides to "optimize" your entire auth flow into a single 500-line function.

Next Paul Ford is right that AI makes it too easy to do a job badly →

── more in #ai-agents 4 stories · sorted by recency
── more on @claude code 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/build-a-custom-ai-co…] indexed:0 read:5min 2026-09-12 ·