Skip to main content
Glama

ask_openai

Query OpenAI GPT models to get AI-generated responses for prompts, supporting various model versions and temperature settings.

Instructions

Ask OpenAI GPT models a question

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesThe prompt to send to OpenAI
modelNoThe model to use (default: gpt-4o-mini)gpt-4o-mini
temperatureNoTemperature for response generation (0-2)

Implementation Reference

  • The handler function that executes the 'ask_openai' tool logic. Validates inputs, calls OpenAI chat completions API, handles specific errors like rate limits, and formats the response as MCP content.
    async handleOpenAI(args) {
      if (!this.openai) {
        throw new ConfigurationError(ERROR_MESSAGES.OPENAI_NOT_CONFIGURED);
      }
    
      // Validate inputs
      const prompt = validatePrompt(args.prompt);
      const model = validateModel(args.model, 'OPENAI');
      const temperature = validateTemperature(args.temperature, 'OPENAI');
    
      try {
        if (process.env.NODE_ENV !== 'test') logger.debug(`OpenAI request - model: ${model}, temperature: ${temperature}`);
        
        const completion = await this.openai.chat.completions.create({
          model: model,
          messages: [{ role: 'user', content: prompt }],
          temperature: temperature,
        });
    
        return {
          content: [
            {
              type: 'text',
              text: `🤖 OPENAI RESPONSE (${model}):\n\n${completion.choices[0].message.content}`,
            },
          ],
        };
      } catch (error) {
        if (error.status === 429) {
          throw new APIError('OpenAI rate limit exceeded. Please try again later.', 'OpenAI');
        } else if (error.status === 401) {
          throw new ConfigurationError('Invalid OpenAI API key');
        } else {
          throw new APIError(`OpenAI API error: ${error.message}`, 'OpenAI');
        }
      }
    }
  • Input schema for the 'ask_openai' tool, defining properties for prompt (required), model (with enum), and temperature (with bounds). Used for tool specification and validation.
    inputSchema: {
      type: 'object',
      properties: {
        prompt: {
          type: 'string',
          description: 'The prompt to send to OpenAI',
        },
        model: {
          type: 'string',
          description: `The model to use (default: ${DEFAULTS.OPENAI.MODEL})`,
          enum: MODELS.OPENAI,
          default: DEFAULTS.OPENAI.MODEL,
        },
        temperature: {
          type: 'number',
          description: `Temperature for response generation (${DEFAULTS.OPENAI.MIN_TEMPERATURE}-${DEFAULTS.OPENAI.MAX_TEMPERATURE})`,
          default: DEFAULTS.OPENAI.TEMPERATURE,
          minimum: DEFAULTS.OPENAI.MIN_TEMPERATURE,
          maximum: DEFAULTS.OPENAI.MAX_TEMPERATURE,
        },
      },
      required: ['prompt'],
    },
  • src/index.js:90-116 (registration)
    Registers the 'ask_openai' tool in the available tools list (conditionally if OpenAI client is initialized), providing name, description, and input schema for MCP listTools.
    tools.push({
      name: 'ask_openai',
      description: 'Ask OpenAI GPT models a question',
      inputSchema: {
        type: 'object',
        properties: {
          prompt: {
            type: 'string',
            description: 'The prompt to send to OpenAI',
          },
          model: {
            type: 'string',
            description: `The model to use (default: ${DEFAULTS.OPENAI.MODEL})`,
            enum: MODELS.OPENAI,
            default: DEFAULTS.OPENAI.MODEL,
          },
          temperature: {
            type: 'number',
            description: `Temperature for response generation (${DEFAULTS.OPENAI.MIN_TEMPERATURE}-${DEFAULTS.OPENAI.MAX_TEMPERATURE})`,
            default: DEFAULTS.OPENAI.TEMPERATURE,
            minimum: DEFAULTS.OPENAI.MIN_TEMPERATURE,
            maximum: DEFAULTS.OPENAI.MAX_TEMPERATURE,
          },
        },
        required: ['prompt'],
      },
    });
  • src/index.js:174-175 (registration)
    Registers the dispatch for 'ask_openai' tool calls within the main CallToolRequestSchema handler switch statement.
    case 'ask_openai':
      return await this.handleOpenAI(args);
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states the basic action but doesn't mention rate limits, authentication requirements, cost implications, response format, or error handling. For a tool that likely involves API calls with potential constraints, this leaves significant behavioral aspects undocumented.

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 communicates the core purpose without unnecessary words. It's appropriately sized for a straightforward tool and front-loads the essential information. Every word earns its place in this minimal but complete statement.

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 tool with 3 parameters, no annotations, and no output schema, the description provides only basic purpose information. It doesn't address behavioral aspects, return values, error conditions, or usage constraints. Given the complexity of interacting with external AI models and the lack of structured metadata, the description is insufficiently complete.

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%, providing complete parameter documentation. The description doesn't add any parameter-specific information beyond what's in the schema. According to scoring rules, when schema coverage is high (>80%), the baseline is 3 even with no param info in the description, which applies here.

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 action ('ask') and target resource ('OpenAI GPT models'), making the purpose immediately understandable. It distinguishes from the sibling 'ask_gemini' by specifying OpenAI rather than Google's model. However, it doesn't specify what type of question or interaction this enables (e.g., chat completion, text generation), leaving some ambiguity about the exact operation.

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 usage context (when you need to query OpenAI models) but doesn't explicitly state when to use this versus the 'ask_gemini' sibling tool. There's no guidance on prerequisites, limitations, or alternative scenarios. The implied differentiation is present but not articulated clearly enough for optimal agent decision-making.

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/fakoli/mcp-ai-bridge'

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