Skip to main content

CelestoMCPHub

CelestoMCPHub is a context manager that provides access to Celesto AI’s MCP Hub, which aggregates multiple MCP servers and their tools into a single endpoint.

Class Definition

Constructor

int
default:"10"
Timeout in seconds for MCP requests
int
default:"3"
Accepted for backwards compatibility. The MCP client does not retry, so this has no effect.
bool
default:"true"
Accepted for backwards compatibility. Tools are listed once per connection, so this has no effect.
str
Celesto AI API key. If not provided, reads from the CELESTO_API_KEY environment variable. Raises ValueError when neither is set.

Usage

CelestoMCPHub is designed to be used as an async context manager with the async with statement:
The context manager handles connection and cleanup automatically:
  • __aenter__: Connects to the MCP Hub and returns an MCPServer instance
  • __aexit__: Cleans up the connection when exiting the context
Connect and exit on the same event loop — put the whole async with block inside one asyncio.run().

Example Usage

Basic Usage with Agent

Custom Configuration

Multiple Agents with Shared Hub

Configuration

API Key

The API key can be provided in three ways (in order of precedence):
  1. Constructor parameter:
  2. Environment variable:
  3. Configuration file: The API key is read from celesto_config.api_key
If no API key is found, a ValueError is raised.

Connection Parameters

The hub connects to the Celesto AI MCP endpoint with the following settings:
  • URL: {celesto_config.base_url}/mcp
  • Authentication: Bearer token using the provided API key
  • Headers: Authorization: Bearer {api_key}

Error Handling

Under the Hood

When you use CelestoMCPHub, it:
  1. Creates an MCPServer pointed at {CELESTO_BASE_URL}/mcp with a bearer token header
  2. Connects to the hub during __aenter__
  3. Returns the MCP server instance for use as a tool
  4. Automatically cleans up the connection during __aexit__
When you pass that server to an agent, the agent opens its own connection for the duration of each run, so concurrent runs never share one session. The hub provides access to all tools registered across multiple MCP servers hosted by Celesto AI, allowing agents to use a wide range of capabilities through a single integration.

See Also

Last modified on August 28, 2026