MCP Optimizer supports filtering tool lookups by ToolHive groups, allowing you to restrict which tools are discoverable based on their group membership.
When running multiple MCP servers across different ToolHive groups (e.g., production, staging, development), you may want to limit tool discovery to specific groups. Group filtering enables this by allowing you to specify which groups to search when looking up tools.
Group filtering can be configured using two methods:
Set the ALLOWED_GROUPS environment variable:
# Single group
export ALLOWED_GROUPS="production"
# Multiple groups (comma-separated)
export ALLOWED_GROUPS="production,staging"
# Start the server
mcp-optimizerIf the environment variable is not set, all groups are searched (no filtering).
Restrict tool discovery to development and testing groups:
export ALLOWED_GROUPS="development,testing"
mcp-optimizerOnly discover tools from the production group:
export ALLOWED_GROUPS="production"
mcp-optimizer-
Server Group Assignment: When MCP Optimizer ingests MCP servers from ToolHive, it automatically captures and stores each server's group information.
-
Tool Discovery: When searching for tools using
find_tool,list_tools, orsearch_registry, MCP Optimizer:- Checks if group filtering is configured via the
ALLOWED_GROUPSenvironment variable - Filters the search to only include tools from servers in the specified groups
- Returns only matching tools
- Checks if group filtering is configured via the
-
Group Filtering Behavior:
ALLOWED_GROUPSnot set (default): Search all groupsALLOWED_GROUPS="group-a": Only search servers ingroup-aALLOWED_GROUPS="group-a,group-b": Search servers in eithergroup-aorgroup-b
The mcpserver table includes a group column (nullable) that stores the ToolHive group name. An index (idx_mcpserver_group) is created for efficient group-based queries.
Group filtering is applied at the database query level, affecting:
- Semantic similarity search (vector embeddings)
- BM25 full-text search
- Tool listing operations
- Existing servers without group assignments have
group = NULL - Servers with
NULLgroups are excluded when group filtering is active - No breaking changes to existing APIs
MCP Optimizer automatically discovers and respects ToolHive group assignments:
# Create groups in ToolHive
thv group create production
thv group create staging
# Run servers in different groups
thv run --group production github
thv run --group staging postgres
# Configure MCP Optimizer to only see production tools
export ALLOWED_GROUPS="production"
mcp-optimizer