> ## Documentation Index
> Fetch the complete documentation index at: https://docs.blaxel.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Query MCP servers

> Connect to MCP servers deployed on Blaxel via streamable HTTP endpoints. Covers authentication, public access, and integration with agents and apps.

Blaxel uses **streamable HTTP** as its MCP transport mechanism. MCP servers deployed on Blaxel are only hosted server-side and cannot be installed locally.

## MCP server endpoint

When you deploy an MCP server on Blaxel, an **HTTP endpoint** is generated on Global Agentics Network to connect to the server.

The server endpoint looks like this:

```http Connect to an MCP server theme={null}

https://run.blaxel.ai/{YOUR-WORKSPACE}/functions/{YOUR-SERVER-NAME}/mcp

```

### Endpoint authentication

By default, MCP servers deployed on Blaxel aren’t public. It is necessary to authenticate all connections, via a [bearer token](../Security/Access-tokens).

The evaluation of authentication/authorization for messages is managed by the Global Agentics Network based on the [access given in your workspace](../Security/Workspace-access-control).

You can make an MCP server **public**, meaning it will bypass Blaxel authentication and you will have to implement your own authentication inside the server. This can be done through the `blaxel.toml` configuration file.

<Accordion title="blaxel.toml reference">
  The MCP server deployment can be configured via the ***blaxel.toml*** file in your MCP server directory. This file is not mandatory; if the file is not found or a required option is not set, you will be prompted for the information during deployment.

  ```toml theme={null}
  name = "my-mcp-server"
  workspace = "my-workspace"
  type = "function"

  [env]
  DEFAULT_CITY = "San Francisco"

  [[triggers]]
    id = "trigger-my-mcp"
    type = "http"
  [triggers.configuration]
    path = "functions/my-mcp" # This will create this endpoint on the following base URL: https://run.blaxel.ai/{YOUR-WORKSPACE}/
    authenticationType = "public"
  ```

  * `name`, `workspace`, and `type` fields are optional and serve as default values. Any bl command run in the folder will use these defaults rather than prompting you for input.
  * `[env]` section defines environment variables that the MCP server can access via the SDK. Note that these are NOT [secrets](../Agents/Variables-and-secrets).
  * `[[triggers]]`  and `[triggers.configuration]` sections defines ways to send requests to the MCP servers. You can also make them either private (default) or public (`authenticationType = "public"`).
</Accordion>

### Runtime limit

MCP server runtime has a hard limit of 15 minutes.

## Call the MCP server

You can connect to your MCP server and send requests in several ways (code samples below):

* **use the Blaxel SDK to retrieve tools**: best when developing an agent, particularly when running on Blaxel
* **integrate with AI tools**: integrate with AI agents and other MCP-aware tools
* **connect from your code directly**: suitable for custom implementations requiring server connection to list and call tools
* **connect from the Blaxel Console's Playground**: best for testing and validating server functionality

### Use Blaxel SDK to retrieve tools

The following code example demonstrates how to use the Blaxel SDK to retrieve and pass an MCP server’s tools when building an agent.

<CodeGroup>
  ```typescript In TypeScript theme={null}

  // Import tool adapter (in whichever framework format):
  import { blTools } from "@blaxel/langchain";
  // or
  import { blTools } from "@blaxel/llamaindex";
  // or
  import { blTools } from "@blaxel/mastra";
  // or
  import { blTools } from "@blaxel/vercel";

  // or

  // …

  const tools = blTools(['blaxel-search'])
  ```

  ```python In Python theme={null}

  # Import tool adapter (in whichever framework format):

  from blaxel.pydantic import bl_tools
  # or
  from blaxel.langgraph import bl_tools
  # or
  from blaxel.crewai import bl_tools
  # or
  from blaxel.googleadk import bl_tools
  # or
  from blaxel.openai import bl_tools

  #or

  # …

  tools = await bl_tools(['blaxel-search'])
  ```
</CodeGroup>

