Source: [Skills, MCP, RAG and Memory: How an AI Agent Investigates a 500 Error](https://treenodes.com/articles/skills-mcp-rag-memory-500-error/)

This Markdown version is generated from the public page. Visit the source for interactive examples and full-size visuals.

[All writing](https://treenodes.com/articles/)

Published 22 September 2026 · Applied AI · 6 min read

# Skills, MCP, RAG and Memory: How an AI Agent Investigates a 500 Error

A post will not publish. Follow one 500 error from the server logs to a missing database update, and see how skills, MCP, RAG and memory support the investigation.

Written by [Nermien Barakat](https://treenodes.com/articles/by/nermien-barakat/)  · Systems & Applied AI Architect

![A systems architect follows evidence from a failed publishing request to a missing database update, with four sources supporting the investigation.](https://treenodes.com/assets/articles/skills-mcp-rag-memory-500-error-hero-treenodes.webp?v=d014e3245efb)

One visible failure, four different ways to support the investigation. The example below is fictional.

Imagine you finish writing a post and click **Publish**. Instead of seeing your article, the screen displays:

> **500 — Internal Server Error**

You ask an AI agent: “Can you find out why publishing is failing?”

A [500 response](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/500) tells us that the server encountered an unexpected condition that prevented it from completing the request. It does not identify the cause. That requires investigation.

The model may understand common server problems. But it needs evidence from your application to explain this particular failure.

You could give it source code, logs, documentation and previous bug reports. For a small task, supplying the relevant material directly may be enough. In a larger system, the challenge is selecting the information needed at each step.

This is where **skills, MCP, RAG and memory** can help. These are different kinds of support, not four compulsory stages. They can work together, overlap, or be used separately.

For the wider architecture, start with [How AI systems fit together](https://treenodes.com/articles/how-ai-systems-fit-together/).

## The investigation at a glance

Diagram: From a 500 error to a verified correction Four independent contributions support the AI agent: skills supply guidance, MCP tools provide logs and database records, RAG retrieves the required database update, and memory offers a lead to check. A failed publishing request starts the investigation. Current evidence confirms the code and database mismatch. Apply the matching migration, then verify that the test post is saved and displayed. · From a 500 error to a verified correction · Four independent contributions support the AI agent: skills supply guidance, MCP tools provide logs and database records, RAG retrieves the required database update, and memory offers a lead to check. A failed publishing request starts the investigation. Current evidence confirms the code and database mismatch. Apply the matching migration, then verify that the test post is saved and displayed. · Skills · How should Iinvestigate? · Follow the debuggingprocedure · Guidance · MCP · How can I inspect thesystem? · Use connected tools · Logs and databaserecords · RAG · What should thisrelease include? · Retrieve the releasedocumentation · Required databaseupdate · Memory · Have we seen a similarissue? · Recall an earliermigration issue · A lead to check · Click Publish · 500 · Internal Server Error · AI agent investigates · CONFIRMED CAUSE · New code expects a database field · The required migration is missing · CORRECTION · Apply the matching migration · through the deployment process · VERIFICATION · Publish the test post again · Confirm it is saved and displayed

Four kinds of support feed one investigation. The dashed memory connection is a lead to check; current evidence establishes the cause. Correction and verification follow separately.

[Dark PNG](https://treenodes.com/downloads/ai-agent-500-error/diagram-overview-dark.png)[Light PNG](https://treenodes.com/downloads/ai-agent-500-error/diagram-overview-light.png)[Mermaid source](https://treenodes.com/downloads/ai-agent-500-error/diagram.mmd)

**Read the diagram as text**

Click Publish**500 — Internal Server Error**

Four contributions to the investigation

**Skills**

**How should I investigate?**Follow the debugging procedureGuidance → AI agent

**MCP**

**How can I inspect the system?**Use connected toolsLogs and database records → AI agent

**RAG**

**What should this release include?**Retrieve the release documentationRequired database update → AI agent

**Memory**

**Have we seen a similar issue?**Recall an earlier migration issueA lead to check → AI agent

**AI agent investigates**

1.  **Confirmed cause**New code expects a database field  
    The required migration is missing
2.  **Correction**Apply the matching migration  
    through the deployment process
3.  **Verification**Publish the test post again  
    Confirm it is saved and displayed

## Skills: a procedure to follow

A skill packages instructions for a particular kind of work. It can also include scripts, templates and reference material. Compatible agents load the detailed instructions when the task calls for them—an approach known as [progressive disclosure](https://agentskills.io/home).

For our publishing error, a troubleshooting skill might tell the agent to:

1.  Reproduce the failure with a sample post.
2.  Find the server logs for the failed request.
3.  Check recent application and database changes.
4.  Compare the evidence with the system’s expected behaviour.
5.  Verify the correction by publishing again.

The skill can also explain when to stop and ask for help, such as when the evidence is incomplete or a proposed change exceeds the agent’s permissions.

This gives the investigation structure. But an instruction to inspect the logs still needs a way to reach them.

## MCP: access to tools and information

[Model Context Protocol, or MCP](https://modelcontextprotocol.io/docs/learn/architecture), provides a standard interface between an AI application and servers that expose tools and data. The application manages the connections, and the servers provide the available capabilities.

In our example, connected tools could let the agent read application logs, inspect deployment records and check the database structure.

The agent finds two useful facts:

-   The failed request produced a database error: a field called `published_at` does not exist.
-   Publishing failures began after the latest application release.

The first finding identifies the immediate failure. The second gives the agent a change to investigate.

MCP makes these capabilities available through a common interface. The underlying integrations still need to be implemented, and access depends on the configured permissions. Direct API connections can also provide tools.

## RAG: relevant documentation

[Retrieval augmented generation, or RAG](https://docs.langchain.com/oss/python/deepagents/retrieval), retrieves relevant information and supplies it to the model to help generate an answer. That information can come from documents, databases or other knowledge sources.

The agent now knows that a database field is missing. It needs to establish why the application expects that field.

The retrieval system finds the release notes and deployment instructions for the version that is running. They explain that the latest release records when a post is published. This requires the new `published_at` field and a database migration—a controlled update to the database structure.

The agent now has a specific requirement to check: **was that migration applied to the database used by the application?**

RAG does not require every document to be stored in a vector database. Retrieval can use exact terms, similarity of meaning, or both. Here, matching the correct application version and migration identifier matters.

## Memory: useful findings from earlier work

[Memory](https://docs.langchain.com/oss/python/concepts/memory) is information the application retains for later use. It can include user-provided facts, progress on an unfinished task and findings from previous investigations.

Suppose an earlier investigation recorded that an application release succeeded while its database migration step was skipped.

That gives the agent a useful lead. It checks the current deployment record and the migration history of the database serving the application.

In our fictional example, the current records confirm a mismatch: the running application expects `published_at`, but the database has neither that column nor a record of the required migration.

The earlier finding suggested what to check. The current records establish why publishing fails. They do not yet explain why the migration is missing.

Once the issue is resolved, the application can retain the verified finding, including the affected release, the correction and the checks performed. That gives a future investigation a useful starting point.

## From explanation to a verified correction

The agent can now report:

> Publishing fails because the running application writes to a database field that is missing. The matching migration is absent from that database’s migration history.
> 
> Apply the matching migration through the normal deployment process, then verify publishing.

In this example, the team applies the migration and publishes the sample post again. The request succeeds, the post is saved with its publication time, and the published page displays correctly.

| Mechanism | Its role in the investigation |
| --- | --- |
| Skill | Guided the troubleshooting procedure. |
| MCP | Provided access to logs, deployment records and database information. |
| RAG | Retrieved the applicable release and migration documentation. |
| Memory | Recalled a previous finding worth checking. |

These mechanisms can overlap. An MCP tool might search documentation or retrieve saved investigation notes. Memory can itself use retrieval to find relevant information.

## Try it: diagnose the publishing failure

Use a small, fictional evidence pack to check whether an explanation follows from the records.

**How to try it.** Copy the complete prompt into a new chat, or work through it yourself. Everything needed is included. This exercise uses supplied records; it does not connect to a live system or configure MCP, retrieval or memory.

Trace a 500 error from the evidence

Included file: ai-agent-500-error-evidence.txt

[Download file](https://treenodes.com/downloads/practice/ai-agent-500-error-evidence.txt)

**Full prompt**

```
TASK
Investigate a fictional publishing failure using only the evidence below.
Explain the likely cause, what each record proves, and how a correction
should be verified. Do not perform changes or claim a test has run.

EVIDENCE
[E1] POST /posts/publish returns HTTP 500 for test post P42.
[E2] The matching server log reports that column published_at is missing.
[E3] The failed request was served by release R12. Its publishing code
writes the publication timestamp to posts.published_at.
[E4] The R12 deployment guide requires migration M12, which creates that column.
[E5] The database used by the running application has migrations M1–M11.
Its posts table does not contain published_at.
[E6] A saved note from an earlier incident says an application release
succeeded while its database migration step was skipped.

OUTPUT
1. A short diagnosis citing E1–E6 where relevant.
2. Separate current evidence from the historical lead.
3. The correction to review and the checks that would confirm it worked.
4. Identify where a skill, MCP-connected tools, RAG and memory could help.

VARIATION
If E5 were unavailable, explain what remains unverified and what to inspect next.
```

### What your result should show

-   E2–E5 connect the failed request to release R12 and establish that its required column and migration record are missing from the database. E1 alone does not establish the cause.
-   E6 is a historical lead. The current records support the code/database mismatch independently of it, but do not explain why the migration is missing.
-   The proposed correction uses the matching migration and verifies the successful request, saved publication time and displayed post. The answer does not claim those checks have already run.

### Change one condition

Remove E5. The error still identifies a missing column, but the migration history is unverified. Request the current database structure and migration history before declaring the migration absent.

A useful AI investigation shows what the evidence supports, what remains uncertain and how the correction should be checked.

READING PATH · 2 OF 5

## Designing an AI system

Choose the parts, define the task, give the agent useful context, then apply it to a changing design.

[Next: Giving AI a job description Turn that design into a task contract with inputs, limits and an output schema.](https://treenodes.com/articles/giving-ai-a-job-description/) [View the complete reading path](https://treenodes.com/articles/reading-paths/#ai-system-design)

1.  [01 How AI systems fit together](https://treenodes.com/articles/how-ai-systems-fit-together/)
2.  02 Skills, MCP, RAG and Memory: How an AI Agent Investigates a 500 Error
3.  [03 Giving AI a job description](https://treenodes.com/articles/giving-ai-a-job-description/)
4.  [04 Give AI agents a design reference](https://treenodes.com/articles/design-references-for-ai-agents/)
5.  [05 What is Astra, and when would I use it?](https://treenodes.com/articles/astra-and-the-moment-the-brief-changes/)

**REFERENCES AND FURTHER READING  — 5 sources**

1.  [500 Internal Server Error](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/500)  — MDN Web Docs  — What a 500 response establishes and why the underlying cause needs investigation.
2.  [Agent Skills overview](https://agentskills.io/home)  — Agent Skills  — Reusable instructions, supporting resources and progressive disclosure.
3.  [Architecture overview](https://modelcontextprotocol.io/docs/learn/architecture)  — Model Context Protocol  — The AI application, its clients and the servers that expose capabilities.
4.  [Retrieval](https://docs.langchain.com/oss/python/deepagents/retrieval)  — LangChain  — Retrieving information from documents and existing knowledge systems.
5.  [Memory overview](https://docs.langchain.com/oss/python/concepts/memory)  — LangChain  — Retained facts, experiences and context that can be used in later interactions.
