MCP Calling in OCI Generative AI

MCP (Model Context Protocol) tools are executable functions or capabilities that AI models can use to interact with external systems. Use MCP Calling in OCI Generative AI to let a model access executable tools exposed by a remote MCP server during a Responses API request. These tools can provide access to external systems such as API, databases, file systems, or application endpoints. OCI Generative AI communicates directly with remote MCP servers as part of the request workflow.

Note

The OCI MCP calling tool uses the same format as the OpenAI MCP calling for the Responses API, with the OCI OpenAI-compatible endpoint. For syntax and request details, see the OpenAI MCP documentation.

When To Use MCP Calling

Use MCP Calling when the model needs access to tools hosted on a remote MCP server. This approach is useful when you want:

  • The Enterprise AI Agent platform to communicate with the MCP server directly
  • Fewer client-side orchestration steps
  • Lower latency than a client-executed tool pattern
  • Access to tools exposed through a remote MCP server

Key Features

MCP Calling provides the following benefits:

  • Direct platform-to-server communication: Unlike standard function calling, which returns control to the client application, MCP Calling lets OCI Generative AI communicate directly with the remote MCP server.
  • Lower latency: Because the request doesn't require an extra client round trip, MCP Calling can reduce orchestration overhead.

  • Transport Support: Supports Streamable HTTP (SSE deprecated and unsupported).

Defining an MCP Tool

To define an MCP tool, add an entry in the tools property with "type": "mcp".

response_stream = client.responses.create(
    model="openai.gpt-5.4",
    tools=[
        {
            "type": "mcp",
            "server_label": "dmcp",
            "server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",
            "server_url": "https://mcp.deepwiki.com/mcp",
            "require_approval": "never",
        },
    ],
    input="Roll 2d4+1",
    stream=True,
)

for event in response_stream:
    if event.type == "response.output_text.delta":
        print(event.delta, end="", flush=True)

This example streams the response and prints text as it's generated.

Restrict the Tools Exposed by an MCP Server

A remote MCP server can expose many tools, which can increase cost and latency. If the application needs only a subset of those tools, use allowed_tools to limit the set.

response_stream = client.responses.create(
    model="openai.gpt-oss-120b",
    tools=[
        {
            "type": "mcp",
            "server_label": "dmcp",
            "server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",
            "server_url": "https://mcp.deepwiki.com/mcp",
            "require_approval": "never",
            "allowed_tools": ["roll"],
        },
    ],
    input="Roll 2d4+1",
    stream=True,
    store=False,
)

Provide Authentication to the MCP Server

If the remote MCP server requires authentication, pass the access token in the authorization field.

response_stream = client.responses.create(
    model="xai.grok-4-1-fast-reasoning",
    tools=[
        {
            "type": "mcp",
            "server_label": "calendar",
            "server_url": "https://calendar.example.com/mcp",
            "authorization": "$CALENDAR_OAUTH_ACCESS_TOKEN"
        },
    ],
    input="List my meetings for 2026-02-02.",
    stream=True
)

Pass only the raw token value. Don't include the Bearer prefix.

OCI sends the token in the API request body over TLS. OCI doesn't decode, inspect, store, or log the token. We recommend that you use TLS-encrypted MCP server endpoints.