Skip to main content
Glama
BrewMyTech

Grok MCP Server

by BrewMyTech

create_completion

Generate text completions using the Grok API by specifying a model, prompt, and parameters like temperature, max tokens, and penalties to tailor output effectively.

Instructions

Create a text completion with the Grok API

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
best_ofNoGenerate best_of completions server-side and return the best one
echoNoEcho back the prompt in addition to the completion
frequency_penaltyNoPenalty for new tokens based on frequency in text (-2 to 2)
logit_biasNoMap of token IDs to bias scores (-100 to 100) that influence generation
logprobsNoInclude log probabilities on most likely tokens (0-5)
max_tokensNoMaximum number of tokens to generate
modelYesID of the model to use
nNoNumber of completions to generate
presence_penaltyNoPenalty for new tokens based on presence in text (-2 to 2)
promptYesThe prompt(s) to generate completions for
seedNoIf specified, results will be more deterministic when the same seed is used
stopNoSequences where the API will stop generating further tokens
streamNoWhether to stream back partial progress
suffixNoThe suffix that comes after a completion of inserted text
temperatureNoSampling temperature (0-2)
top_pNoNucleus sampling parameter (0-1)
userNoA unique user identifier

Implementation Reference

  • Core handler function that performs the POST request to the Grok completions endpoint and validates the response.
    export async function createCompletion(
      options: z.infer<typeof CompletionsRequestSchema>
    ): Promise<z.infer<typeof CompletionsResponseSchema>> {
      const response = await grokRequest("completions", {
        method: "POST",
        body: options,
      });
    
      return CompletionsResponseSchema.parse(response);
    }
  • Zod schema defining the input parameters for the create_completion tool.
    export const CompletionsRequestSchema = z.object({
      model: z.string().describe("ID of the model to use"),
      prompt: z
        .union([z.string(), z.array(z.string())])
        .describe("The prompt(s) to generate completions for"),
      suffix: z
        .string()
        .optional()
        .describe("The suffix that comes after a completion of inserted text"),
      max_tokens: z
        .number()
        .int()
        .positive()
        .optional()
        .describe("Maximum number of tokens to generate"),
      temperature: z
        .number()
        .min(0)
        .max(2)
        .optional()
        .describe("Sampling temperature (0-2)"),
      top_p: z
        .number()
        .min(0)
        .max(1)
        .optional()
        .describe("Nucleus sampling parameter (0-1)"),
      n: z
        .number()
        .int()
        .positive()
        .optional()
        .describe("Number of completions to generate"),
      stream: z
        .boolean()
        .optional()
        .describe("Whether to stream back partial progress"),
      logprobs: z
        .number()
        .int()
        .min(0)
        .max(5)
        .optional()
        .describe("Include log probabilities on most likely tokens (0-5)"),
      echo: z
        .boolean()
        .optional()
        .describe("Echo back the prompt in addition to the completion"),
      stop: z
        .union([z.string(), z.array(z.string())])
        .optional()
        .describe("Sequences where the API will stop generating further tokens"),
      presence_penalty: z
        .number()
        .min(-2)
        .max(2)
        .optional()
        .describe("Penalty for new tokens based on presence in text (-2 to 2)"),
      frequency_penalty: z
        .number()
        .min(-2)
        .max(2)
        .optional()
        .describe("Penalty for new tokens based on frequency in text (-2 to 2)"),
      logit_bias: z
        .record(z.string(), z.number())
        .optional()
        .describe(
          "Map of token IDs to bias scores (-100 to 100) that influence generation"
        ),
      seed: z
        .number()
        .int()
        .optional()
        .describe(
          "If specified, results will be more deterministic when the same seed is used"
        ),
      best_of: z
        .number()
        .int()
        .positive()
        .optional()
        .describe(
          "Generate best_of completions server-side and return the best one"
        ),
      user: z.string().optional().describe("A unique user identifier"),
    });
  • index.ts:124-136 (registration)
    Registration of the create_completion tool in the FastMCP server, which delegates to the handler function.
    server.addTool({
      name: "create_completion",
      description: "Create a text completion with the Grok API",
      parameters: completions.CompletionsRequestSchema,
      execute: async (args) => {
        try {
          const result = await completions.createCompletion(args);
          return JSON.stringify(result, null, 2);
        } catch (err) {
          handleError(err);
        }
      },
    });
  • Zod schema for validating the response from the completions API.
    const CompletionsResponseSchema = z.object({
      id: z.string(),
      object: z.string(),
      created: z.number(),
      model: z.string(),
      choices: z.array(CompletionsChoiceSchema),
      usage: z.object({
        prompt_tokens: z.number(),
        completion_tokens: z.number(),
        total_tokens: z.number(),
      }),
    });
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 but offers minimal information. It states the tool creates completions but doesn't mention whether this is a read or write operation, potential costs/rate limits, authentication requirements, or what the output looks like. For a 17-parameter tool with complex behavior, this is insufficient.

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 states the core purpose without unnecessary words. It's appropriately sized for a tool with extensive schema documentation and gets straight to the point with zero wasted text.

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 complex text generation tool with 17 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what a 'completion' actually returns, doesn't mention typical use cases, and provides no behavioral context beyond the basic action. The agent would need to rely heavily on the schema alone to understand this tool's functionality.

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?

The schema description coverage is 100%, with all parameters well-documented in the schema itself. The description adds no additional parameter information beyond what's already in the schema, so it meets the baseline expectation but doesn't provide extra value. The description doesn't explain relationships between parameters or provide usage examples.

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 ('Create a text completion') and target ('with the Grok API'), providing a specific verb+resource combination. However, it doesn't differentiate this tool from its sibling 'create_chat_completion' which suggests a similar purpose but for chat-based interactions.

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?

The description provides no guidance on when to use this tool versus alternatives like 'create_chat_completion' or 'create_embeddings'. There's no mention of appropriate contexts, prerequisites, or exclusions that would help an agent choose between these text generation options.

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/BrewMyTech/grok-mcp'

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