Skip to content

AI assistants

Call the Qelka MCP server from the OpenAI API

Add the Qelka MCP server as a remote MCP tool in the OpenAI Responses API with your key in a header, allowed tools and approvals, then read the mcp_call items.

Updated 2026-11-26

This recipe lets an OpenAI model call the Qelka checks from the Responses API. You add the Qelka MCP server as a remote MCP tool, OpenAI connects to it, imports the tools you allow, and runs the calls the model decides to make: verify an email, validate a phone number, look up an IP. Your code sends one request and reads the calls and the answer.

The server at https://mcp.qelka.com/mcp speaks Streamable HTTP, is stateless, and authenticates with your API key in an Authorization: Bearer header. For ChatGPT itself, which needs OAuth for connectors, follow the ChatGPT setup page instead.

What you need

  • An OpenAI API key, read from OPENAI_API_KEY by the SDK, and a current release of the OpenAI SDK: openai for Node.js or Python.
  • A model that supports the MCP tool in the Responses API. The examples use gpt-6.2-astra, the model OpenAI's MCP guide uses at the time of writing; check their model pages for the current list.
  • A Qelka API key in the QELKA_API_KEY environment variable of your server. Start with a sk_test_ key: tools return simulated, fixed answers and never spend credits. See Test mode.
  • Preferably a restricted key, since it travels to OpenAI in each request: tick the endpoints the model should call, plus account for get_account. See restricted keys.

Both keys stay on your server. Never send them to a browser.

Steps

1. Send a request with the MCP tool

import OpenAI from 'openai'

const client = new OpenAI({ timeout: 300_000 })

try {
  const response = await client.responses.create({
    model: 'gpt-6.2-astra',
    input: 'Check jane@example.com and +1 415 555 0123. Which one should I not contact, and why?',
    tools: [
      {
        type: 'mcp',
        server_label: 'qelka',
        server_description: 'Validates phone numbers, email addresses and IP addresses.',
        server_url: 'https://mcp.qelka.com/mcp',
        headers: { Authorization: `Bearer ${process.env.QELKA_API_KEY}` },
        allowed_tools: ['verify_email', 'validate_phone', 'get_account'],
        require_approval: 'never',
      },
    ],
  })

  for (const item of response.output) {
    if (item.type === 'mcp_call') {
      console.log(`called ${item.name} ${item.arguments}`)
      if (item.error) console.log('tool refused', item.error)
    }
  }
  console.log(response.output_text)
} catch (error) {
  if (!(error instanceof OpenAI.APIError)) throw error
  console.log(`check skipped: OpenAI API ${error.status ?? 'unreachable'} ${error.message}`)
}
import os

import openai
from openai import OpenAI

client = OpenAI(timeout=300.0)

try:
    response = client.responses.create(
        model="gpt-6.2-astra",
        input="Check jane@example.com and +1 415 555 0123. Which one should I not contact, and why?",
        tools=[
            {
                "type": "mcp",
                "server_label": "qelka",
                "server_description": "Validates phone numbers, email addresses and IP addresses.",
                "server_url": "https://mcp.qelka.com/mcp",
                "headers": {"Authorization": f"Bearer {os.environ['QELKA_API_KEY']}"},
                "allowed_tools": ["verify_email", "validate_phone", "get_account"],
                "require_approval": "never",
            }
        ],
    )
except openai.APIError as error:
    print(f"check skipped: {type(error).__name__} {error.message}")
else:
    for item in response.output:
        if item.type == "mcp_call":
            print("called", item.name, item.arguments)
            if item.error:
                print("tool refused", item.error)
    print(response.output_text)
  • headers carries your key to the Qelka server. OpenAI describes this field as the place for HTTP headers the server needs, authentication included.
  • allowed_tools imports only the listed tools out of the server's 12. Fewer tool definitions mean fewer input tokens and fewer ways for the model to spend credits.
  • require_approval: "never" lets the model call the tools without a round trip to your code. OpenAI's default is to ask for approval on every call; step 3 shows that flow.
  • The client timeout bounds the whole request, tool calls included. Treat a timeout as "not checked".

2. Read the output items

The response output records what happened:

Item Fields What to do with it
mcp_list_tools server_label, tools The tools OpenAI imported. Keep this item in the conversation context on follow-up turns and OpenAI does not list them again
mcp_call name, arguments (a JSON string), output, error output is the tool's JSON result as text. error is set when the call failed, with the API's message, error type and HTTP status
message text content The model's answer, also in output_text

The JSON in a successful output is the same as the REST response. If your code acts on results, parse output rather than the prose:

