Implementation:Openai Openai python Tool Choice MCP
| 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
- Repository: openai-python
- File: src/openai/types/responses/tool_choice_mcp.py
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",
},
)