Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions core/mcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ const (
MCPClientConnectionEstablishTimeout = 30 * time.Second // Timeout for MCP client connection establishment

// Context keys for client filtering in requests
MCPContextKeyIncludeClients = "mcp_include_clients" // Context key for whitelist client filtering
MCPContextKeyExcludeClients = "mcp_exclude_clients" // Context key for blacklist client filtering
MCPContextKeyIncludeClients = "mcp-include-clients" // Context key for whitelist client filtering
MCPContextKeyExcludeClients = "mcp-exclude-clients" // Context key for blacklist client filtering
MCPContextKeyIncludeTools = "mcp-include-tools" // Context key for whitelist tool filtering
MCPContextKeyExcludeTools = "mcp-exclude-tools" // Context key for blacklist tool filtering
)

// ============================================================================
Expand Down Expand Up @@ -151,7 +153,11 @@ func (m *MCPManager) getAvailableTools(ctx context.Context) []schemas.Tool {
}

// Add all tools from this client
for _, tool := range client.ToolMap {
for toolName, tool := range client.ToolMap {
if m.shouldSkipToolForRequest(toolName, ctx) {
continue
}

tools = append(tools, tool)
}
}
Expand Down Expand Up @@ -627,6 +633,32 @@ func (m *MCPManager) shouldSkipToolForConfig(toolName string, config schemas.MCP
return false // Tool is allowed
}

// shouldSkipToolForRequest checks if a tool should be skipped based on the request context.
func (m *MCPManager) shouldSkipToolForRequest(toolName string, ctx context.Context) bool {
includeTools := ctx.Value(MCPContextKeyIncludeTools)
excludeTools := ctx.Value(MCPContextKeyExcludeTools)

if includeTools != nil {
if includeStr, ok := includeTools.(string); ok && includeStr != "" {
includeToolsList := strings.Split(includeStr, ",")
if slices.Contains(includeToolsList, toolName) {
return false // Tool is allowed
}
}
}

if excludeTools != nil {
if excludeStr, ok := excludeTools.(string); ok && excludeStr != "" {
excludeToolsList := strings.Split(excludeStr, ",")
if slices.Contains(excludeToolsList, toolName) {
return true // Tool should be skipped
}
}
}

return false // Tool is allowed
}

// convertMCPToolToBifrostSchema converts an MCP tool definition to Bifrost format.
func (m *MCPManager) convertMCPToolToBifrostSchema(mcpTool *mcp.Tool) schemas.Tool {
return schemas.Tool{
Expand Down
Loading