Integrating Multiple MCP Servers to an OpenAI Agent
Introduction & Overview
Welcome back! In the previous lesson, you learned how to make your agent more efficient by enabling tool caching when connecting to a single MCP server. This allowed your agent to quickly access the list of available tools, reducing latency and improving the user experience, especially during multi-turn conversations.
Now, let’s take the next step in building more capable and autonomous agents. In real-world scenarios, you often need your agent to handle tasks that go beyond the scope of a single MCP server. For example, imagine an agent that not only manages a shopping list but can also place orders for products from suppliers. To achieve this, you need to connect your agent to multiple MCP servers, each providing a different set of tools.
In this lesson, you will learn how to set up and coordinate multiple MCP servers, allowing your agent to solve more complex tasks by using tools from different services — all within a single conversation.
Revisiting The Basics Of MCP Server Integration
Before we dive into multi-server integration, let’s quickly revisit how an agent connects to a single MCP server. In the previous lesson, you saw that an MCP server is a process that exposes a set of tools — actions the agent can use to help answer user queries. The agent connects to the MCP server, fetches the list of available tools (optionally caching them), and then uses these tools as needed to fulfill user requests.
This single-server setup works well for focused tasks, such as managing a shopping list. However, as your agent’s responsibilities grow, you may want it to interact with several different services. For example, one MCP server might handle shopping list management, while another could handle product ordering. By connecting to multiple MCP servers, you can give your agent access to a much broader set of capabilities, making it more useful and autonomous.
Launching And Configuring Multiple MCP Servers
To connect your agent to more than one MCP server, you can use the OpenAI Agents SDK’s MCPServerStdio class for local subprocess servers, the MCPServerSse class for remote HTTP-based servers, or even combine both types in a single agent. Each server instance should be configured individually, and you can assign a unique name to each for easier identification during debugging or logging.
For example, suppose you have two local MCP servers: one for managing a shopping list (list/mcp_server.py) and another for ordering products (products/mcp_server.py). You can launch both servers like this:
Here, each MCPServerStdio instance is configured with the command to run the server, a descriptive name, and the cache_tools_list parameter set to True for efficiency.
