Search⌘ K
AI Features

Adding the Resource Feature to the MCP Application

Explore how to implement resource features in MCP applications by creating static data objects accessible to clients. Learn to register file-based resources on the server and fetch them interactively on the client side to provide AI agents with essential contextual information like topic suggestions or reference data, enabling richer and more flexible natural language interactions.

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, resources don’t perform actions; they simply provide data. The client retrieves them and decides how to use that 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 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 reference documents.

Unlike tools (which perform actions) or prompts (which provide instructions for the model), resources simply provide data. 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.

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 want the assistant to recommend interesting Wikipedia topics that users might explore.

To support this, we’ll create a simple text file named suggested_titles.txt. ...