get_memory_info_tool
Retrieve real-time memory usage statistics for system monitoring and analysis using the MCP server's interface.
Instructions
Retrieve memory usage statistics.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/system_info_mcp/server.py:46-50 (handler)The handler function for the 'get_memory_info_tool' tool, decorated with @app.tool() which also serves as registration. It delegates to the get_memory_info helper.@app.tool() def get_memory_info_tool() -> Dict[str, Any]: """Retrieve memory usage statistics.""" return get_memory_info()
- src/system_info_mcp/tools.py:80-111 (helper)Core helper function implementing the memory information retrieval using psutil.virtual_memory() and psutil.swap_memory(), with formatting utilities.@cache_result("memory_info", ttl=1) def get_memory_info() -> Dict[str, Any]: """Retrieve memory usage statistics.""" try: # Get virtual memory info virtual_mem = psutil.virtual_memory() # Get swap memory info swap_mem = psutil.swap_memory() return { "virtual_memory": { "total": virtual_mem.total, "available": virtual_mem.available, "used": virtual_mem.used, "percent": round(virtual_mem.percent, 1), "total_gb": bytes_to_gb(virtual_mem.total), "available_gb": bytes_to_gb(virtual_mem.available), "used_gb": bytes_to_gb(virtual_mem.used), }, "swap_memory": { "total": swap_mem.total, "used": swap_mem.used, "free": swap_mem.free, "percent": round(swap_mem.percent, 1), "total_gb": bytes_to_gb(swap_mem.total), }, } except Exception as e: logger.error(f"Error getting memory info: {e}") raise