Realtime does not execute tool calls
Author: hemaAICreated Apr 26, 2026Updated May 9, 2026
I have connected my realtime sip app with twilio but it never does tool calls. Can you take a look at my code? I am sure that the mcp is working. I tested it with npx @modelcontextprotocol/inspector The logs of the app only show my tool intro message from the instructions where it says "one moment, let me take a look"
from flask import Flask, request, Response
from openai import OpenAI, InvalidWebhookSignatureError
import asyncio
import json
import os
import requests
import time
import threading
import websockets
app = Flask(__name__)
client = OpenAI(
webhook_secret=os.environ["OPENAI_WEBHOOK_SECRET"]
)
AUTH_HEADER = {
"api-key": os.getenv("OPENAI_API_KEY")
}
AZURE_RESOURCE_NAME = os.getenv("AZURE_RESOURCE_NAME")
LANGFLOW_API_KEY = os.getenv("LANGFLOW_API_KEY")
response_create = {
"type": "response.create",
"response": {
"instructions": (
os.getenv("GREETING")
)
},
}
call_accept = {
"type": "realtime",
"instructions": os.getenv("INSTRUCTIONS", "You are a support agent."),
"model": os.getenv("REALTIME_MODEL", "gpt-realtime-1.5"),
"tools": [
{
"type": "mcp",
"server_label": os.getenv("LANGFLOW_SERVER_LABEL", "lf-search"),
"server_url": os.getenv("LANGFLOW_MCP_URL"),
"allowed_tools": ["search"],
"headers": {
"x-api-key": os.getenv("LANGFLOW_API_KEY")
},
"require_approval": "never"
}
]
}
async def websocket_task(call_id):
try:
async with websockets.connect(
f"wss://{AZURE_RESOURCE_NAME}.openai.azure.com/openai/v1/realtime?call_id=" + call_id,
additional_headers=AUTH_HEADER,
) as websocket:
await websocket.send(json.dumps(response_create))
while True:
response = await websocket.recv()
print(f"Received from WebSocket: {response}")
except Exception as e:
print(f"WebSocket error: {e}")
@app.route("/", methods=["POST"])
def webhook():
try:
event = client.webhooks.unwrap(request.data, request.headers)
if event.type == "realtime.call.incoming":
requests.post(
f"https://{AZURE_RESOURCE_NAME}.openai.azure.com/openai/v1/realtime/calls/"
+ event.data.call_id
+ "/accept",
headers={**AUTH_HEADER, "Content-Type": "application/json"},
json=call_accept,
)
threading.Thread(
target=lambda: asyncio.run(
websocket_task(event.data.call_id)
),
daemon=True,
).start()
return Response(status=200)
except InvalidWebhookSignatureError as e:
print("Invalid signature", e)
return Response("Invalid signature", status=400)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)Source: openai/openai-realtime-agents