Skip to main content
Glama
pyroprompts

any-chat-completions-mcp

by pyroprompts

chat-with-openai

Send a chat message to OpenAI and receive an AI-generated response. Use this tool for direct chat completions via the any-chat-completions-mcp server.

Instructions

Text chat with OpenAI

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYesThe content of the chat to send to OpenAI

Implementation Reference

  • Handler for the chat tool. Connects to an OpenAI SDK compatible AI Integration. The tool name is dynamically generated as 'chat-with-{AI_CHAT_NAME_CLEAN}' where AI_CHAT_NAME_CLEAN is the lowercase, space-replaced AI_CHAT_NAME env var.
    server.setRequestHandler(CallToolRequestSchema, async (request) => {
      switch (request.params.name) {
        case `chat-with-${AI_CHAT_NAME_CLEAN}`: {
          const content = String(request.params.arguments?.content)
          if (!content) {
            throw new Error("Content is required")
          }
    
          const client = new OpenAI({
            apiKey: AI_CHAT_KEY,
            baseURL: AI_CHAT_BASE_URL,
            timeout: parseInt(`${AI_CHAT_TIMEOUT}`, 10),
          });
    
          try {
            const messages: [OpenAI.ChatCompletionMessageParam]  = [
              { role: 'user', content: content }
            ];
            if (AI_CHAT_SYSTEM_PROMPT) {
              messages.unshift({ role: 'system', content: `${AI_CHAT_SYSTEM_PROMPT}` });
            }
            messages.push();
            const chatCompletion = await client.chat.completions.create({
              messages, 
              model: AI_CHAT_MODEL.trim(), // Trim to remove any whitespace
            });
    
            const responseContent = chatCompletion.choices[0]?.message?.content;
            
            if (!responseContent) {
              throw new Error('No response content received from API');
            }
    
            return {
              content: [
                {
                  type: "text",
                  text: responseContent
                }
              ]
            };
          } catch (error: any) {
            const errorMessage = error.response?.data?.error?.message || error.message || 'Unknown error occurred';
            console.error('Chat completion error:', errorMessage);
            
            return {
              content: [
                {
                  type: "text",
                  text: `Error: ${errorMessage}`
                }
              ],
              isError: true
            };
          }
        }
    
        default:
          throw new Error("Unknown tool");
      }
    });
  • Schema definition for the 'chat-with-{AI_CHAT_NAME_CLEAN}' tool. Input schema requires a 'content' string property.
    tools: [
      {
        name: `chat-with-${AI_CHAT_NAME_CLEAN}`,
        description: `Text chat with ${AI_CHAT_NAME}`,
        inputSchema: {
          type: "object",
          properties: {
            content: {
              type: "string",
              description: `The content of the chat to send to ${AI_CHAT_NAME}`,
            }
          },
          required: ["content"]
        }
      }
  • src/index.ts:78-97 (registration)
    Registration of the tool via ListToolsRequestSchema handler, exposing the dynamically-named chat tool.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: `chat-with-${AI_CHAT_NAME_CLEAN}`,
            description: `Text chat with ${AI_CHAT_NAME}`,
            inputSchema: {
              type: "object",
              properties: {
                content: {
                  type: "string",
                  description: `The content of the chat to send to ${AI_CHAT_NAME}`,
                }
              },
              required: ["content"]
            }
          }
        ]
      };
    });
  • src/index.ts:103-163 (registration)
    Registration of the tool handler via CallToolRequestSchema, matching the dynamic tool name.
    server.setRequestHandler(CallToolRequestSchema, async (request) => {
      switch (request.params.name) {
        case `chat-with-${AI_CHAT_NAME_CLEAN}`: {
          const content = String(request.params.arguments?.content)
          if (!content) {
            throw new Error("Content is required")
          }
    
          const client = new OpenAI({
            apiKey: AI_CHAT_KEY,
            baseURL: AI_CHAT_BASE_URL,
            timeout: parseInt(`${AI_CHAT_TIMEOUT}`, 10),
          });
    
          try {
            const messages: [OpenAI.ChatCompletionMessageParam]  = [
              { role: 'user', content: content }
            ];
            if (AI_CHAT_SYSTEM_PROMPT) {
              messages.unshift({ role: 'system', content: `${AI_CHAT_SYSTEM_PROMPT}` });
            }
            messages.push();
            const chatCompletion = await client.chat.completions.create({
              messages, 
              model: AI_CHAT_MODEL.trim(), // Trim to remove any whitespace
            });
    
            const responseContent = chatCompletion.choices[0]?.message?.content;
            
            if (!responseContent) {
              throw new Error('No response content received from API');
            }
    
            return {
              content: [
                {
                  type: "text",
                  text: responseContent
                }
              ]
            };
          } catch (error: any) {
            const errorMessage = error.response?.data?.error?.message || error.message || 'Unknown error occurred';
            console.error('Chat completion error:', errorMessage);
            
            return {
              content: [
                {
                  type: "text",
                  text: `Error: ${errorMessage}`
                }
              ],
              isError: true
            };
          }
        }
    
        default:
          throw new Error("Unknown tool");
      }
    });
  • Environment variable configuration that determines the tool name. AI_CHAT_NAME is lowercased and spaces replaced with hyphens to form the tool name 'chat-with-{AI_CHAT_NAME_CLEAN}'.
    const AI_CHAT_NAME = process.env.AI_CHAT_NAME;
    const AI_CHAT_TIMEOUT = process.env.AI_CHAT_TIMEOUT || 30000;
    const AI_CHAT_SYSTEM_PROMPT = process.env.AI_CHAT_SYSTEM_PROMPT;
    
    if (!AI_CHAT_BASE_URL) {
      throw new Error("AI_CHAT_BASE_URL is required")
    }
    
    if (!AI_CHAT_KEY) {
      throw new Error("AI_CHAT_KEY is required")
    }
    
    if (!AI_CHAT_MODEL) {
      throw new Error("AI_CHAT_MODEL is required")
    }
    
    if (!AI_CHAT_NAME) {
      throw new Error("AI_CHAT_NAME is required")
    }
    const AI_CHAT_NAME_CLEAN = AI_CHAT_NAME.toLowerCase().replace(' ', '-')
Behavior1/5

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

No annotations are provided, and the description does not disclose any behavioral traits such as whether it is read-only, destructive, or requires authentication. The tool's side effects or limitations are unknown.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, short sentence with no unnecessary words. It is concise, though it does not elaborate on details.

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?

Given the lack of annotations and output schema, the description fails to provide essential context such as expected output, potential side effects, or error conditions. A simple chat tool still benefits from minimal completeness.

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 coverage is 100%, so the schema already documents the lone parameter. The description adds no additional meaning beyond what the schema provides, meeting the baseline for high coverage.

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 'Text chat with OpenAI' clearly states the action (chat) and the resource (OpenAI). It is specific and distinct enough, though very brief.

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 or any alternatives. No usage context or exclusions are given.

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/pyroprompts/any-chat-completions-mcp'

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