Adding Prompts in Multi-Server MCP
Learn how to implement user-callable MCP prompts on multiple servers and update a client to discover and execute these guided workflows.
Our agent is now capable of composing tools from two independent servers: the weather_server
and the task_server
, giving it a diverse, reactive skillset. 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 challenge now becomes one of orchestration. How does our central client discover prompts that are distributed across different servers? How does it manage user commands and route them to the correct server for execution? In this lesson, we will solve this by equipping each of our servers with its own unique prompt and upgrading our client to act as a central coordinator, creating a seamless and powerful user experience from multiple, independent sources.
Expanding our multi-server scenario
Our multi-server agent is already quite capable, able to access tools from both the weather and task management servers. Furthermore, in a previous lesson, we saw how a prompt like compare_weather
can enhance our weather_server
by providing a guided, multi-step workflow. Now, let’s expand on this concept. What if our task_server
could also offer its own complex workflow? Imagine that a user wants to plan a trip. Instead of adding each to-do item manually, they could invoke a single plan_trip
prompt that automatically generates and saves a standard travel checklist.
This enhancement, while powerful, presents a new architectural challenge. With prompts now available on both servers, our client is faced with a routing problem. How does our client discover that one prompt lives on the weather_server
and the other on the task_server
? How does it know which server to query when a user invokes a specific prompt? The simple client we have now is unequipped to handle this; it needs to become a true orchestrator.
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 ...