When to Use Dynamic Tools
Use dynamic tools when you want users to control which capabilities are available. This helps reduce agent bloat by allowing you to assign tools to an agent on demand rather than deploying lots of agents where each one has a different permutation of tools. For agents that should always have specific capabilities, pass the tools directly via the agent’stoolkits parameter.  This works for both MCP tools and MeshAgent toolkits. See Using OpenAI Connectors & MCP Servers for examples of creating agents with always-on MCP toolkits.
How Dynamic Tools Work
Dynamic tool selection requires three components: (1) deployed services that expose MCP Servers or OpenAI Connectors, (2) an agent configured to accept MCP tools, and (3) a UI that displays available services and lets users toggle them on/off.1. Deployed Services
First you need to package and deploy a project or room service for the MCP Servers or OpenAI Connectors you want the agent to have access to. You can do this by defining a service yaml file and creating the service using the MeshAgent CLI (see examples below).2. Agent with MCPToolkitBuilder
Your agent needs to be configured with MCPToolkitBuilder() so it can accept and use the MCP tools that users select.
The CLI ChatBot does this automatically:
bash
--mcp flag adds MCPToolkitBuilder() for you behind the scenes.
Note: The CLI ChatBot also supports other dynamic toolkits likeFor custom ChatBots, you must add it manually:--web-searchand--storagethat work similarly. They add toolkit builders so users can enable/disable these capabilities per message.
python
3. UI configured to discover and display services
Your UI needs to discover and display available services so users can toggle them on/off. MeshAgent Studio handles this automatically - when you open a room with a ChatBot that has MCP enabled, it queries for available services and shows them as selectable tools. If you’re building a custom UI, you’ll need to implement similar discovery and selection functionality.How They Work Together
When a user sends a message:- The UI displays available services and passes the user’s selected services to the ChatBot
 - The ChatBot’s 
MCPToolkitBuildercreates tool definitions with the server endpoints - These definitions are sent to OpenAI’s Responses API via the 
OpenAIResponsesAdapter - OpenAI connects to each MCP server and discovers what tools they offer
 - The agent can now call those tools, and the adapter handles execution and returning the results
 
Important: MeshAgent Studio + CLI ChatBot with --mcp flag handles the UI hooks and MCP setup automatically. This lets you quickly test dynamic MCP tools without writing any UI code or creating a custom agent yourself. When you’re ready to customize, you can build your own agent or UI by implementing the same pattern.
Example 1: Create a MeshAgent Service for an MCP Server
Let’s deploy the DeepWiki MCP Server which provides tools for reading public GitHub repositories (no authentication required). Step 1: Create the Service YAMLyaml
myroom, select the chatbot, turn on MCP tools, and toggle “mcp-deepwiki”. Then you can ask questions like “What’s in the README for pydantic-ai?”. If you don’t want to use the DeepWiki tools anymore you can simply toggle them off.
Example 2: Create a MeshAgent Service for an OpenAI Connector
OpenAI Connectors require OAuth authentication. You’ll need to register an OAuth client with the service provider first. See OpenAI’s documentation for additional instructions. Once you register your OAuth API client you can create and deploy the service just like we did for the MCP Server. Step 1: Create the Service YAMLRelated Topics
- Using OpenAI Connectors & MCP Servers: Learn how to create agents with always-on toolkits
 - Secrets: Securely manage OAuth credentials
 - Packaging Services: Service YAML reference
 - Deploying Services: Deployment options and strategies