Result What to do
Email undeliverable Do not send to it; show did_you_mean when there is one
Email risky Disposable, catch-all or full mailbox: flag it for review
Email unknown, or a call with an error Not conclusive: keep the contact and check again later
Phone invalid Ask for the number again
Phone unknown The number has no + and no country was given: say which country it is from
Phone valid Store e164 and use it for calls and messages

See the email reference and the phone reference for every field.

3. Approve calls from your code (optional)

When the input comes from your users, you may want to see each call before it runs. Leave out require_approval, or set it to "always", and the response stops with an mcp_approval_request item holding the tool name and arguments. Send your decision in a new request that points at the previous response:

const approvals = first.output
  .filter((item) => item.type === 'mcp_approval_request')
  .map((item) => ({
    type: 'mcp_approval_response',
    approval_request_id: item.id,
    approve: ['verify_email', 'validate_phone', 'get_account'].includes(item.name),
  }))

const second = await client.responses.create({
  model: 'gpt-6.2-astra',
  previous_response_id: first.id,
  tools,
  input: approvals,
})
console.log(second.output_text)
approvals = [
    {
        "type": "mcp_approval_response",
        "approval_request_id": item.id,
        "approve": item.name in {"verify_email", "validate_phone", "get_account"},
    }
    for item in first.output
    if item.type == "mcp_approval_request"
]

second = client.responses.create(
    model="gpt-6.2-astra",
    previous_response_id=first.id,
    tools=tools,
    input=approvals,
)
print(second.output_text)

Here tools is the same tools array as in step 1, without require_approval: "never", and first is the response to that request. Send the full tools array again, header included: the decision request needs it to reach the server. require_approval also takes an object, so you can skip approval for some tools only, for example { "never": { "tool_names": ["get_account"] } }. Every Qelka tool is marked read-only, so { "never": { "read_only": true } } skips approvals for all of them.

4. Check the connection and the key mode

Send the request of step 1 with this input:

Prompt
What is my Qelka credit balance, and is this key in test or live mode?

The model calls get_account, which is free, and answers with your plan, balance and key.mode. Run this check when your service starts: production running with a sk_test_ key would trust simulated answers.

Credits and limits

Each tool call is one Qelka API request made with your key, billed, cached and rate limited like a REST call:

Tool Credits
verify_email 1
validate_phone 1 at basic, 3 at live
lookup_ip 1
get_account 0

The server tells models to prefer the fast email mode, which skips the mailbox check and answers quickly, and the basic phone level. Ask for "check that the mailbox exists" or "the current carrier" in your input when you need mode: "full" or level: "live". A long list can turn into one call per item, so cap it in your code, and use a bulk job for thousands of rows.

Handle errors and rate limits

Two layers can fail, and neither should block your product: when the request throws or times out, treat every check as unchecked and retry later.

What happens Cause Fix
The SDK raises an error An OpenAI problem: wrong OpenAI key, a model without MCP support, a timeout Log the error class and status, then fail open
OpenAI reports that it could not list the server's tools The Authorization header is empty or not Bearer sk_live_... or Bearer sk_test_...: the server answers 401 Check that QELKA_API_KEY is set where your code runs
mcp_call with invalid_api_key in error The key is well formed but revoked or mistyped Create a new key and redeploy
mcp_call with forbidden The key is restricted and the tool's endpoint is not in its list Use a key that allows it, or drop the tool from allowed_tools
mcp_call with insufficient_credits Your balance cannot cover the call Add credits; nothing was billed
mcp_call with rate_limited and "Retry after N seconds." A key allows 200 requests per 10 seconds Send fewer items per request, or wait and resend

Refused tool calls are never billed. See Errors and Rate limits.

Frequently asked questions

Should I put the key in headers or in authorization?
OpenAI documents authorization for OAuth access tokens and headers for any HTTP header the server needs, including for authentication. The Qelka server reads a plain Authorization: Bearer header with your API key, so this guide sends it through headers. Send it on every request: the key is part of the tool definition.
Can I connect the server to ChatGPT instead?
Not as a connector: ChatGPT connects to remote MCP servers through OAuth, which the Qelka server does not offer. A custom GPT with an action calls the REST API with your key instead, and the ChatGPT setup page walks through it. The Responses API in this guide is the way to use the MCP server from OpenAI models in your own code.
Does OpenAI charge for the tool calls?
According to OpenAI's guide, you pay only for the tokens used to import tool definitions and make tool calls, with no fee per call; their pricing can change. Qelka bills each tool call at the price of the matching API call, and get_account is free. A sk_test_ key makes every call free and simulated.

More in AI assistants

All integrations

Put this check in your product

Get an API key in under a minute. 100 free credits every month, no card required.

  • 100 free credits a month
  • No card
  • Test keys spend nothing
  • Cancel any time