list_provider_resources
Retrieve all resources linked to a specified Terraform provider using regex-based filtering on the IAC Memory MCP Server.
Instructions
List all resources associated with a specific Terraform provider
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filter_criteria | No | Optional filtering criteria | |
| provider_name | Yes | Name of the Terraform provider |
Implementation Reference
- The handler function that implements the core logic of the 'list_provider_resources' tool. It retrieves resources for a given provider from the database, applies optional filters based on type patterns, formats them into a readable text output, and handles errors gracefully.async def handle_list_provider_resources( db: Any, arguments: Dict[str, Any], operation_id: str ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]: """Handle list_provider_resources tool.""" try: logger.info( "Listing provider resources", extra={ "provider_name": arguments["provider_name"], "operation_id": operation_id, }, ) # Get resources resources = get_provider_resources(db, arguments["provider_name"]) # Apply any filters filter_criteria = arguments.get("filter_criteria", {}) if filter_criteria: if "type_pattern" in filter_criteria: pattern = re.compile(filter_criteria["type_pattern"]) resources = [r for r in resources if pattern.match(r["resource_type"])] # Format output if not resources: return [types.TextContent( type="text", text=f"No resources found for provider {arguments['provider_name']}" )] output = [f"Resources for provider {arguments['provider_name']}:"] for r in resources: output.append( f"\n- {r['name']} ({r['resource_type']})" f"\n Version: {r['version']}" f"\n Documentation: {r['doc_url']}" ) return [types.TextContent( type="text", text="\n".join(output) )] except Exception as e: error_msg = f"Failed to list provider resources: {str(e)}" logger.error(error_msg, extra={"operation_id": operation_id}) return [types.TextContent(type="text", text=error_msg)]
- JSON schema defining the input parameters and structure for the 'list_provider_resources' tool, specifying required 'provider_name' and optional 'filter_criteria' with 'type_pattern'."list_provider_resources": { "type": "object", "description": "List all resources associated with a specific Terraform provider", "required": ["provider_name"], "properties": { "provider_name": { "type": "string", "description": "Name of the Terraform provider", }, "filter_criteria": { "type": "object", "description": "Optional filtering criteria", "properties": { "type_pattern": { "type": "string", "description": "Regex pattern to filter resource types", } }, }, }, },
- src/iac_memory_mcp_server/tools/terraform.py:358-366 (registration)Local registration of the 'list_provider_resources' handler within the terraform_tool_handlers dictionary, which is later merged into the global tool handlers.terraform_tool_handlers = { "get_terraform_provider_info": handle_get_terraform_provider_info, "list_provider_resources": handle_list_provider_resources, "get_terraform_resource_info": handle_get_terraform_resource_info, "add_terraform_provider": handle_add_terraform_provider, "add_terraform_resource": handle_add_terraform_resource, "update_provider_version": handle_update_provider_version, "update_resource_schema": handle_update_resource_schema, }
- src/iac_memory_mcp_server/tools/__init__.py:43-55 (registration)Global tool registration function that sets up the call_tool and list_tools endpoints on the MCP server, using the combined tool_handlers dictionary which includes the terraform handlers.def register_tools(server: Server) -> None: """Register all tool handlers with the server.""" @server.call_tool() async def call_tool( name: str, arguments: Dict[str, Any], ctx: RequestContext | None = None ): return await handle_call_tool(name, arguments, ctx) @server.list_tools() async def list_tools(ctx: RequestContext = None): return await handle_list_tools(ctx)