What is the Difference Between 'mcp' and 'function' Types in the MCP OpenAI Documentation and Python SDK, and Why am I Receiving a BadRequest Error When Using 'mcp'?

This topic was automatically generated from Slack. You can find the original thread here.

Hi team, while reading the MCP OpenAI documentation (link), I noticed that it uses tools with type ‘mcp’. However, when I checked the Python SDK, I only saw tools defined using the ‘function’ type. Could someone please clarify or explain the difference? Because when I use type 'mcp" I got the error “openai.BadRequestError: Error code: 400 - {‘error’: {‘message’: “Missing required parameter: ‘tools[0].function’.”, ‘type’: ‘invalid_request_error’, ‘param’: ‘tools[0].function’, ‘code’: ‘missing_required_parameter’}}” and this is my current set up in my code:

 completion = client.chat.completions.create(
            model=model_info.model,
            messages=[
                {"role": "user", "content": user_prompt},
            ],
            temperature=model_info.temperature,
            tools=[
                {
                    "type": "mcp",
                    "server_label": "GoogleSheets",
                    "server_url": MCP_SERVER_URL,
                    "headers": {
                        "Authorization": f"Bearer {settings.pipedream_access_token}",
                        "x-pd-project-id": settings.pipedream_project_id,
                        "x-pd-environment": settings.pipedream_environment,
                        "x-pd-external-user-id": "cv-bot",
                        "x-pd-app-slug": app_slug,
                    },
                    "require_approval": "never",
                }
            ],
        )

Thank you so much

Hi , you’ll need to use OpenAI Response API for MCP

The easiest way to have the ready-to-use code is to access OpenAI Playground > Code tab (image below)

Got it, thank you so much, Leo