Skip to main content

openai.responses_tools()

Connect Console to an application-owned OpenAI Responses tool loop.

Usage

Source

openai.responses_tools(console: MCPConsole) -> list[ResponsesTool]
openai.responses_tools(console: AsyncMCPConsole) -> list[AsyncResponsesTool]

Pass every tool.definition to responses.create(tools=...). Route model function calls by name; tool(call) executes the selected tool and returns the function_call_output item for the next API request. Text and images in successful results are preserved. MCP tool errors raise RuntimeError, including image results. The application runs this loop and routes any other tools.

Create the adapters after connecting Console, and keep that connection open for the entire loop. With AsyncMCPConsole, the factory returns AsyncResponsesTool objects; await both the model requests and tool(call).

Discovery includes every tool, even when the server has no send tool.

Parameters

console: MCPConsole | AsyncMCPConsole
A connected MCPConsole or AsyncMCPConsole.

Returns

list[ResponsesTool] | list[AsyncResponsesTool]
A list of ResponsesTool or AsyncResponsesTool objects matching the client.

Examples

Install with pip install 'mcp-console[openai]'. Set OPENAI_API_KEY and set OPENAI_MODEL to your model ID. This example registers only Console, feeds each tool result back into the response chain, and prints the final answer:

import os
import mcp_console
from mcp_console import MCPConsole
from openai import OpenAI

with OpenAI() as client, MCPConsole() as console:
    tools = mcp_console.openai.responses_tools(console)
    definitions = [tool.definition for tool in tools]
    by_name = {tool.definition["name"]: tool for tool in tools}
    response = client.responses.create(
        model=os.environ["OPENAI_MODEL"],
        input="Use Python in Console to calculate the mean and sample "
        "standard deviation of [12, 15, 18, 20, 25].",
        tools=definitions,
        parallel_tool_calls=False,
    )
    while calls := [
        item for item in response.output if item.type == "function_call"
    ]:
        response = client.responses.create(
            model=os.environ["OPENAI_MODEL"],
            previous_response_id=response.id,
            input=[by_name[call.name](call) for call in calls],
            tools=definitions,
            parallel_tool_calls=False,
        )
    print(response.output_text)

previous_response_id keeps the conversation, including earlier tool calls. parallel_tool_calls=False requests sequential calls to the persistent Console. Keep passing all tool definitions on each request.