|
| 1 | +--- |
| 2 | +title: Dynamic MCP |
| 3 | +linkTitle: Dynamic MCP |
| 4 | +description: Discover and add MCP servers on-demand using natural language with Dynamic MCP servers |
| 5 | +keywords: dynamic mcps, mcp discovery, mcp-find, mcp-add, code-mode, ai agents, model context protocol |
| 6 | +weight: 35 |
| 7 | +params: |
| 8 | + sidebar: |
| 9 | + badge: |
| 10 | + color: green |
| 11 | + text: New |
| 12 | +--- |
| 13 | + |
| 14 | +Dynamic MCP enables AI agents to discover and add MCP servers on-demand during |
| 15 | +a conversation, without manual configuration. Instead of pre-configuring every |
| 16 | +MCP server before starting your agent session, clients can search the |
| 17 | +[MCP Catalog](/manuals/ai/mcp-catalog-and-toolkit/catalog.md) and add servers |
| 18 | +as needed. |
| 19 | + |
| 20 | +This capability is enabled automatically when you connect an MCP client to the |
| 21 | +[MCP Toolkit](/manuals/ai/mcp-catalog-and-toolkit/toolkit.md). The gateway |
| 22 | +provides a set of primordial tools that agents use to discover and manage |
| 23 | +servers during runtime. |
| 24 | + |
| 25 | +{{% experimental %}} |
| 26 | + |
| 27 | +Dynamic MCP is an experimental feature in early development. While you're |
| 28 | +welcome to try it out and explore its capabilities, you may encounter |
| 29 | +unexpected behavior or limitations. Feedback is welcome via at [GitHub |
| 30 | +issues](https://github.com/docker/mcp-gateway/issues) for bug reports and |
| 31 | +[GitHub discussions](https://github.com/docker/mcp-gateway/discussions) for |
| 32 | +general questions and feature requests. |
| 33 | + |
| 34 | +{{% /experimental %}} |
| 35 | + |
| 36 | +## How it works |
| 37 | + |
| 38 | +When you connect a client to the MCP Gateway, the gateway exposes a small set |
| 39 | +of management tools alongside any MCP servers you've already enabled. These |
| 40 | +management tools let agents interact with the gateway's configuration: |
| 41 | + |
| 42 | +| Tool | Description | |
| 43 | +| ---------------- | ------------------------------------------------------------------------ | |
| 44 | +| `mcp-find` | Search for MCP servers in the catalog by name or description | |
| 45 | +| `mcp-add` | Add a new MCP server to the current session | |
| 46 | +| `mcp-config-set` | Configure settings for an MCP server | |
| 47 | +| `mcp-remove` | Remove an MCP server from the session | |
| 48 | +| `mcp-exec` | Execute a tool by name that exists in the current session | |
| 49 | +| `code-mode` | Create a JavaScript-enabled tool that combines multiple MCP server tools | |
| 50 | + |
| 51 | +With these tools available, an agent can search the catalog, add servers, |
| 52 | +handle authentication, and use newly added tools directly without requiring a |
| 53 | +restart or manual configuration. |
| 54 | + |
| 55 | +Dynamically added servers and tools are associated with your _current session |
| 56 | +only_. When you start a new session, previously added servers are not |
| 57 | +automatically included. |
| 58 | + |
| 59 | +## Prerequisites |
| 60 | + |
| 61 | +To use Dynamic MCP, you need: |
| 62 | + |
| 63 | +- Docker Desktop version 4.50 or later, with [MCP Toolkit](/manuals/ai/mcp-catalog-and-toolkit/toolkit.md) enabled |
| 64 | +- An LLM application that supports MCP (such as Claude Desktop, Visual Studio Code, or Claude Code) |
| 65 | +- Your client configured to connect to the MCP Gateway |
| 66 | + |
| 67 | +See [Get started with Docker MCP Toolkit](/manuals/ai/mcp-catalog-and-toolkit/get-started.md) |
| 68 | +for setup instructions. |
| 69 | + |
| 70 | +## Usage |
| 71 | + |
| 72 | +Dynamic MCP is enabled automatically when you use the MCP Toolkit. Your |
| 73 | +connected clients can now use `mcp-find`, `mcp-add`, and other management tools |
| 74 | +during conversations. |
| 75 | + |
| 76 | +To see Dynamic MCP in action, connect your AI client to the Docker MCP Toolkit |
| 77 | +and try this prompt: |
| 78 | + |
| 79 | +```plaintext |
| 80 | +What MCP servers can I use for working with SQL databases? |
| 81 | +``` |
| 82 | + |
| 83 | +Given this prompt, your agent will use the `mcp-find` tool provided by MCP |
| 84 | +Toolkit to search for SQL-related servers in the [MCP Catalog](./catalog.md). |
| 85 | + |
| 86 | +And to add a server to a session, simply write a prompt and the MCP Toolkit |
| 87 | +takes care of installing and running the server: |
| 88 | + |
| 89 | +```plaintext |
| 90 | +Add the postgres mcp server |
| 91 | +``` |
| 92 | + |
| 93 | +## Tool composition with code mode |
| 94 | + |
| 95 | +The `code-mode` tool is available as an experimental capability for creating |
| 96 | +custom JavaScript functions that combine multiple MCP server tools. The |
| 97 | +intended use case is to enable workflows that coordinate multiple services |
| 98 | +in a single operation. |
| 99 | + |
| 100 | +> **Note** |
| 101 | +> |
| 102 | +> Code mode is in early development and is not yet reliable for general use. |
| 103 | +> The documentation intentionally omits usage examples at this time. |
| 104 | +> |
| 105 | +> The core Dynamic MCP capabilities (`mcp-find`, `mcp-add`, `mcp-config-set`, |
| 106 | +> `mcp-remove`) work as documented and are the recommended focus for current |
| 107 | +> use. |
| 108 | +
|
| 109 | +The architecture works as follows: |
| 110 | + |
| 111 | +1. The agent calls `code-mode` with a list of server names and a tool name |
| 112 | +2. The gateway creates a sandbox with access to those servers' tools |
| 113 | +3. A new tool is registered in the current session with the specified name |
| 114 | +4. The agent calls the newly created tool |
| 115 | +5. The code executes in the sandbox with access to the specified tools |
| 116 | +6. Results are returned to the agent |
| 117 | + |
| 118 | +The sandbox can only interact with the outside world through MCP tools, |
| 119 | +which are already running in isolated containers with restricted privileges. |
| 120 | + |
| 121 | +## Security considerations |
| 122 | + |
| 123 | +Dynamic MCP maintains the same security model as static MCP server |
| 124 | +configuration in MCP Toolkit: |
| 125 | + |
| 126 | +- All servers in the MCP Catalog are built, signed, and maintained by Docker |
| 127 | +- Servers run in isolated containers with restricted resources |
| 128 | +- Code mode runs agent-written JavaScript in an isolated sandbox that can only |
| 129 | + interact through MCP tools |
| 130 | +- Credentials are managed by the gateway and injected securely into containers |
| 131 | + |
| 132 | +The key difference with dynamic capabilities is that agents can add new tools |
| 133 | +during runtime. |
| 134 | + |
| 135 | +## Disabling Dynamic MCP |
| 136 | + |
| 137 | +Dynamic MCP is enabled by default in the MCP Toolkit. If you prefer to use only |
| 138 | +statically configured MCP servers, you can disable the dynamic tools feature: |
| 139 | + |
| 140 | +```console |
| 141 | +$ docker mcp feature disable dynamic-tools |
| 142 | +``` |
| 143 | + |
| 144 | +To re-enable the feature later: |
| 145 | + |
| 146 | +```console |
| 147 | +$ docker mcp feature enable dynamic-tools |
| 148 | +``` |
| 149 | + |
| 150 | +After changing this setting, you may need to restart any connected MCP clients. |
| 151 | + |
| 152 | +## Further reading |
| 153 | + |
| 154 | +Check out the [Dynamic MCP servers with Docker](https://docker.com/blog) blog |
| 155 | +post for more examples and inspiration on how you can use dynamic tools. |
0 commit comments