Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Openai Openai python Tool Choice MCP

From Leeroopedia
Revision as of 13:41, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Openai_Openai_python_Tool_Choice_MCP.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains API_Types, Responses_API
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete type for representing a tool choice configuration that forces the model to call a specific tool on a remote MCP server, provided by the openai-python SDK.

Description

ToolChoiceMcp is a Pydantic model used to force the model to invoke a tool on a remote MCP (Model Context Protocol) server. It requires a server_label identifying which MCP server to use, a type field always set to "mcp", and an optional name field specifying which tool to call on that server. If name is omitted, the model may choose any tool on the specified server.

Usage

Import this type when you need to inspect or type-check an MCP tool choice configuration returned by the API.

Code Reference

Source Location

Signature

class ToolChoiceMcp(BaseModel):
    """Use this option to force the model to call a specific tool on a remote MCP server."""

    server_label: str
    type: Literal["mcp"]
    name: Optional[str] = None

Import

from openai.types.responses import ToolChoiceMcp

I/O Contract

Fields

Name Type Required Description
server_label str Yes The label of the MCP server to use.
type Literal["mcp"] Yes For MCP tools, the type is always mcp.
name Optional[str] No The name of the tool to call on the server. If omitted, the model may choose any tool on the server.

Usage Examples

import openai

client = openai.OpenAI()

response = client.responses.create(
    model="gpt-4o",
    input="Look up the Python asyncio documentation.",
    tools=[{
        "type": "mcp",
        "server_label": "deepwiki",
        "server_url": "https://mcp.deepwiki.com/mcp",
        "require_approval": "never",
    }],
    tool_choice={
        "type": "mcp",
        "server_label": "deepwiki",
    },
)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment