Skip to main content
Glama
AgentWong

IAC Memory MCP Server

by AgentWong

get_terraform_resource_info

Retrieve detailed schema and documentation for a Terraform resource by specifying the provider and resource name, enabling efficient IaC management.

Instructions

Retrieve comprehensive information about a Terraform resource including schema and documentation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
provider_nameYesName of the Terraform provider
resource_nameYesName of the resource

Implementation Reference

  • The primary handler function that implements the tool logic. It retrieves Terraform resource information from the database, formats it with schema and metadata, and returns it as text content. Handles missing resources and errors gracefully.
    async def handle_get_terraform_resource_info( db: Any, arguments: Dict[str, Any], operation_id: str ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]: """Handle get_terraform_resource_info tool.""" try: logger.info( "Getting resource info", extra={ "provider_name": arguments["provider_name"], "resource_name": arguments["resource_name"], "operation_id": operation_id, }, ) # Get resource info resource = get_resource_info( db, arguments["resource_name"], provider_name=arguments["provider_name"] ) if not resource: error_msg = f"Resource '{arguments['resource_name']}' not found for provider '{arguments['provider_name']}'" logger.error(error_msg, extra={"operation_id": operation_id}) return [types.TextContent( type="text", text=error_msg )] # Format output output = [ f"Resource: {resource['name']}", f"Provider: {resource['provider_name']}", f"Type: {resource['resource_type']}", f"Version: {resource['version']}", f"Documentation: {resource['doc_url']}", "\nSchema:", resource["schema"], ] return [types.TextContent( type="text", text="\n".join(output) )] except Exception as e: error_msg = f"Failed to get resource info: {str(e)}" logger.error(error_msg, extra={"operation_id": operation_id}) return [types.TextContent(type="text", text=error_msg)]
  • JSON schema defining the tool's input parameters: provider_name (string, required) and resource_name (string, required), along with description.
    "get_terraform_resource_info": { "type": "object", "description": "Retrieve comprehensive information about a Terraform resource including schema and documentation", "required": ["provider_name", "resource_name"], "properties": { "provider_name": { "type": "string", "description": "Name of the Terraform provider", }, "resource_name": {"type": "string", "description": "Name of the resource"}, }, },
  • Maps the tool name 'get_terraform_resource_info' to its handler function within the terraform-specific tool handlers dictionary, which is later merged into 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, }
  • Database helper function called by the handler to query and return detailed Terraform resource information (including schema) from the SQLite database, joining resources and providers tables.
    def get_resource_info(db: DatabaseManager, resource_name: str, provider_name: str = None) -> Optional[Dict]: """Get detailed information about a Terraform resource. Args: db: Database manager instance resource_name: Name or ID of the resource provider_name: Optional provider name to filter by """ logger.info( "Fetching resource info", extra={ "resource_name": resource_name, "provider_name": provider_name, "operation": "get_resource_info" }, ) try: with db.get_connection() as conn: if provider_name: # Query by resource name and provider name result = conn.execute( """SELECT r.*, p.name as provider_name, p.version as provider_version FROM terraform_resources r JOIN terraform_providers p ON r.provider_id = p.id WHERE r.name = ? AND p.name = ?""", (resource_name, provider_name), ).fetchone() else: # Try first as ID, then as name result = conn.execute( """SELECT r.*, p.name as provider_name, p.version as provider_version FROM terraform_resources r JOIN terraform_providers p ON r.provider_id = p.id WHERE r.id = ? OR r.name = ?""", (resource_name, resource_name), ).fetchone() return dict(result) if result else None except sqlite3.Error as e: error_msg = f"Failed to get resource info: {str(e)}" logger.error(error_msg) raise DatabaseError(error_msg)
  • Global registration of tool handling with the MCP server using @server.call_tool() and @server.list_tools(), which uses the combined tool_handlers including the terraform ones.
    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)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/AgentWong/iac-memory-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server