export_topology
Export Azure infrastructure topology graphs in JSON or summary format to analyze resource relationships and connectivity paths.
Instructions
Export the complete topology graph
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "export_topology"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | No | Export format | summary |
Implementation Reference
- src/server.ts:525-557 (handler)Handler function that implements the export_topology tool logic. It builds the topology and returns either full JSON or a summary based on the format parameter.
case 'export_topology': { const { format = 'summary' } = args as { format?: 'json' | 'summary' }; const topology = await buildTopology(); if (format === 'json') { return { content: [ { type: 'text', text: JSON.stringify(topology, null, 2), }, ], }; } else { const resourceTypes = Array.from(new Set(topology.nodes.map(n => n.type))).sort(); const subscriptions = Array.from(new Set(topology.nodes.map(n => n.subscriptionId))).sort(); const resourceGroups = Array.from(new Set(topology.nodes.map(n => n.resourceGroup))).sort(); return { content: [ { type: 'text', text: `Azure Topology Summary:\n\n` + `Total Resources: ${topology.nodes.length}\n` + `Total Connections: ${topology.edges.length}\n\n` + `Subscriptions (${subscriptions.length}):\n${subscriptions.map(s => `• ${s}`).join('\n')}\n\n` + `Resource Groups (${resourceGroups.length}):\n${resourceGroups.map(rg => `• ${rg}`).join('\n')}\n\n` + `Resource Types (${resourceTypes.length}):\n${resourceTypes.map(rt => `• ${rt}`).join('\n')}`, }, ], }; } } - src/server.ts:406-416 (schema)Input schema for the export_topology tool, defining the optional format parameter.
inputSchema: { type: 'object', properties: { format: { type: 'string', enum: ['json', 'summary'], description: 'Export format', default: 'summary', }, }, }, - src/server.ts:404-417 (registration)Registration of the export_topology tool in the tools list returned by ListToolsRequestHandler.
name: 'export_topology', description: 'Export the complete topology graph', inputSchema: { type: 'object', properties: { format: { type: 'string', enum: ['json', 'summary'], description: 'Export format', default: 'summary', }, }, }, }, - src/server.ts:114-162 (helper)Key helper function called by the handler to build and cache the topology graph from Azure Resource Graph queries.
async function buildTopology(): Promise<TopologyGraph> { const now = Date.now(); if (topologyCache && (now - cacheTimestamp) < CACHE_TTL) { return topologyCache; } console.error('Building topology from Azure resources...'); try { // Query all resources const resourcesResult = await resourceGraphClient.resources({ query: RESOURCE_QUERY, subscriptions: subscriptionIds, }); const nodes: GraphNode[] = []; const edges: GraphEdge[] = []; // Process resources into nodes if (resourcesResult.data) { for (const resource of resourcesResult.data as any[]) { const node: GraphNode = { id: resource.id, type: resource.type, name: resource.name, subscriptionId: resource.subscriptionId, resourceGroup: resource.resourceGroup, location: resource.location, tags: resource.tags, properties: resource.properties, }; nodes.push(node); } } // Build relationships/edges await buildResourceRelationships(nodes, edges); const topology: TopologyGraph = { nodes, edges }; topologyCache = topology; cacheTimestamp = now; console.error(`Topology built: ${nodes.length} nodes, ${edges.length} edges`); return topology; } catch (error) { console.error('Error building topology:', error); throw error; } }