Skip to main content
Glama

chat

Get AI assistance for general questions, creative writing, coding help, and text tasks using Grok models with optional conversation history and customizable parameters.

Instructions

Basic chat completion with Grok models - your standard conversational AI tool. Use this for general questions, creative writing, coding help, or any text task. You can optionally keep conversation history to maintain context across multiple exchanges. For reasoning models, use the reasoning_effort parameter. For other models, you have more control with penalties and stop sequences. Args: prompt: What you want to ask or have the AI do model: Which Grok model to use (default is grok-4-fast) system_prompt: Instructions for how the AI should behave (only used at start) use_conversation_history: Keep context between messages (default False) temperature: Creativity level 0-2 (higher = more creative) max_tokens: Maximum length of response top_p: Alternative to temperature for controlling randomness presence_penalty: Penalize talking about same topics (-2.0 to 2.0) frequency_penalty: Penalize repeating the same words (-2.0 to 2.0) stop: List of sequences where the AI should stop generating reasoning_effort: "low" or "high" for reasoning models only (grok-3-mini) Returns the AI's response as a string.

Input Schema

NameRequiredDescriptionDefault
promptYes
modelNogrok-4-fast
system_promptNo
use_conversation_historyNo
temperatureNo
max_tokensNo
top_pNo
presence_penaltyNo
frequency_penaltyNo
stopNo
reasoning_effortNo

Input Schema (JSON Schema)

{ "properties": { "frequency_penalty": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "default": null, "title": "Frequency Penalty" }, "max_tokens": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": null, "title": "Max Tokens" }, "model": { "default": "grok-4-fast", "title": "Model", "type": "string" }, "presence_penalty": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "default": null, "title": "Presence Penalty" }, "prompt": { "title": "Prompt", "type": "string" }, "reasoning_effort": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Reasoning Effort" }, "stop": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Stop" }, "system_prompt": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "System Prompt" }, "temperature": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "default": null, "title": "Temperature" }, "top_p": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "default": null, "title": "Top P" }, "use_conversation_history": { "default": false, "title": "Use Conversation History", "type": "boolean" } }, "required": [ "prompt" ], "type": "object" }

Implementation Reference

  • The handler function for the 'chat' tool, including its registration via @mcp.tool(), parameter definitions serving as schema, and the full execution logic for performing chat completions with Grok models via the xAI API.
    @mcp.tool() async def chat( prompt: str, model: str = "grok-4-fast", system_prompt: Optional[str] = None, use_conversation_history: bool = False, temperature: Optional[float] = None, max_tokens: Optional[int] = None, top_p: Optional[float] = None, presence_penalty: Optional[float] = None, frequency_penalty: Optional[float] = None, stop: Optional[List[str]] = None, reasoning_effort: Optional[str] = None ) -> str: """ Basic chat completion with Grok models - your standard conversational AI tool. Use this for general questions, creative writing, coding help, or any text task. You can optionally keep conversation history to maintain context across multiple exchanges. For reasoning models, use the reasoning_effort parameter. For other models, you have more control with penalties and stop sequences. Args: prompt: What you want to ask or have the AI do model: Which Grok model to use (default is grok-4-fast) system_prompt: Instructions for how the AI should behave (only used at start) use_conversation_history: Keep context between messages (default False) temperature: Creativity level 0-2 (higher = more creative) max_tokens: Maximum length of response top_p: Alternative to temperature for controlling randomness presence_penalty: Penalize talking about same topics (-2.0 to 2.0) frequency_penalty: Penalize repeating the same words (-2.0 to 2.0) stop: List of sequences where the AI should stop generating reasoning_effort: "low" or "high" for reasoning models only (grok-3-mini) Returns the AI's response as a string. """ global conversation_history if not use_conversation_history: conversation_history = [] messages = [] if system_prompt and len(conversation_history) == 0: messages.append({ "role": "system", "content": system_prompt }) messages.extend(conversation_history) messages.append({ "role": "user", "content": prompt }) request_data = { "model": model, "messages": messages } if temperature is not None: request_data["temperature"] = temperature if max_tokens is not None: request_data["max_tokens"] = max_tokens if top_p is not None: request_data["top_p"] = top_p is_reasoning = is_reasoning_model(model) if is_reasoning: # reasoning_effort only for grok-3-mini if reasoning_effort and model != "grok-4": if reasoning_effort not in ["low", "high"]: raise ValueError("reasoning_effort must be 'low' or 'high'") request_data["reasoning_effort"] = reasoning_effort else: # These parameters only work with non reasoning models if presence_penalty is not None: request_data["presence_penalty"] = presence_penalty if frequency_penalty is not None: request_data["frequency_penalty"] = frequency_penalty if stop is not None: request_data["stop"] = stop timeout = get_model_timeout(model) client = create_client(timeout=timeout) response = await client.post("/chat/completions", json=request_data) response.raise_for_status() data = response.json() await client.aclose() assistant_response = data["choices"][0]["message"]["content"] if use_conversation_history: conversation_history.append({ "role": "user", "content": prompt }) conversation_history.append({ "role": "assistant", "content": assistant_response }) return assistant_response

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/merterbak/Grok-MCP'

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