Skip to main content
Glama

get_all_global_fields

Retrieve all global fields with pagination and branch information options, enabling efficient management and organization of content structure in Contentstack MCP.

Instructions

Retrieves a list of all global fields, with options for pagination and including branch information.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
include_branch_infoNoInclude branch information in response
include_countNoInclude total count of global fields
limitNoNumber of global fields to return (max 100)
skipNoNumber of global fields to skip (for pagination)

Implementation Reference

  • Full inline implementation of the 'get_all_global_fields' tool handler, including registration, input schema (Zod), API call to Contentstack, response formatting, and error handling.
    server.tool(
      'get_all_global_fields',
      'Retrieves a list of all global fields, with options for pagination and including branch information.',
      {
        include_count: z.boolean().optional().default(false).describe('Include total count of global fields'),
        skip: z.number().optional().default(0).describe('Number of global fields to skip (for pagination)'),
        limit: z.number().optional().default(100).describe('Number of global fields to return (max 100)'),
        include_branch_info: z.boolean().optional().default(false).describe('Include branch information in response'),
      },
      async ({ include_count, skip, limit, include_branch_info }) => {
        try {
          const url = new URL(`${API_BASE_URL}/global_fields`)
    
          // Add query parameters if needed
          if (include_count) {
            url.searchParams.append('include_count', 'true')
          }
    
          if (skip > 0) {
            url.searchParams.append('skip', skip.toString())
          }
    
          if (limit !== 100) {
            url.searchParams.append('limit', limit.toString())
          }
    
          if (include_branch_info) {
            url.searchParams.append('include_branch_info', 'true')
          }
    
          const response = await axios.get<GlobalFieldsResponse>(url.toString(), {
            headers: getHeaders(),
          })
    
          // Format the response
          let formattedResponse = ''
    
          if (include_count && response.data.count) {
            formattedResponse += `Total global fields: ${response.data.count}\n\n`
          }
    
          formattedResponse += `Global fields retrieved: ${response.data.global_fields.length}\n\n`
    
          if (response.data.global_fields.length > 0) {
            // For large result sets, show a summary
            if (response.data.global_fields.length > 10) {
              formattedResponse += 'First 10 global fields:\n'
              for (let i = 0; i < 10; i++) {
                const globalField = response.data.global_fields[i]
                formattedResponse += `${i + 1}. ${globalField.uid} - ${globalField.title}\n`
              }
              formattedResponse += `\n(${response.data.global_fields.length - 10} more global fields not shown)\n\n`
            } else {
              formattedResponse += 'Global fields:\n'
              response.data.global_fields.forEach((globalField, index) => {
                formattedResponse += `${index + 1}. ${globalField.uid} - ${globalField.title}\n`
              })
              formattedResponse += '\n'
            }
    
            formattedResponse += `Full response data:\n${JSON.stringify(response.data, null, 2)}`
          } else {
            formattedResponse += 'No global fields found.'
          }
    
          return {
            content: [
              {
                type: 'text',
                text: formattedResponse,
              },
            ],
          }
        } catch (error) {
          return {
            content: [
              {
                type: 'text',
                text: `Error retrieving global fields: ${handleError(error as ApiError)}`,
              },
            ],
            isError: true,
          }
        }
      },
    )
  • TypeScript interface defining the response structure for global fields API.
    export interface GlobalFieldsResponse {
      global_fields: GlobalField[]
      count?: number
    }
  • Helper function to generate authentication headers used in the API request.
    const getHeaders = () => {
      const headers: Record<string, string> = {
        'Content-Type': 'application/json',
        api_key: API_KEY,
      }
    
      // Use management token
      if (MANAGEMENT_TOKEN) {
        headers.authorization = MANAGEMENT_TOKEN
      }
    
      // Include branch header if specified
      if (BRANCH) {
        headers.branch = BRANCH
      }
    
      return headers
  • Helper function to format error messages from API responses, used in error handling.
    const handleError = (error: ApiError): string => {
      if (error.response) {
        return `API Error: ${error.response.status} - ${JSON.stringify(error.response.data)}`
      }
      if (error.request) {
        return `No response received: ${error.request}`
      }
      return `Error: ${error.message}`
Behavior2/5

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

With no annotations provided, the description carries full burden but only mentions pagination and branch info options. It doesn't disclose whether this is a read-only operation, potential rate limits, authentication requirements, or what the response structure looks like (especially critical without an output schema).

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 a single, efficient sentence that front-loads the core purpose and briefly mentions key features. Every word serves a purpose with no redundancy or unnecessary elaboration.

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

Completeness2/5

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

For a list retrieval tool with 4 parameters and no output schema, the description is insufficient. It doesn't explain the return format, what 'global fields' represent in this context, or how results are ordered. Without annotations or output schema, more behavioral context is needed for proper agent usage.

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 description coverage is 100%, so the schema fully documents all four parameters. The description adds minimal value by mentioning 'pagination' (implied by limit/skip) and 'including branch information' (matching include_branch_info), but doesn't provide additional context beyond what's in the schema.

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 verb 'retrieves' and resource 'global fields', making the purpose unambiguous. It distinguishes from siblings like 'get_global_field' (singular) by specifying 'all global fields', though it doesn't explicitly contrast with other list operations like 'get_all_content_types'.

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?

No guidance is provided on when to use this tool versus alternatives like 'get_global_field' or other list operations. The description mentions pagination and branch info options but doesn't specify use cases or prerequisites for invoking this tool.

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/darekrossman/contentstack-mcp'

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