OpenAI (ChatGPT)

MCP Client Configuration Guide

Configure OpenAI to access b.well's healthcare data and services through b.well Health SDK for AI. This guide includes configuration parameters and code examples for quickly setting up the MCP client in OpenAI's responses API.

Prerequisites

Install the OpenAI Python library:

pip install openai

Required Credentials:

CredentialSourceNotes
OpenAI API KeyOpenAI platform accountRequired for all requests
b.well User TokenOAuth 2.0 Token ExchangeBearer token for user authentication
OR: User JWE + Client Keyb.well (Client Key) + Your IdP (User JWE)Alternative authentication method

MCP Configuration Parameters:

OpenAI connects to b.well's MCP server through the tools parameter in the responses API. Configure the MCP tool with these parameters:

ParameterValueDescription
type"mcp"Indicates Model Context Protocol
server_label"bwell-mcp-fhir-agent"Identifier for b.well MCP server
server_urlhttps://mcpfhiragent.{ENVIRONMENT}.icanbwell.comb.well MCP server endpoint (client-sandbox)
require_approval"never"Automatic tool execution (no user confirmation)
headersAuthentication headersBearer token OR JWE + Client Key



Code Example 1: Bearer Token Authentication

Use this approach when you have a user access token from b.well's OAuth 2.0 token exchange.

from openai import OpenAI

openai_key = "{insert your openai key here}"

user_token = "{insert your user token here}"

client = OpenAI(
    api_key=openai_key
)

mcp_fhir_agent_url = "https://mcpfhiragent.client-sandbox.icanbwell.com"

response = client.responses.create(
  model="gpt-4o",
  tools=[{
    "type": "mcp",
    "server_label": "bwell-mcp-fhir-agent",
    "server_url": mcp_fhir_agent_url,
    "require_approval": "never",
    "headers": {
          "Authorization": f"Bearer {user_token}",
          "Accept": "application/json, text/event-stream",
     },
  }],
  input=f"Get Active Medications"
)

print(response.output_text)

Code Example 2: Using JWE with Client Key

Use this approach when you only have a user JWE and a client key.

from openai import OpenAI

openai_key = "{insert your openai key here}"

user_jwe = "{insert your user jwe here}"

client_key = "{insert client key assigned by b.well to your company}"

client = OpenAI(
    api_key=openai_key
)

mcp_fhir_agent_url = "https://mcpfhiragent.client-sandbox.icanbwell.com"

response = client.responses.create(
  model="gpt-4o",
  tools=[{
    "type": "mcp",
    "server_label": "bwell-mcp-fhir-agent",
    "server_url": mcp_fhir_agent_url,
    "require_approval": "never",
    "headers": {
          "Authorization": f"{user_jwe}",
          "ClientKey": f"{client_key}",
          "Accept": "application/json, text/event-stream",
     },
  }],
  input=f"Get Active Medications"
)

print(response.output_text)

Using curl

For testing or non-Python implementations, you can use OpenAI's REST API directly:

curl --request POST \
  --url https://api.openai.com/v1/responses \
  --header 'authorization: Bearer {openai key}' \
  --header 'content-type: application/json' \
  --data '{
  "model": "gpt-4o",
  "tools": [
    {
      "type": "mcp",
      "server_label": "bwell-mcp-fhir-agent",
      "server_url": "https://mcpfhiragent.client-sandbox.icanbwell.com",
      "require_approval": "never",
      "headers": {
        "Authorization": "{user jwe}",
        "ClientKey": "{client key}",
        "Accept": "application/json, text/event-stream"
      }
    }
  ],
  "input": "Get Active Medications for person_id='\''{person id}'\''"
}'