How to connect a remote MCP server to the OpenAI API with approvals

Day 4, 25 minutes · beginner

Goal of this lessonConnect the OpenAI Docs MCP server to a Responses API call, read each approval request, approve or refuse it, and see what was sent.

Why it matters

Connect a remote MCP server to the OpenAI API in Python and approve or refuse every tool call before it runs, using OpenAI's public docs server. Writing every tool yourself gets slow. Many services now offer an MCP server: a ready set of tools that any AI app can connect to. The OpenAI API can use a remote MCP server for you, straight from a Responses API call, with no tool code of your own.

The catch is trust. When the model uses that server, your data goes to it. So today you connect a server with approvals switched on: before every tool call, your script shows you what the model wants to send, and you say yes or no. You use OpenAI's own public documentation server, which needs no login. You finish with a working connection, an approved and a refused call, and your own rule for when to say no.

What MCP is

MCP (Model Context Protocol) is an open standard for connecting AI apps to tools and data. A server offers tools; a client, here the OpenAI API, lists them and calls them. The MCP for beginners course builds a server of your own, if you want to see the other side.

With the Responses API you add the server as a tool of type mcp:

  • server_label: a short name you choose.
  • server_url: the address of the server. It must be on the public internet, because OpenAI's servers call it, not your laptop. OpenAI has a separate feature, Secure MCP Tunnel, for private servers; this course does not use it.
  • require_approval: always here. The guide says approval is the default.
  • allowed_tools: optional, a list of tool names to import, so the model sees only what it needs.
  • authorization: an access token, for servers that need a login. The docs server does not. The guide says this value is not stored, so you send it on every call.

The server in this lesson is https://developers.openai.com/mcp, the OpenAI Docs MCP server from OpenAI's own guide. It offers read-only documentation tools. The address and tool names come from that guide on 4 December 2026 and may change.

What comes back

The first reply has new item types in output:

  1. mcp_list_tools: the tools the API found on the server. As long as this item stays in the conversation, the API does not fetch the list again.
  2. mcp_approval_request: the tool the model wants to call and the exact arguments it wants to send.

Your script prints these, asks you, and sends an mcp_approval_response with approve true or false and the id of the request. It chains the new call to the old one with previous_response_id and sends the MCP tool again. Each approval covers one call. After a yes, an mcp_call item shows what was sent and what the server returned, or an error.

Risks, from OpenAI's own guide

  • Only use servers you trust. OpenAI does not verify remote servers. A bad server can take data from anything in the model's context.
  • Prompt injection. Text from a web page, an email or a tool result can contain hidden instructions. A server or a page could try to make the model send private data somewhere.
  • Pick official servers, run by the service itself, not by a third party that passes your data on.
  • Read and log what is sent. Approvals are the place to do it. Only skip them (require_approval set to never, or a list of tool names) for a server you trust, with data you do not mind sharing.
  • Their rules apply. Data sent to an MCP server falls under that server's own retention and location terms, not OpenAI's.

Cost

The guide says you pay only for the tokens used to import tool definitions and make tool calls, with no extra fee per MCP call. A long tool list costs tokens on every call, which is one more reason to use allowed_tools.

The steps

  1. Add the docs server as an mcp tool with approvals on.
  2. Run the script and read the approval request before answering.
  3. Approve and check the answer and its links.
  4. Refuse on a second run and see what changes.
  5. Limit the import to one tool with allowed_tools.
  6. Write down your own rule for when you would say no.

Pick your tool below and follow the steps.

Common mistakes

  • Setting require_approval to never on day one.
  • Using a server_url that only works on your own machine, such as localhost. OpenAI must be able to reach it over the internet.
  • Trusting an MCP server from a random list because it has a familiar name.
  • Pasting a real access token into code. Treat it like your API key: keep it in .env.

Today's actions

Ticks are not saved without an account

Do it in OpenAI API

OpenAI API

  1. Create mcp_docs.py in your project folder. It connects the public OpenAI Docs MCP server and asks for your approval before every tool call.
    from config import MODEL, client
    
    DOCS_SERVER = {
        "type": "mcp",
        "server_label": "openai_docs",
        "server_description": "Search and read the public OpenAI documentation.",
        "server_url": "https://developers.openai.com/mcp",
        "require_approval": "always",
    }
    SETTINGS = {"model": MODEL, "tools": [DOCS_SERVER], "max_output_tokens": 4000}
    
    response = client.responses.create(
        input="Search the OpenAI docs for how to set a monthly spend limit on a project. Give the links.",
        **SETTINGS,
    )
    for _ in range(3):  # never more than three rounds of approvals
        print("output items:", [item.type for item in response.output])
        requests = [item for item in response.output if item.type == "mcp_approval_request"]
        if not requests:
            break
        answers = []
        for request in requests:
            print(f"\nThe model wants to call {request.server_label}.{request.name}")
            print("with these arguments:", request.arguments)
            approve = input("Approve? y/n: ").strip().lower() == "y"
            answers.append(
                {"type": "mcp_approval_response", "approve": approve, "approval_request_id": request.id}
            )
        response = client.responses.create(previous_response_id=response.id, input=answers, **SETTINGS)
    
    for item in response.output:
        if item.type == "mcp_call":
            print("\nSent to the server:", item.arguments, "| error:", item.error)
    print("\nANSWER:", response.output_text or f"none (status {response.status})")
  2. Run python mcp_docs.py. The first line lists the output item types: look for mcp_list_tools and mcp_approval_request among them. Read the tool name and the arguments: that is exactly what will be sent to the server.
  3. Type y and press Enter. You should see an mcp_call line with what was sent, then an answer with links. Open one link and check that it is a real page about spend limits.
  4. Run the script again and type n. Read what comes back this time. Nothing was sent to the server for the call you refused.
  5. To import only one tool from the server, add a line "allowed_tools": ["search_openai_docs"], under the require_approval line, using the tool name that your approval request showed. Run again and approve.
  6. Write mcp-notes.txt with three things: the arguments that were sent, whether you approved, and one kind of call you would never approve for a server you do not run yourself.

Note: The server address must be reachable from the internet, because OpenAI calls it, not your computer. Approval is the default. Every approved call sends data to that server, so use only servers you trust. The docs server address and tool name come from the OpenAI guide and may change. MCP adds no fee per call, only tokens.

Paid planNeeds prepaid API credit. The OpenAI API is billed per use, separately from any ChatGPT plan.

Checked on 4 December 2026 · Source: OpenAI API docs: MCP servers (opens in a new tab)

Create a free account to save your progress. Sign in or sign up