Skip to main content
Glama
wpfleger96

PagerDuty MCP Server

by wpfleger96

build_user_context

Build and validate a user's context into a structured dictionary to filter escalation policies, incidents, on-calls, services, and users in PagerDuty.

Instructions

Validate and build the current user's context into a dictionary with the following format: { "user_id": str, "team_ids": List[str], "service_ids": List[str], "escalation_policy_ids": List[str] } The MCP server tools use this user context to filter the following resources: - Escalation policies - Incidents - Oncalls - Services - Users

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core implementation of build_user_context: fetches current user via _show_current_user, builds context dict with user_id, name, email, team_ids, service_ids, escalation_policy_ids using helper functions from other modules, handles errors.
    def build_user_context() -> Dict[str, Any]:
        """Validate and build the current user's context. Exposed as MCP server tool.
    
        See the "Standard Response Format" section in `tools.md` for the complete standard response structure.
    
        Returns:
            See the "Standard Response Format" section in `tools.md` for the complete standard response structure.
            The response will contain the current user's context in the format defined in the "build_user_context" section of `tools.md`.
    
        Raises:
            See the "Error Handling" section in `tools.md` for common error scenarios.
        """
        try:
            user = _show_current_user()
            if not user:
                raise ValueError("Failed to get current user data")
    
            context = {
                "user_id": str(user.get("id", "")).strip(),
                "name": user.get("name", ""),
                "email": user.get("email", ""),
                "team_ids": [],
                "service_ids": [],
                "escalation_policy_ids": [],
            }
    
            if not context["user_id"]:
                raise ValueError("Invalid user data: missing or empty user ID")
    
            team_ids = teams.fetch_team_ids(user=user)
            context["team_ids"] = [
                str(tid).strip() for tid in team_ids if tid and str(tid).strip()
            ]
    
            if context["team_ids"]:
                service_ids = services.fetch_service_ids(team_ids=context["team_ids"])
                context["service_ids"] = [
                    str(sid).strip() for sid in service_ids if sid and str(sid).strip()
                ]
    
            escalation_policy_ids = escalation_policies.fetch_escalation_policy_ids(
                user_id=context["user_id"]
            )
            context["escalation_policy_ids"] = [
                str(epid).strip()
                for epid in escalation_policy_ids
                if epid and str(epid).strip()
            ]
    
            return context
    
        except Exception as e:
            utils.handle_api_error(e)
  • Registration of the MCP tool 'build_user_context' via @mcp.tool() decorator. Includes output format documentation (acts as schema) and thin wrapper delegating to users.build_user_context().
    @mcp.tool()
    def build_user_context() -> Dict[str, Any]:
        """Validate and build the current user's context into a dictionary with the following format:
            {
                "user_id": str,
                "team_ids": List[str],
                "service_ids": List[str],
                "escalation_policy_ids": List[str]
            }
        The MCP server tools use this user context to filter the following resources:
            - Escalation policies
            - Incidents
            - Oncalls
            - Services
            - Users
        """
        return users.build_user_context()
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It explains what the tool produces (a validated dictionary with specific fields) and how that output is used by other tools (for filtering resources). However, it doesn't disclose important behavioral aspects like whether this requires authentication, what validation entails, error conditions, or whether it's idempotent.

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

Conciseness5/5

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

The description is perfectly structured and concise. The first sentence states the core purpose and output format. The second sentence explains how the output is used by other tools, with a clear bulleted list of resource types. Every sentence earns its place with no wasted words.

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 the tool has no parameters, no annotations, and no output schema, the description does a reasonable job explaining what the tool does and how its output is used. However, for a context-building tool that likely interacts with authentication systems, it should ideally mention authentication requirements, validation failure scenarios, or whether the context is cached/session-based.

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 0 parameters with 100% schema description coverage, so the baseline is 4. The description appropriately doesn't waste space discussing non-existent parameters and instead focuses on the output format and usage context, which is the right emphasis for a parameterless tool.

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: 'Validate and build the current user's context into a dictionary' with a specific format. It distinguishes itself from sibling tools (which are all 'get_' operations) by focusing on user context construction rather than resource retrieval. However, it doesn't explicitly contrast with specific alternatives beyond the general sibling list.

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?

The description implies when to use this tool by stating 'The MCP server tools use this user context to filter the following resources' and listing five resource types. This suggests it should be used before those filtering operations. However, it doesn't provide explicit when-not-to-use guidance or name specific alternative tools for different scenarios.

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/wpfleger96/pagerduty-mcp-server'

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