Adding Prompts in Multi-Server MCP
Explore the process of enhancing multi-server MCP systems by adding user-callable prompts on separate servers. Understand how to configure servers to expose unique prompts, update clients to discover and route prompt commands correctly, and execute complex workflows. This lesson equips you to build scalable AI systems with coordinated multi-server prompt orchestration.
Our agent is now capable of composing tools from two independent servers: the weather_server and the task_server, giving it a diverse, reactive skill set. However, its intelligence is currently limited to executing single actions. To elevate our agent into a true assistant, we need to empower the user with pre-defined, complex workflows using the MCP Prompt feature we explored earlier.
The next challenge is coordinating prompts across multiple MCP servers. How does the client discover prompts exposed by multiple servers, and how does it map user commands to the appropriate server and retrieve the corresponding prompt? In this lesson, we will define a prompt on each server and update the client to discover prompts across servers and route requests to the appropriate one, providing a consistent interface across multiple independent servers.
Expanding our multi-server scenario
Our multi-server agent can now access tools from both the weather and task management servers. In a previous lesson, we added the compare_weather prompt to weather_server to provide a reusable multi-step workflow. We can apply the same pattern to task_server. Instead of creating each task individually, a user could invoke a plan_trip prompt that instructs the agent to generate a standard travel checklist and save each item through the available task tools.
Adding prompts to multiple servers introduces a routing challenge. The client must determine which server exposes each prompt. How does it discover which prompts are exposed by weather_server and which are exposed by task_server? How does it route a prompt request to the server that exposes that prompt? The current client does not yet track prompt ownership across servers. It must discover prompts across servers and maintain the routing information needed to invoke them.
To solve this orchestration problem, our first step is to ensure that both of our servers are correctly configured to offer their unique prompts.
Adding prompts to our MCP servers
We will now enhance each of our existing servers, using the @mcp.prompt() decorator to implement these new, user-callable recipes.
Reviewing the weather_server_prompt
We will begin by adding compare_weather_prompt to our existing weather_server.py file. This is the same code we used while implementing prompts in our single-server module.
@mcp.prompt()def compare_weather_prompt(location_a: str, location_b: str) -> str:"""Generates a clear, comparative summary of the weather between two specified locations.This is the best choice when a user asks to compare, contrast, or see the difference in weather between two places.Args:location_a: The first city for comparison (e.g., "London").location_b: The second city for comparison (e.g., "Paris")."""return f"""You are acting as a helpful weather analyst. Your goal is to provide a clear and easy-to-read comparison of the weather in two different locations for a user.The user wants to compare the weather between "{location_a}" and "{location_b}".To accomplish this, follow these steps:1. First, gather the necessary weather data for both "{location_a}" and "{location_b}".2. Once you have the weather data for both locations, DO NOT simply list the raw results.3. Instead, synthesize the information into a concise summary. Your final response should highlight the key differences, focusing on temperature, the general conditions (e.g., 'sunny' vs 'rainy'), and wind speed.4. Present the comparison in a structured format, like a markdown table or a clear bulleted list, to make it easy for the user to understand at a glance."""
Enhancing the task_server
Next, we will add a plan_trip_prompt to our task_server.py. It will guide the agent’s LLM to first use its general knowledge to create a travel plan, and then use the existing add_task ...