Skip to main content

MCP SDK

PyPI version 3.2.0

Use the Python SDK when an agent runtime or backend calls CortexHub programmatically. It connects your runtime to two governed capabilities:

  • the AI gateway for OpenAI-compatible model requests;
  • the MCP gateway for governed tools, brain, and files.

The primary credential is an API key bound to one registered external agent. The key begins with cxh_key_ and is created after the agent has been given the capabilities and toolkit access it needs.

Quick start​

  1. Register an external agent in CortexHub.
  2. Grant its capabilities and toolkit access.
  3. Create an API key for that agent and select the AI gateway, MCP gateway, or both scopes.
  4. Copy the key once and store it in your secret manager.
  5. Set CORTEXHUB_API_KEY in the runtime that runs your agent.
pip install "cortexhub[all]"
export CORTEXHUB_API_KEY="cxh_key_..."

Use one SDK session for each conversation or autonomous run:

from cortexhub import Cortexhub

cx = Cortexhub()

session = cx.session(
agent="your-registered-agent-reference",
mcp_session_id="conversation-8472",
end_user_subject="user-193",
)

reply = session.llm.responses.create(
model="cortexhub/auto",
input="Summarize the latest project updates.",
)

print(reply.output_text)

mcp_session_id is your stable conversation or run identifier. end_user_subject is the stable opaque identifier for the person the agent is acting for. Reuse both for every turn in that conversation.

Other authentication​

A server-side process can use a programmatic member credential with client_id and client_secret for MCP access. Browser-based Claude, ChatGPT, and Cursor connections use interactive OAuth and do not use this SDK.

Documentation​

PageContents
QuickstartRegister an agent, mint a key, run inference, and connect MCP
InstallationRequirements, extras, and environment variables
AuthenticationAgent API keys, scopes, and programmatic OAuth
ConnectMCP connection objects and transports
Sessions & attributionConversation IDs, end-user subjects, objectives, and grouping
LLM routerOpenAI-compatible inference
Meta-toolsSearch, schema, invoke, and approval/task polling
OutcomesInvoke statuses and MCP errors
Framework examplesOpenAI Agents, LangChain, and other runtimes
Python API referenceClient, sessions, and connection objects
ErrorsException types

TypeScript​

TypeScript is planned. Until it ships, use the Python SDK or connect with the MCP protocol described in Connect.