Skip to main content
Glama
Sealjay

mcp-hey

hey_list_label_emails

Read-only

List emails from a specific label with pagination. Use force_refresh to get fresh data bypassing cache.

Instructions

List emails with a specific label. Returns cached results unless force_refresh=true.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
label_idYesThe label/folder ID to list emails from
limitNoMaximum number of emails to return (default: 25)
pageNoPage number for pagination (default: 1)
force_refreshNoBypass cache and fetch fresh data (default: false)

Implementation Reference

  • src/index.ts:269-296 (registration)
    Tool definition/input schema registration for 'hey_list_label_emails' - defines the MCP tool metadata including name, description, readOnlyHint, openWorldHint, and inputSchema (requires label_id, optional limit/page/force_refresh).
    {
      name: "hey_list_label_emails",
      annotations: { readOnlyHint: true, openWorldHint: true },
      description:
        "List emails with a specific label. Returns cached results unless force_refresh=true.",
      inputSchema: {
        type: "object" as const,
        properties: {
          label_id: {
            type: "string",
            description: "The label/folder ID to list emails from",
          },
          limit: {
            type: "number",
            description: "Maximum number of emails to return (default: 25)",
          },
          page: {
            type: "number",
            description: "Page number for pagination (default: 1)",
          },
          force_refresh: {
            type: "boolean",
            description: "Bypass cache and fetch fresh data (default: false)",
          },
        },
        required: ["label_id"],
      },
    },
  • Tool handler/dispatch for 'hey_list_label_emails' - validates label_id via validateId(), clamps limit/page, then calls listLabelEmails() with the label ID and options.
    case "hey_list_label_emails": {
      const labelId = validateId(args?.label_id)
      const limit = clampNumber(args?.limit, 25, 1, 100)
      const page = clampNumber(args?.page, 1, 1, 1000)
      const forceRefresh = (args?.force_refresh as boolean) ?? false
      if (!labelId) {
        return {
          content: [
            {
              type: "text",
              text: "Error: label_id is required and must be valid",
            },
          ],
          isError: true,
        }
      }
      result = await listLabelEmails(labelId, { limit, page, forceRefresh })
      break
    }
  • The actual implementation function listLabelEmails() - delegates to the generic listFolder() helper with cache key 'label_{labelId}' and fetches from '/folders/{labelId}'.
    export async function listLabelEmails(
      labelId: string,
      options: ListOptions = {},
    ): Promise<CachedResult<Email[]>> {
      return listFolder(`label_${labelId}`, `/folders/${labelId}`, options)
    }
  • The shared listFolder() helper function used by listLabelEmails - handles cache check, network fetch, email HTML parsing, and cache update logic.
    async function listFolder(
      folder: string,
      path: string,
      options: ListOptions = {},
    ): Promise<CachedResult<Email[]>> {
      const { limit = 25, page = 1, forceRefresh = false } = options
    
      // Check cache first (only for first page)
      if (!forceRefresh && page === 1 && !needsRefresh(folder)) {
        const cached = getCachedMessages(folder, limit)
        if (cached) {
          return {
            data: cached.messages,
            _cache: cached.metadata,
          }
        }
      }
    
      // Fetch from network
      const fullPath = page > 1 ? `${path}?page=${page}` : path
      const html = await heyClient.fetchHtml(fullPath)
      const emails = extractEmailsFromHtml(html).slice(0, limit)
    
      // Update cache (only for first page)
      if (page === 1) {
        cacheMessages(folder, emails)
        // Cache raw HTML for imbox (enables summary extraction without network)
        if (folder === "imbox") {
          cacheFolderHtml(folder, html)
        }
      }
    
      return {
        data: emails,
        _cache: createNetworkMetadata(),
      }
    }
  • The validateId() helper used to validate the label_id parameter - ensures it's a 1-100 char alphanumeric string with hyphens/underscores.
    function validateId(value: unknown): string | null {
      if (typeof value !== "string") {
        return null
      }
      const trimmed = value.trim()
      // IDs should be 1-100 chars, alphanumeric with hyphens/underscores
      if (trimmed.length === 0 || trimmed.length > 100) {
        return null
      }
      if (!/^[a-zA-Z0-9_-]+$/.test(trimmed)) {
        return null
      }
      return trimmed
    }
Behavior4/5

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

Annotations declare readOnlyHint=true and openWorldHint=true. Description adds that results are cached and force_refresh bypasses cache, which is beyond annotations. No contradictions.

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?

Two concise sentences, front-loaded with purpose, no unnecessary information.

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?

No output schema is provided, and the description does not explain the return format or structure. For a listing tool, agents might benefit from knowing what fields are returned (e.g., subject, date).

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

Parameters3/5

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

Schema coverage is 100% with each parameter described. The description adds context about caching for force_refresh, but otherwise does not significantly enhance understanding of parameters.

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 clearly states the tool lists emails with a specific label. It uses a specific verb and resource, and distinguishes itself from siblings like hey_list_emails and hey_list_collection_emails.

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?

Mentions caching behavior and force_refresh, but does not explicitly guide when to use this tool vs alternatives like hey_list_emails or hey_list_collection_emails. Implicit understanding from the tool name, but lacks direct guidance.

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/Sealjay/mcp-hey'

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