### Integrate with AI tools

Add the MCP server to MCP-aware applications and tools. This section has instructions for some popular applications.

<Note>
  You must provide your [Blaxel API key](../Security) in the `Authorization` header. If you have access to multiple workspaces, include the workspace header as well.

  * Required: `Authorization: Bearer <APIKEY>`
  * Optional (multi-workspace): `X-Blaxel-Workspace: <WORKSPACE_NAME_OR_ID>`
</Note>

<Tabs>
  <Tab title="Cursor">
    Add the server to `~/.cursor/mcp.json`:

    ```json theme={null}
    {
      "mcpServers": {
        "blaxel": {
          "url": "https://run.blaxel.ai/<WORKSPACE_NAME_OR_ID>/functions/blaxel-search/mcp",
          "headers": {
            "Authorization": "Bearer <APIKEY>",
            "X-Blaxel-Workspace": "<OPTIONAL_WORKSPACE>"
          }
        }
      }
    }
    ```
  </Tab>

  <Tab title="Claude Code">
    [Add the remote HTTP server to your Claude Code](https://docs.anthropic.com/en/docs/claude-code/mcp#option-3%3A-add-a-remote-http-server) by running the following command:

    ```bash theme={null}

    claude mcp add --transport http blaxel https://run.blaxel.ai/<WORKSPACE_NAME_OR_ID>/functions/blaxel-search/mcp \\
      --header "Authorization: Bearer <APIKEY>" \\
      --header "X-Blaxel-Workspace: <OPTIONAL_WORKSPACE>"
    ```
  </Tab>

  <Tab title="Windsurf">
    Add to `~/.codeium/windsurf/mcp_config.json`:

    ```json theme={null}

    {
      "mcpServers": {
        "blaxel": {
          "url": "https://run.blaxel.ai/<WORKSPACE_NAME_OR_ID>/functions/blaxel-search/mcp",
          "headers": {
            "Authorization": "Bearer <APIKEY>",
            "X-Blaxel-Workspace": "<OPTIONAL_WORKSPACE>"
          }
        }
      }
    }
    ```
  </Tab>

  <Tab title="Goose">
    Add to `~/.config/goose/config.yaml`:

    ```yaml theme={null}
    extensions:
      blaxel:
        enabled: true
        type: streamable_http
        name: blaxel
        description: Blaxel MCP
        uri: https://run.blaxel.ai/<WORKSPACE_NAME_OR_ID>/functions/blaxel-search/mcp
        envs: {}
        env_keys: []
        headers:
          Authorization: Bearer <APIKEY>
          X-Blaxel-Workspace: <OPTIONAL_WORKSPACE>
        bundled: null
        available_tools: []
    ```
  </Tab>
</Tabs>

### Directly connect from your code

Below are snippets of code to connect to an MCP server that is deployed on Blaxel. You will need the following information:

* `BL_API_KEY`: an [API key](../Security/Access-tokens) to connect to your Blaxel workspace
* `BL_WORKSPACE`: the slug ID for your workspace
* `MCP_SERVER_NAME`: the slug name for your MCP server

<CodeGroup>
  ```typescript In TypeScript theme={null}

  import { settings } from "@blaxel/core";
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
  import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
  import dotenv from 'dotenv';

  // Load environment variables from .env file
  dotenv.config();

  // Initialize client
  const client = new Client({
    name: 'streamable-http-client',
    version: '2.0.0'
  });

  // Initialize transport
  const baseUrl = `${settings.runUrl}/${settings.workspace}/functions/blaxel-search/mcp`
  const transport = new StreamableHTTPClientTransport(new URL(baseUrl), { requestInit: { headers: settings.headers } });

  // Connect client to transport
  await client.connect(transport);

  // List tools
  const response = await client.listTools();
  console.log(`Tools retrieved, number of tools: ${response.tools.length}`);
  ```

  ```python In Python theme={null}

  import asyncio

  from mcp.client.session import ClientSession
  from mcp.client.streamable_http import streamablehttp_client

  from blaxel import settings

  async def run():
      """Run the completion client example."""
      url = f"{settings.run_url}/{settings.workspace}/functions/blaxel-search/mcp"

      async with streamablehttp_client(url, settings.headers) as (read, write, _):
          async with ClientSession(read, write) as session:
              # Initialize the connection
              await session.initialize()
              tools = await session.list_tools()
              print(f"Tools retrieved, number of tools: {len(tools.tools)}")

  asyncio.run(run())
  ```
</CodeGroup>

Requirements are as follows:

<CodeGroup>
  ```json package.json (In TypeScript) theme={null}

  "dependencies": {"@blaxel/core": …}

  ```

  ```txt requirements.txt (In Python) theme={null}

  python-dotenv
  blaxel

  ```
</CodeGroup>

### Connect to pre-built servers

Blaxel’s pre-built MCP servers offer two methods:

* `tools/list` : method that **lists the available tools** and their schemas, allowing consumers (you or agents) to discover the function’s capabilities.
* `tools/call` : method that lets consumers **execute individual tools**. It requires params with two keys:
  * `name`: the name of the tool to run, obtained from the listing endpoint above
  * `arguments`: an object with the key and values of input parameters for the execution, obtained from the listing endpoint above

Example of `tools/list` outbound message on a Brave Search toolkit (make sure to fill in the authentication token).

```json theme={null}
{
	"method":"tools/list",
	"jsonrpc":"2.0",
	"id":1
}
```

This one returns two tools in the function: ***brave\_web\_search*** and ***brave\_local\_search***.

```json theme={null}
{
    "result": {
        "tools": [
            {
                "name": "blaxel_web_search",
                "description": "Performs a web search using the Brave Search API, ideal for general queries, news, articles, and online content. Use this for broad information gathering, recent events, or when you need diverse web sources. Supports pagination, content filtering, and freshness controls. Maximum 20 results per request, with offset for pagination. ",
                "inputSchema": {
                    "type": "object",
                    "properties": {
                        "query": {
                            "type": "string"
                        },
                        "count": {
                            "type": "number"
                        },
                        "offset": {
                            "type": "number"
                        }
                    },
                    "additionalProperties": false,
                    "$schema": "http://json-schema.org/draft-07/schema#"
                }
            },
            {
                "name": "blaxel_local_search",
                "description": "Searches for local businesses and places using Brave's Local Search API. Best for queries related to physical locations, businesses, restaurants, services, etc. Returns detailed information including:\n- Business names and addresses\n- Ratings and review counts\n- Phone numbers and opening hours\nUse this when the query implies 'near me' or mentions specific locations. Automatically falls back to web search if no local results are found.",
                "inputSchema": {
                    "type": "object",
                    "properties": {
                        "query": {
                            "type": "string"
                        },
                        "count": {
                            "type": "number"
                        }
                    },
                    "additionalProperties": false,
                    "$schema": "http://json-schema.org/draft-07/schema#"
                }
            }
        ]
    },
    "jsonrpc": "2.0",
    "id": "1"
}
```

Example of `tools/call` outbound message on the ***brave\_web\_search*** tool.

```json theme={null}
{
	"jsonrpc":"2.0",
	"id":2,
	"method":"tools/call",
	"params":{
		"name":"blaxel_web_search",
		"arguments":{
			"query":"What is the current weather in NYC?",
			"count":1,
			"offset":1
			}
		}
}
```

### Via Blaxel console

Requests to an MCP server can be made from the Blaxel console from the server deployment’s **Playground** page.

<img src="https://mintcdn.com/blaxel/OV8J20a-e6sNRxmO/Functions/Invoke-functions/image.webp?fit=max&auto=format&n=OV8J20a-e6sNRxmO&q=85&s=165bf307da0e4339091f9e45455e5d1e" alt="image.webp" width="2412" height="1540" data-path="Functions/Invoke-functions/image.webp" />
