Skip to main content
Version: 2.31.0

Using EdgeSession in MCP Tools

This guide explains how to use EdgeSession within an MCP (Model Context Protocol) Tool Server. It is possible to use EdgeSession in MCP Tools, though some configuration is required.

Overview

MCP Tool Servers can interact with Edge services using the EdgeSession API. This allows your MCP tools to access Edge files, applications, secrets, and other Edge features programmatically.

Configuration Requirements

To use EdgeSession in your MCP Tool Server, you need to configure the following:

1. Dependencies

Your MCP Tool Server must include enthought_edge in its dependencies. Add this to your project's dependency configuration file.

2. Service URL Configuration

You must specify the edge_api_service_url for your MCP Tool Server. This URL points to the Edge API endpoint.

The service URL format depends on your deployment:

For internal/cluster communication:

http://edge-api.<namespace>.svc.cluster.local:10000

This can be configured through environment variables or passed programmatically when creating an EdgeSession instance.

3. Terraform Configuration

For the internal cluster communication to work, you need to assign your application to the appropriate service account:

  • In the application's .tf file, in the spec.spec section, include service_account_name = var.mcp_tool_sa_name
  • In the application's module definition, be sure to include mcp_tool_sa_name = module.edge.mcp_tool_sa_name
  • In the variables file, include:
variable "mcp_tool_sa_name" {
type = string
}
  • Set a secret, config, or environment variable for the EDGE_API_ENDPOINT to the internal service URL, e.g.:
edge_api_endpoint = "http://${kubernetes_service_v1.edge_api.metadata[0].name}.${data.kubernetes_namespace_v1.edge.metadata[0].name}.svc.cluster.local:10000"

4. Using EdgeSession in Your MCP Tool

Once your MCP Tool Server is properly configured with the dependencies and service URL, you can use EdgeSession as documented in the EdgeSession reference.

Example: Basic Usage

import os

from edge.edge_session import EdgeSession
from fastmcp.server.dependencies import get_http_headers

@mcp.tool()
async def use_edge_session() -> str:
"""Do something with EdgeSession."""
headers = get_http_headers()
access_token = headers.get("x-access-token") or headers.get("X-access-token")
refresh_token = headers.get("x-refresh-token") or headers.get("X-refresh-token")
org_id = headers.get("x-org-id") or headers.get("X-org-id")
edge_api_service_url = os.environ["EDGE_API_ENDPOINT"]

session = EdgeSession(
service_url=edge_api_service_url,
organization=org_id,
access_token=access_token,
refresh_token=refresh_token,
)
# Do something with session and return a result