MODULE 04

AGENTS AND RAG

Understand AI agents, retrieval-augmented generation, and how to connect Claude to external data sources.

Learning objectives

  • > Distinguish between chatbots and AI agents
  • > Understand retrieval-augmented generation (RAG) and why it matters
  • > Learn the basics of Model Context Protocol (MCP)
  • > Configure Claude Code with an MCP server to access local files

Before you start

Agents and RAG introduce a new failure mode: errors that compound across pipeline stages. When Claude delegates work to subagents, mistakes in early steps become assumed facts in later ones. The concept below explains how this works and what to do about it.

Read: working with subagents — compounding errors and verification →

Key concepts

Chatbots vs. agents

Chatbot: Responds to prompts using only its training data. Can't take actions, access external information, or modify files. Like talking to someone who can only answer from memory.

Agent: Can use tools, access data sources, and take actions. Breaks complex tasks into steps, decides what tools to use, and executes multi-step plans. Claude Code is an agent - it can read files, run commands, and make changes to your projects.

Retrieval-augmented generation (RAG)

RAG combines a language model with external data retrieval. Instead of relying only on training data, the model can search relevant documents and include that information in its response. This reduces hallucinations and lets the model work with current, domain-specific information it was never trained on.

How RAG works

A typical RAG pipeline:

  1. 1. Query: User asks a question
  2. 2. Retrieve: System searches a document collection for relevant passages
  3. 3. Augment: Retrieved passages are added to the prompt as context
  4. 4. Generate: The model generates a response using both the question and retrieved context

Model Context Protocol (MCP)

MCP is an open standard for connecting AI models to external tools and data sources. An MCP server provides capabilities (like file access, database queries, or web searches) that Claude can use. Think of MCP servers as plugins that extend what Claude can do.

MCP server types

Common MCP servers include:

  • > Filesystem: Read and write files in specified directories
  • > Database: Query databases (SQLite, PostgreSQL, etc.)
  • > Web: Fetch and parse web pages
  • > Search: Search engines, vector databases for semantic search
  • > Custom: Any tool or API you want Claude to access

EXERCISE

GOAL: Set up an MCP server that gives Claude controlled access to a document folder, enabling RAG-style workflows.

01 Understand the default file access

Claude Code can already read and write files in your current working directory. MCP extends this by:

  • > Giving access to specific directories you configure
  • > Enabling more structured queries (search within files, list by criteria)
  • > Supporting additional data sources beyond the filesystem

02 Create a research documents folder

Open your terminal, launch Claude Code, and ask it to set up the folder:

terminal
claude
claude code
Create a folder called research-docs in my home directory with three realistic sample documents I can use to test RAG queries: a city budget summary for fiscal year 2024 with department-level breakdowns, school board meeting minutes from January 2024, and quarterly crime statistics for Q4 2024. Use believable fictional numbers and names throughout.

03 Configure MCP in Claude Code

Ask Claude to set up the MCP filesystem server configuration. Stay in the same session:

claude code
Set up MCP filesystem server access to my ~/research-docs folder. Create or update ~/.claude/claude_desktop_config.json with the correct configuration. Use the actual path to my research-docs directory (not a placeholder). Tell me what you wrote so I can verify it.

VERIFY: Check that the path in the config file matches your actual username and home directory. Claude should detect this automatically, but confirm the path before moving on.

04 Install the MCP filesystem server

The server will be installed automatically when needed, but you can pre-install it:

terminal
npm install -g @modelcontextprotocol/server-filesystem

05 Restart Claude Code and verify

Start a new Claude Code session:

terminal
claude

Ask Claude to list what MCP tools are available:

prompt
What MCP servers and tools do you have access to?

You should see the filesystem server listed with access to your research-docs folder.

06 Query your documents

Now test RAG-style queries against your document collection:

prompt
Based on my research documents, what was the total city budget for 2024 and what percentage went to education?
prompt
Search my documents for any mentions of school start times. What's the current status of that discussion?
prompt
Compare the crime statistics to the budget allocations for public safety. Is there any correlation worth investigating?

07 Build a research workflow

Use your document collection to draft a story:

prompt
I'm writing a story about how the city is allocating resources to address public safety. Using my research documents, help me outline the key facts I should include and identify any gaps where I need more information.

Checkpoint

Self-check: Make sure you can answer these before moving on.

  • ? What is the main difference between a chatbot and an AI agent?
  • ? What problem does RAG solve that pure language models can't?
  • ? What does MCP stand for and what does it enable?
  • ? Why might you want to limit which folders an MCP server can access?

Resources

  • [DOCS] Model Context Protocol - Official MCP documentation and specification
  • [REF] Claude Code documentation - MCP configuration reference
  • [REPO] MCP Servers repository - Collection of official and community MCP servers
  • [ARTICLE] Introducing the Model Context Protocol - Anthropic's announcement explaining MCP

Troubleshooting

MCP server doesn't appear in Claude Code

Check that your config file is valid JSON (no trailing commas, proper quoting). Use cat ~/.claude/claude_desktop_config.json to verify the contents. Restart Claude Code after making changes.

"Permission denied" accessing files

The MCP server can only access directories you've explicitly configured. Check that the path in your config matches the actual directory, and that your user has read permission on those files.

Server fails to start

Make sure Node.js and npm are installed and in your PATH. Try running the server manually to see error messages: npx @modelcontextprotocol/server-filesystem ~/research-docs

Claude doesn't seem to use the documents

Be explicit in your prompts: "Search my research documents for..." or "Using the files in my research folder...". Claude may not automatically search documents unless asked.