Google (Gemini)

MCP Client Configuration Guide

Configure Google Gemini 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 Google's Generative AI API.

Prerequisites

Install the Google GenAI Python libraries:

pip install google-genai fastmcp

Required Credentials:

CredentialSourceNotes
Google Gemini API KeyGoogle AI StudioRequired for all requests
b.well User TokenOAuth 2.0 Token ExchangeBearer token for user authenticatio

MCP Configuration Parameters:

Google Gemini connects to b.well's MCP server through the FastMCP client using Bearer token authentication. Configure the MCP client with these parameters:

ParameterValueDescription
mcp_fhir_agent_urlhttps://mcpfhiragent.{ENVIRONMENT}.icanbwell.comb.well MCP server endpoint (client-sandbox)
authBearerAuth(user_token)Bearer token authentication wrapper
modelgemini-2.0-flashGoogle Gemini model version
tools[mcp_client.session]MCP client session for tool acces



Code Example: Bearer Token Authentication

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

import asyncio

from fastmcp import Client
from fastmcp.client.auth import BearerAuth
from google import genai

person_id = "{insert person id here}"
user_token = "{insert user token here}"
mcp_fhir_agent_url = "https://mcpfhiragent.client-sandbox.icanbwell.com"

mcp_client = Client(
        mcp_fhir_agent_url,
       auth=BearerAuth(user_token),
)

gemini_client = genai.Client(api_key="{insert your Gemini Key here}")

async def main():
    async with mcp_client:
        response = await gemini_client.aio.models.generate_content(
            model="gemini-2.0-flash",
            contents=f"Get Active Medications for person_id={person_id}",
            config=genai.types.GenerateContentConfig(
                temperature=0,
                tools=[mcp_client.session]
            ),
        )
        print(response.text)


if __name__ == "__main__":
    asyncio.run(main())