Adding Prompts in Single-Server MCP
Explore how to add user-callable prompts in a single-server MCP setup that enable reusable workflows. Learn to create prompt templates on the server for tasks such as comparing weather in two cities, updating the client to list and invoke these prompts, and managing prompt arguments. This lesson enhances agent capabilities by bridging user commands to multi-step LLM tool usage, improving interaction and task orchestration.
The agent can now use tools to perform actions such as fetching current weather. We should also give users a reusable way to initiate a multi-step task, such as comparing the weather in two cities. MCP prompts provide a reusable, server-defined message template for this kind of workflow. An MCP prompt is a predefined message template exposed by the server. The prompt function runs on the server and returns the messages for the client to use. It does not invoke get_weather or call the language model directly. The client sends the prompt messages to the model, which can then request tool calls through the agent runtime. In this lesson, we’ll add a prompt to the weather server and update the client so users can discover and invoke it.
Introduction to prompts
Tools expose discrete actions that an agent can invoke, while MCP prompts provide a reusable, discoverable way to package instructions for recurring tasks. An MCP prompt is a server-defined message template that a client can retrieve and present to the model. The developer defines the prompt content and any parameters it accepts. When a user selects a prompt, the client retrieves its generated messages from the server and sends them to the model. This lets users initiate a multi-step workflow without rewriting the full instructions each time.
Tools vs. prompts: A critical distinction
The most important difference between tools and prompts lies in who initiates them. Understanding this is key to designing effective agentic systems:
Tools: These are designed for the agent to call autonomously. The LLM decides when to use a tool like
get_weatherbased on its reasoning about the conversational context to achieve a goal.Prompts: These are designed for the user to initiate directly. The user selects a prompt like
compare_weather_promptfrom a list of available options (e.g., a slash command), provides the necessary arguments, and the client then uses the prompt’s template to guide the LLM.
Scenario: Expanding our weather agent’s capabilities
Our weather agent currently handles one defined task: retrieving the current weather for a location. Now consider a request that compares two locations: “How does the weather in London compare to Paris today?” The agent can already invoke get_weather once for each city. An MCP prompt does not add new tool capabilities. Instead, it provides a reusable, discoverable set of instructions that can define how the comparison should be performed and presented, so users do not need to provide the full instructions each time. To make this workflow reusable through the client, we will add an MCP prompt that users can discover and invoke.
In this part of the lesson, we’ll define a prompt that takes two cities as input and returns a prompt string instructing the assistant to compare the weather of both cities and show a structured comparison.
Adding a prompt to the weather_server
We can support this workflow by defining an MCP prompt on the server. We will update weather_ ...