Skip to main content
Glama
dknell

System Information MCP Server

by dknell

get_memory_info_tool

Retrieve memory usage statistics to monitor system RAM utilization and free memory.

Instructions

Retrieve memory usage statistics.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Registration of the 'get_memory_info_tool' MCP tool via the @app.tool() decorator in the FastMCP server. It is a thin wrapper that delegates to get_memory_info().
    @app.tool()
    def get_memory_info_tool() -> Dict[str, Any]:
        """Retrieve memory usage statistics."""
        return get_memory_info()
  • Actual implementation of memory info retrieval. Uses psutil.virtual_memory() and psutil.swap_memory() to collect memory statistics, returning dicts with virtual and swap memory details. Cached with a 1-second TTL.
    @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
  • Helper function used by get_memory_info to convert byte values to gigabytes for human-readable output.
    def bytes_to_gb(bytes_value: int) -> float:
        """Convert bytes to gigabytes with 1 decimal precision."""
        return round(bytes_value / (1024**3), 1)
  • Decorator used to cache get_memory_info results with a 1-second TTL, reducing redundant psutil calls.
    def cache_result(cache_key: str, ttl: Optional[int] = None) -> Any:
        """Decorator to cache function results with TTL."""
        if ttl is None:
            ttl = config.cache_ttl
    
        def decorator(func: Callable[..., T]) -> Callable[..., T]:
            @wraps(func)
            async def async_wrapper(*args: Any, **kwargs: Any) -> T:
                current_time = time.time()
    
                # Check if we have cached result
                if cache_key in _cache:
                    cache_entry = _cache[cache_key]
                    if current_time - cache_entry["timestamp"] < ttl:
                        logger.debug(f"Cache hit for {cache_key}")
                        return cache_entry["data"]
    
                # Get fresh data
                logger.debug(f"Cache miss for {cache_key}, fetching fresh data")
                if asyncio.iscoroutinefunction(func):
                    result = await func(*args, **kwargs)
                else:
                    result = func(*args, **kwargs)
    
                # Cache the result
                _cache[cache_key] = {"data": result, "timestamp": current_time}
    
                return result
    
            @wraps(func)
            def sync_wrapper(*args: Any, **kwargs: Any) -> T:
                current_time = time.time()
    
                # Check if we have cached result
                if cache_key in _cache:
                    cache_entry = _cache[cache_key]
                    if current_time - cache_entry["timestamp"] < ttl:
                        logger.debug(f"Cache hit for {cache_key}")
                        return cache_entry["data"]
    
                # Get fresh data
                logger.debug(f"Cache miss for {cache_key}, fetching fresh data")
                result = func(*args, **kwargs)
    
                # Cache the result
                _cache[cache_key] = {"data": result, "timestamp": current_time}
    
                return result
    
            # Return appropriate wrapper based on whether function is async
            return async_wrapper if asyncio.iscoroutinefunction(func) else sync_wrapper
    
        return decorator
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It only states 'retrieve' which implies a read operation, but no details about permissions, side effects, or return format are disclosed. The existence of an output schema may compensate, but without seeing it, the description alone is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence with no unnecessary words. For a tool with no parameters, this is appropriately sized, though it could be slightly more informative without losing conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no parameters and an existing output schema, the description is minimally adequate. However, it lacks specifics about what the returned statistics include (e.g., total, used, free), which would help the agent understand the output without relying solely on the schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

There are no parameters, and schema description coverage is 100%, so the description does not need to add parameter info. Baseline is 4.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses the verb 'Retrieve' and specifies the resource 'memory usage statistics', clearly distinguishing it from sibling tools like get_cpu_info_tool which target different resources.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit when-to-use or alternatives are given, but the context of sibling tools (e.g., get_cpu_info_tool) implies this tool is for memory statistics. The guidance is implied rather than stated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/dknell/mcp-system-info'

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