Skip to main content
Glama

get_server_metrics

Retrieve detailed server performance metrics, including request counts, success rates, method usage, error categories, and cache statistics, to monitor and optimize Scrapy MCP Server operations.

Instructions

Get server performance metrics and statistics.

Returns information about:

  • Request counts and success rates

  • Performance metrics

  • Method usage statistics

  • Error categories

  • Cache statistics

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'get_server_metrics' MCP tool. Decorated with @app.tool() for automatic registration. Fetches metrics from global collectors (metrics_collector.get_stats() and cache_manager.stats()), constructs a MetricsResponse Pydantic model, and returns server performance statistics including request counts, success rates, response times, uptime, cache stats, method usage, and error categories. Includes exception handling for robustness.
    async def get_server_metrics() -> MetricsResponse:
        """
        Get server performance metrics and statistics.
    
        Args: 无需参数,返回服务器性能指标和统计信息
    
        Returns information about:
        - Request counts and success rates
        - Performance metrics
        - Method usage statistics
        - Error categories
        - Cache statistics
        - Server configuration details
    
        Returns:
            MetricsResponse object containing detailed server metrics including scraping performance,
            cache statistics, server configuration, and real-time statistics.
        """
        try:
            metrics = metrics_collector.get_stats()
            cache_stats = cache_manager.stats()
    
            return MetricsResponse(
                success=True,
                total_requests=metrics.get("total_requests", 0),
                successful_requests=metrics.get("successful_requests", 0),
                failed_requests=metrics.get("failed_requests", 0),
                success_rate=metrics.get("success_rate", 0.0),
                average_response_time=metrics.get("average_response_time", 0.0),
                uptime_seconds=metrics.get("uptime_seconds", 0.0),
                cache_stats=cache_stats,
                method_usage=metrics.get("method_usage", {}),
                error_categories=metrics.get("error_categories", {}),
            )
        except Exception:
            return MetricsResponse(
                success=False,
                total_requests=0,
                successful_requests=0,
                failed_requests=0,
                success_rate=0.0,
                average_response_time=0.0,
                uptime_seconds=0.0,
                cache_stats={},
                method_usage={},
                error_categories={},
            )
  • Pydantic BaseModel defining the response schema for get_server_metrics tool. Specifies fields for success status, request statistics (total/successful/failed counts and rates), performance metrics (avg response time, uptime), and breakdowns (cache stats, method usage, error categories). Used for input/output validation in the FastMCP framework.
    class MetricsResponse(BaseModel):
        """Response model for server metrics."""
    
        success: bool = Field(..., description="操作是否成功")
        total_requests: int = Field(..., description="总请求数")
        successful_requests: int = Field(..., description="成功请求数")
        failed_requests: int = Field(..., description="失败请求数")
        success_rate: float = Field(..., description="成功率")
        average_response_time: float = Field(..., description="平均响应时间(秒)")
        uptime_seconds: float = Field(..., description="运行时间(秒)")
        cache_stats: Dict[str, Any] = Field(..., description="缓存统计")
        method_usage: Dict[str, int] = Field(..., description="方法使用统计")
        error_categories: Dict[str, int] = Field(..., description="错误分类统计")
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 of behavioral disclosure. While it lists the categories of metrics returned, it doesn't address critical behavioral aspects like whether this requires authentication, if it's a read-only operation, what time range the metrics cover, or if there are rate limits. The description is insufficient for a mutation-free tool with zero annotation coverage.

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 efficiently structured with a clear purpose statement followed by a bulleted list of return categories. Every sentence earns its place, though the bulleted list could be slightly more concise by integrating it into the flow rather than as a separate section.

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 that there's an output schema (which handles return value documentation), zero parameters, and no annotations, the description is reasonably complete for its core purpose. However, it lacks important context about when to use it versus siblings and behavioral constraints, making it only minimally adequate.

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?

The tool has zero parameters, and schema description coverage is 100%, so there's no parameter documentation burden. The description appropriately doesn't waste space discussing non-existent parameters, earning a high score for correctly handling this edge case.

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

Purpose4/5

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

The description clearly states the tool's purpose with the verb 'Get' and resource 'server performance metrics and statistics', making it immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_page_info' or 'scrape_webpage' which might also provide performance-related data in different contexts, preventing a perfect score.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With sibling tools like 'get_page_info' that might overlap in providing server-related data, there's no indication of when this specific metrics tool is preferred or what contexts it's designed for.

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

Related 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/ThreeFish-AI/scrapy-mcp'

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