Using MCP Prompts in a Client Application

This section focuses on how to define and access MCP resources effectively. It also covers creating reusable prompt templates to streamline your client applications.

4 audio · 2:04

Nortren·

How do you implement list prompts in an MCP client?

0:30
The final step in building an MCP client is implementing prompt functionality. The list prompts method is straightforward. It calls the session's list prompts function, awaits the result, and returns the prompts to your application. From there, your code can show the list to the user, perhaps as items in a slash command menu. The pattern is exactly the same as list tools and list resources: get the session, call the corresponding method, return the result. This consistency is one of the things that makes MCP clients pleasant to write, because once you know the pattern for one primitive, the others follow the same shape.

How do you fetch an MCP prompt with variable interpolation?

0:31
The get prompt method is more interesting because it handles variable interpolation. When you request a prompt, you provide an arguments dictionary that gets passed to the prompt function as keyword arguments. For example, if your server has a format document prompt that expects a doc ID parameter, the arguments dictionary would contain doc ID mapped to a value like plan dot markdown. The session sends both the prompt name and the arguments to the server, the server runs your prompt function with those keyword arguments, and you get back the fully interpolated list of messages, ready to send to Claude.

How do users discover and trigger MCP prompts in a CLI?

0:29
Once prompts are implemented in the client, you test them through the command line interface. When the user types a slash, the available prompts appear as commands in a menu. Selecting a prompt like format will then prompt the user to choose from available documents. After they pick a document, the client sends the complete, interpolated prompt to Claude. The model receives both the formatting instructions and the document ID, then uses the available tools to fetch and process the content. From the user's point of view, it is just two quick selections, but underneath, the prompt and tool primitives are working together.

What is the end-to-end workflow for building reusable MCP prompts?

0:34
Prompts define a set of user and assistant messages that clients can use. They should be high-quality, well-tested, and relevant to your MCP server's purpose. The workflow is as follows. First, you write and evaluate a prompt that is relevant to your server's functionality. Second, you define the prompt in your MCP server using the mcp prompt decorator. Third, clients can request that prompt at any time. Fourth, arguments provided by the client become keyword arguments in your prompt function. And fifth, the function returns formatted messages ready for the model. This system creates reusable, parameterized prompts that maintain consistency while still allowing customization through variables.