...

/

Adding Resource Feature to the MCP Application

Adding Resource Feature to the MCP Application

Learn how to define and retrieve MCP resources to enhance client-side context and interactivity.

While tools enable the assistant to perform actions and prompts shape its reasoning, there are scenarios where we need a structured mechanism to provide contextual information, such as lists, reference data, or background details, within the model’s workflow. This is where resources are essential.

In MCP, resources are passive data objects that the client explicitly loads and utilizes. For example, the assistant might use a file containing suggested Wikipedia topics to recommend areas for further exploration. Unlike tools and prompts, resources do not execute logic or generate dynamic outputs. Instead, they are retrieved by the client and used as static data.

In this lesson, we define a file-based resource on the server and demonstrate how to modify the client to fetch and use it interactively.

What are the resources in MCP?

Resources in MCP are named, structured data objects exposed by the server but retrieved and used entirely by the client. They’re useful when the assistant needs reference information that doesn’t change frequently and doesn’t require computation, like recommended topics, glossary terms, or API keys.

Unlike tools (which execute functions) or prompts (which generate templates), resources contain no logic or instructions. Instead, the client retrieves them using session.read_resource() and determines how to use them—whether feeding them into the LLM, displaying them to the user, or integrating them into UI elements.

Press + to interact
MCP resources workflow
MCP resources workflow

Resources are typically used to:

  • Provide contextual background (e.g., a list of predefined topics).

  • Inject static configuration or preferences.

  • Support client-side filtering, choices, or menus.

Let’s implement a simple resource that loads topic suggestions from a local file.

Creating the resource file

Before defining a resource on the server, we must prepare the content it will expose. In our case, we ...