Skip to main content
Glama

List Surveys

list_surveys

Retrieve all surveys created with your API key, ordered newest first, to find a survey ID for retrieving results or closing a survey, and to check which surveys remain open.

Instructions

List all surveys created with the current API key, ordered newest first. Use this to find a survey_id you need for get_results or close_survey, or to check which surveys are still open.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Registration of the 'list_surveys' tool via server.registerTool(), defining its title, description, empty inputSchema, and the handler callback function.
    server.registerTool(
      'list_surveys',
      {
        title: 'List Surveys',
        description: 'List all surveys created with the current API key, ordered newest first. Use this to find a survey_id you need for get_results or close_survey, or to check which surveys are still open.',
        inputSchema: {},
      },
      async () => {
        const apiKeyError = requireApiKey()
        if (apiKeyError) {
          return apiKeyError
        }
    
        const response = await fetch(`${API_BASE_URL}/api/surveys`, {
          headers: {
            Authorization: `Bearer ${process.env.HUMANSURVEY_API_KEY}`,
          },
        })
        const payload = (await response.json().catch(() => null)) as
          | SurveyListItem[]
          | { error?: string }
          | null
    
        if (!response.ok || !Array.isArray(payload)) {
          const error = payload && !Array.isArray(payload) ? payload.error : response.statusText
          return {
            content: [
              {
                type: 'text',
                text: `Failed to list surveys: ${error ?? response.statusText}`,
              },
            ],
            isError: true,
          }
        }
    
        if (payload.length === 0) {
          return {
            content: [
              {
                type: 'text',
                text: 'No surveys found for this API key.',
              },
            ],
          }
        }
    
        const lines = ['ID          Title                    Status   Responses  Created']
    
        payload.forEach((survey) => {
          lines.push(
            [
              survey.id.padEnd(10),
              truncate(survey.title, 24).padEnd(24),
              (survey.status ?? 'open').padEnd(8),
              String(survey.response_count ?? 0).padEnd(10),
              (survey.created_at ?? '').slice(0, 10),
            ].join('  '),
          )
        })
    
        return {
          content: [
            {
              type: 'text',
              text: lines.join('\n'),
            },
          ],
        }
      },
    )
  • Handler function for 'list_surveys' that validates API key with requireApiKey(), fetches surveys from the API, checks for errors, handles empty results, and formats the output as a text table with ID, title, status, responses, and created date.
    async () => {
      const apiKeyError = requireApiKey()
      if (apiKeyError) {
        return apiKeyError
      }
    
      const response = await fetch(`${API_BASE_URL}/api/surveys`, {
        headers: {
          Authorization: `Bearer ${process.env.HUMANSURVEY_API_KEY}`,
        },
      })
      const payload = (await response.json().catch(() => null)) as
        | SurveyListItem[]
        | { error?: string }
        | null
    
      if (!response.ok || !Array.isArray(payload)) {
        const error = payload && !Array.isArray(payload) ? payload.error : response.statusText
        return {
          content: [
            {
              type: 'text',
              text: `Failed to list surveys: ${error ?? response.statusText}`,
            },
          ],
          isError: true,
        }
      }
    
      if (payload.length === 0) {
        return {
          content: [
            {
              type: 'text',
              text: 'No surveys found for this API key.',
            },
          ],
        }
      }
    
      const lines = ['ID          Title                    Status   Responses  Created']
    
      payload.forEach((survey) => {
        lines.push(
          [
            survey.id.padEnd(10),
            truncate(survey.title, 24).padEnd(24),
            (survey.status ?? 'open').padEnd(8),
            String(survey.response_count ?? 0).padEnd(10),
            (survey.created_at ?? '').slice(0, 10),
          ].join('  '),
        )
      })
    
      return {
        content: [
          {
            type: 'text',
            text: lines.join('\n'),
          },
        ],
      }
    },
  • Type definition for SurveyListItem used to type the response payload from the /api/surveys endpoint.
    type SurveyListItem = {
      id: string
      title: string
      status?: string
      response_count?: number
      created_at?: string
    }
  • Input schema definition for list_surveys — an empty object (no parameters required).
      description: 'List all surveys created with the current API key, ordered newest first. Use this to find a survey_id you need for get_results or close_survey, or to check which surveys are still open.',
      inputSchema: {},
    },
  • Helper function requireApiKey() that checks for the HUMANSURVEY_API_KEY environment variable and returns an error response if missing.
    function requireApiKey() {
      if (process.env.HUMANSURVEY_API_KEY) {
        return null
      }
    
      return {
        content: [
          {
            type: 'text' as const,
            text: 'No API key found. Call the create_key tool first — it takes no arguments and will provision a key immediately. The key will be active for this session and you can then proceed with create_survey.',
          },
        ],
        isError: true,
      }
    }
Behavior4/5

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

Discloses ordering and scope (surveys with current API key) but no annotations exist. For a simple read-only list, this is sufficient; no destructive actions are implied.

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 sentences, front-loaded with action, no waste. Efficient and clear.

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

Completeness5/5

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

For a zero-parameter, no-output-schema tool, description covers purpose, ordering, and use cases. Complexity is low, and description is complete.

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?

No parameters, so baseline 4 applies. Description adds no parameter info as none exist.

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?

Description clearly states the tool lists all surveys created with the current API key, ordered newest first, and distinguishes it from sibling tools like get_results and close_survey.

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

Usage Guidelines4/5

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

Explicitly says when to use: to find a survey_id for get_results or close_survey, or check open surveys. Does not specify when not to use, but context is clear.

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/sunsiyuan/human-survey'

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