Connect User Data Example

Learn how to connect user data to your AI agent or application

Select MCP Servers

BlueNexus supports many MCP Servers. You need to select the MCP server(s) that are relevant for your application and that a user has connected.

Checking connected MCP Servers

MCP servers are only available to your application if the user account has connected the underlying service (Google, Fitbit, etc.) and your application has permission to access that data and MCP servers.

You can check the available MCP servers for a given user by making a request to GET https://api.bluenexus.ai/api/v1/mcps:

curl -X GET "https://api.bluenexus.ai/api/v1/mcps" \
  -H "Authorization: Bearer USER_ACCESS_TOKEN"

Selecting a MCP Server

Extract the url from the response to identify the MCP endpoint(s) for connecting to your LLM.

Example response:

{
    "data": [
        {
            "slug": "notion",
            "label": "Notion",
            "url": "https://api.bluenexus.ai/api/v1/mcps/notion",
            "isActive": true // Indicates if this user is connected to the service (Notion in this case)
        }
    ]
}

In this example you can use the url https://api.bluenexus.ai/api/v1/mcps/notion.

The isActive field indicates whether the user is connected to the underlying service (Notion in this case) and given your application the permissions to use it. For MCP servers where isActive is false, your application can respectfully encourage the user to connect and allow the service first. Trying to use an MCP server that is not active will result in a 403 Forbidden error.

Setup your LLM

Create an AI agent using the library of your choice. You can utilize a third party LLM (ie: Anthropic or OpenAI) or you can use the built-in LLMs provided by BlueNexus which include confidential LLM's for enhanced privacy.

Example 1: Using Anthropic LLM

Here's an example using LangChain with Anthropic:

Example 2: Using BlueNexus LLM

Here's an example using LangChain with BlueNexus built-in LLM for enhanced privacy:

Connect MCP Servers

Connect your LLM to one or more MCP servers.

Here's an example using LangChain:

Automatically Connect All Active MCP Servers

Instead of manually connecting to each MCP server, you can automatically discover and connect to all active MCP servers that you have activated. This requires two steps:

  1. Retrieve the URLs of all active MCP servers (where isActive = true)

  2. Iteratively connect to each server to fetch their tools

Here's an example:

This approach allows your application to automatically adapt to whatever MCP servers you have connected, without hardcoding specific server names.

Make LLM Request

Now, your application can submit a LLM prompt that will utilize the connected MCP servers.

Here's an example using LangChain:

Note: If you used the automatic connection approach from the previous section, replace mcpTools with allMCPTools and clean up connections like this:

Last updated