|
| 1 | +--- |
| 2 | +title: "MCP Tool Filtering" |
| 3 | +description: "Control which MCP tools are available for each Virtual Key." |
| 4 | +icon: "grid-2" |
| 5 | +--- |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +MCP Tool Filtering allows you to control which tools are available to AI models on a per-request basis using Virtual Keys (VKs). By configuring a VirtualKey, you can create a strict allow-list of MCP clients and tools, ensuring that only approved tools can be executed. |
| 10 | + |
| 11 | +Make sure you have at least one MCP client set up. Read more about it [here](../mcp). |
| 12 | + |
| 13 | +## How It Works |
| 14 | + |
| 15 | +The filtering logic is determined by the Virtual Key's configuration: |
| 16 | + |
| 17 | +1. **No MCP Configuration on Virtual Key (Default)** |
| 18 | + - If a Virtual Key has no specific MCP configurations, all tools from all enabled MCP clients are available by default. |
| 19 | + - In this state, a user can still manually filter tools for a single request by passing the `x-bf-mcp-include-tools` header. |
| 20 | + |
| 21 | +2. **With MCP Configuration on Virtual Key** |
| 22 | + - When you configure MCP clients on a Virtual Key, its settings take full precedence. |
| 23 | + - Bifrost automatically generates an `x-bf-mcp-include-tools` header based on your VK configuration. This acts as a strict allow-list for the request. |
| 24 | + - This generated header **overrides** any `x-bf-mcp-include-tools` header that might have been sent manually with the request. |
| 25 | + |
| 26 | +For each MCP client associated with a Virtual Key, you can specify the allowed tools: |
| 27 | +- **Select specific tools**: Only the chosen tools from that client will be available. |
| 28 | +- **Use `*` wildcard**: All available tools from that client will be permitted. |
| 29 | +- **Leave tool list empty**: All tools from that client will be **blocked**. |
| 30 | +- **Do not configure a client**: All tools from that client will be **blocked** (if other clients are configured). |
| 31 | + |
| 32 | +## Setting MCP Tool Restrictions |
| 33 | + |
| 34 | +<Tabs group="mcp-tool-restrictions"> |
| 35 | +<Tab title="Web UI"> |
| 36 | + |
| 37 | +You can configure which tools a Virtual Key has access to via the UI. |
| 38 | + |
| 39 | +1. Go to **Virtual Keys** page. |
| 40 | +2. Create/Edit virtual key |
| 41 | + |
| 42 | +3. In **MCP Client Configurations** section, add the MCP client you want to restrict the VK to |
| 43 | +4. Add the tools you want to restrict the VK to, or leave it blank to allow all tools for this client |
| 44 | +5. Click on the **Save** button |
| 45 | + |
| 46 | +</Tab> |
| 47 | +<Tab title="API"> |
| 48 | + |
| 49 | +You can configure this via the REST API when creating (`POST`) or updating (`PUT`) a virtual key. |
| 50 | + |
| 51 | +**Create Virtual Key:** |
| 52 | +```bash |
| 53 | +curl -X POST http://localhost:8080/api/governance/virtual-keys \ |
| 54 | + -H "Content-Type: application/json" \ |
| 55 | + -d '{ |
| 56 | + "name": "vk-for-billing-support", |
| 57 | + "mcp_configs": [ |
| 58 | + { |
| 59 | + "mcp_client_name": "billing-client", |
| 60 | + "tools_to_execute": ["check-status"] |
| 61 | + }, |
| 62 | + { |
| 63 | + "mcp_client_name": "support-client", |
| 64 | + "tools_to_execute": ["*"] |
| 65 | + } |
| 66 | + ] |
| 67 | + }' |
| 68 | +``` |
| 69 | + |
| 70 | +**Update Virtual Key:** |
| 71 | +```bash |
| 72 | +curl -X PUT http://localhost:8080/api/governance/virtual-keys/{vk_id} \ |
| 73 | + -H "Content-Type: application/json" \ |
| 74 | + -d '{ |
| 75 | + "mcp_configs": [ |
| 76 | + { |
| 77 | + "mcp_client_name": "billing-client", |
| 78 | + "tools_to_execute": ["check-status"] |
| 79 | + }, |
| 80 | + { |
| 81 | + "mcp_client_name": "support-client", |
| 82 | + "tools_to_execute": ["*"] |
| 83 | + } |
| 84 | + ] |
| 85 | + }' |
| 86 | +``` |
| 87 | + |
| 88 | +**Behavior:** |
| 89 | +- The virtual key can only access the `check-status` tool from `billing-client`. |
| 90 | +- It can access all tools from `support-client`. |
| 91 | +- Any other MCP client is implicitly blocked for this key. |
| 92 | + |
| 93 | +</Tab> |
| 94 | + |
| 95 | +<Tab title="config.json"> |
| 96 | + |
| 97 | +You can also define MCP tool restrictions directly in your `config.json` file. The `mcp_configs` array under a virtual key should reference the MCP client by name. |
| 98 | + |
| 99 | +```json |
| 100 | +{ |
| 101 | + "governance": { |
| 102 | + "virtual_keys": [ |
| 103 | + { |
| 104 | + "id": "vk-billing-support-only", |
| 105 | + "name": "VK for Billing and Support", |
| 106 | + "mcp_configs": [ |
| 107 | + { |
| 108 | + "mcp_client_name": "billing-client", |
| 109 | + "tools_to_execute": ["check-status"] |
| 110 | + }, |
| 111 | + { |
| 112 | + "mcp_client_name": "support-client", |
| 113 | + "tools_to_execute": ["*"] |
| 114 | + } |
| 115 | + ] |
| 116 | + } |
| 117 | + ] |
| 118 | + } |
| 119 | +} |
| 120 | +``` |
| 121 | +</Tab> |
| 122 | +</Tabs> |
| 123 | + |
| 124 | +## Example Scenario |
| 125 | + |
| 126 | +**Available MCP Clients & Tools:** |
| 127 | +- **`billing-client`**: with tools `[create-invoice, check-status]` |
| 128 | +- **`support-client`**: with tools `[create-ticket, get-faq]` |
| 129 | + |
| 130 | +<Tabs> |
| 131 | +<Tab title="VK with Full Access"> |
| 132 | +**Configuration:** |
| 133 | +- `billing-client` -> Allowed Tools: `[*]` (wildcard) |
| 134 | +- `support-client` -> Allowed Tools: `[*]` (wildcard) |
| 135 | + |
| 136 | +**Result:** |
| 137 | +A request with this Virtual Key can access all four tools: `create-invoice`, `check-status`, `create-ticket`, and `get-faq`. |
| 138 | + |
| 139 | +</Tab> |
| 140 | +<Tab title="VK with Partial Access"> |
| 141 | +**Configuration:** |
| 142 | +- `billing-client` -> Allowed Tools: `[check-status]` |
| 143 | +- `support-client` -> Not configured |
| 144 | + |
| 145 | +**Result:** |
| 146 | +A request with this Virtual Key can only access the `check-status` tool. All other tools are blocked. |
| 147 | + |
| 148 | +</Tab> |
| 149 | +<Tab title="VK with No Tools"> |
| 150 | +**Configuration:** |
| 151 | +- `billing-client` -> Allowed Tools: `[]` (empty list) |
| 152 | + |
| 153 | +**Result:** |
| 154 | +A request with this Virtual Key cannot access any tools. All tools from all clients are blocked. |
| 155 | +</Tab> |
| 156 | +</Tabs> |
| 157 | + |
| 158 | +<Note> |
| 159 | +When a Virtual Key has MCP configurations, it dynamically generates the `x-bf-mcp-include-tools` header. This ensures that the VK's rules are always enforced and will override any manual header sent by the user. Though you can still use `x-bf-mcp-include-clients` header to filter the MCP clients per request. |
| 160 | +</Note> |
0 commit comments