@@ -5859,6 +5859,86 @@ export function attach(
58595859 return unresolvedSource;
58605860 }
58615861
5862+ type InternalMcpFunctions = {
5863+ __internal_only_getComponentTree ? : Function ,
5864+ } ;
5865+
5866+ const internalMcpFunctions: InternalMcpFunctions = { } ;
5867+ if (__IS_INTERNAL_MCP_BUILD__) {
5868+ // eslint-disable-next-line no-inner-declarations
5869+ function __internal_only_getComponentTree ( ) : string {
5870+ let treeString = '' ;
5871+
5872+ function buildTreeString (
5873+ instance : DevToolsInstance ,
5874+ prefix : string = '' ,
5875+ isLastChild : boolean = true ,
5876+ ) : void {
5877+ if ( ! instance ) return ;
5878+
5879+ const name =
5880+ ( instance . kind !== VIRTUAL_INSTANCE
5881+ ? getDisplayNameForFiber ( instance . data )
5882+ : instance . data . name ) || 'Unknown' ;
5883+
5884+ const id = instance . id !== undefined ? instance . id : 'unknown' ;
5885+
5886+ if ( name !== 'createRoot()' ) {
5887+ treeString +=
5888+ prefix +
5889+ ( isLastChild ? '└── ' : '├── ' ) +
5890+ name +
5891+ ' (id: ' +
5892+ id +
5893+ ')\n' ;
5894+ }
5895+
5896+ const childPrefix = prefix + ( isLastChild ? ' ' : '│ ' ) ;
5897+
5898+ let childCount = 0 ;
5899+ let tempChild = instance . firstChild ;
5900+ while ( tempChild !== null ) {
5901+ childCount ++ ;
5902+ tempChild = tempChild . nextSibling ;
5903+ }
5904+
5905+ let child = instance . firstChild ;
5906+ let currentChildIndex = 0 ;
5907+
5908+ while ( child !== null ) {
5909+ currentChildIndex ++ ;
5910+ const isLastSibling = currentChildIndex === childCount ;
5911+ buildTreeString ( child , childPrefix , isLastSibling ) ;
5912+ child = child . nextSibling ;
5913+ }
5914+ }
5915+
5916+ const rootInstances : Array < DevToolsInstance > = [];
5917+ idToDevToolsInstanceMap.forEach(instance => {
5918+ if ( instance . parent === null || instance . parent . parent === null ) {
5919+ rootInstances . push ( instance ) ;
5920+ }
5921+ } ) ;
5922+
5923+ if ( rootInstances . length > 0 ) {
5924+ for ( let i = 0 ; i < rootInstances . length ; i ++ ) {
5925+ const isLast = i === rootInstances . length - 1 ;
5926+ buildTreeString ( rootInstances [ i ] , '' , isLast ) ;
5927+ if ( ! isLast ) {
5928+ treeString += '\n' ;
5929+ }
5930+ }
5931+ } else {
5932+ treeString = 'No component tree found.' ;
5933+ }
5934+
5935+ return treeString ;
5936+ }
5937+
5938+ internalMcpFunctions . __internal_only_getComponentTree =
5939+ __internal_only_getComponentTree ;
5940+ }
5941+
58625942 return {
58635943 cleanup ,
58645944 clearErrorsAndWarnings ,
@@ -5898,5 +5978,6 @@ export function attach(
58985978 storeAsGlobal ,
58995979 updateComponentFilters ,
59005980 getEnvironmentNames ,
5981+ ...internalMcpFunctions ,
59015982 } ;
59025983}
0 commit comments