Skip to main content

MCP gateway client for cortexhub agents — authenticate, hand the MCP URL to your framework of choice, done.

Project description

cortexhub

MCP gateway client for cortexhub agents. Authenticate, hand the MCP URL to your framework of choice, done.

Documentation · Examples

Install

pip install cortexhub

Quickstart

from cortexhub import Cortexhub

cortexhub = Cortexhub()                       # reads CORTEXHUB_API_KEY
session = cortexhub.create(user_id="user_123")

print(session.mcp.url)        # https://api.cortexhub.ai/v1/mcp-http
print(session.mcp.headers)    # {"Authorization": "Bearer ch_live_…", "X-Cortexhub-End-User-Subject": "user_123"}

Get an API key by registering an agent at app.cortexhub.ai.

Use it with your framework

The SDK only hands you an MCP URL + headers. Plug them into whichever framework you use.

Claude Agent SDK

from cortexhub import Cortexhub
from claude_agent_sdk import ClaudeAgentOptions

cortexhub = Cortexhub()
session = cortexhub.create(user_id="user_123")

options = ClaudeAgentOptions(
    mcp_servers={
        "cortexhub": {
            "type": "http",
            "url": session.mcp.url,
            "headers": session.mcp.headers,
        },
    },
)

OpenAI Agents SDK

from cortexhub import Cortexhub
from agents import Agent, HostedMCPTool

cortexhub = Cortexhub()
session = cortexhub.create(user_id="user_123")

agent = Agent(
    name="Assistant",
    tools=[
        HostedMCPTool(
            tool_config={
                "type": "mcp",
                "server_label": "cortexhub",
                "server_url": session.mcp.url,
                "headers": session.mcp.headers,
                "require_approval": "never",
            }
        )
    ],
)

Vercel AI SDK (TypeScript)

import { Cortexhub } from "@cortexhub/core";          // see @cortexhub/core (TS)
import { createMCPClient } from "@ai-sdk/mcp";

const cortexhub = new Cortexhub();
const session = await cortexhub.create("user_123");

const client = await createMCPClient({
  transport: {
    type: "http",
    url: session.mcp.url,
    headers: session.mcp.headers,
  },
});
const tools = await client.tools();

LangGraph (raw MCP)

Use the standard MCP client; pass the URL + headers from the session.

from cortexhub import Cortexhub
from mcp.client.streamable_http import streamablehttp_client
from mcp import ClientSession

cortexhub = Cortexhub()
session = cortexhub.create(user_id="user_123")

async with streamablehttp_client(session.mcp.url, headers=session.mcp.headers) as (read, write, _):
    async with ClientSession(read, write) as mcp:
        await mcp.initialize()
        tools = await mcp.list_tools()

Claude Desktop / Cursor / ChatGPT (no SDK)

Drop the URL + headers into the client's MCP server config — see docs.cortexhub.ai/mcp-gateway/clients.

Configuration

The SDK reads exactly one environment variable:

Variable Purpose
CORTEXHUB_API_KEY Per-agent API key (ch_live_…)

Or pass it explicitly:

cortexhub = Cortexhub(api_key="ch_live_…")

The MCP gateway URL is fixed — https://api.cortexhub.ai/v1/mcp-http. There is no self-hosted mode and no base-URL override.

How user_id works

user_id is opaque to cortexhub — pass whatever stable identifier your application uses for the human (DB id, email hash, Auth0 sub, …). Cortexhub uses it to:

  • Route per-end-user OAuth tokens (when the toolkit needs them)
  • Attribute every tool call to that user in the audit log
  • Evaluate per-user budget caps and rate limits

Calling create() with the same user_id twice is a no-op — the session is fully local and cheap to construct.

What this SDK doesn't do

The cortexhub MCP gateway is the source of truth for governance. The SDK has no:

  • Decorators (no @cx.tool — the gateway discovers tools from your registered toolkits)
  • Local Policy evaluation
  • Local PII / secret / prompt-injection scanning
  • Local span recording / OTLP export

All of that runs server-side at the gateway when the agent calls a tool through the URL above. The SDK is a thin wrapper around two strings (URL + headers).

Migrating from cortexhub 0.5.x

The v1 SDK is a complete rewrite. The decorator surface (@cx.tool, cx.session, cx.run, cx.llm_call, cx.enforce, …) is gone. If you used 0.5.x:

  1. Remove cortexhub.init() calls.
  2. Remove @cx.tool decorators — your tools come from cortexhub toolkits configured in the dashboard.
  3. Replace the function-call orchestration with an MCP-aware framework (Claude Agent SDK, OpenAI Agents, Vercel AI SDK, LangGraph, …).
  4. Use the snippets above to wire the MCP gateway into the framework.

License

MIT.

Project details


Release history Release notifications | RSS feed

This version

1.0.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cortexhub-1.0.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cortexhub-1.0.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file cortexhub-1.0.0.tar.gz.

File metadata

  • Download URL: cortexhub-1.0.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for cortexhub-1.0.0.tar.gz
Algorithm Hash digest
SHA256 82921ab70c538769999012222fb0f92ed2f63ace79115310018a437fcd8c8a8c
MD5 9bc12906ebb5269d9e72d32e730802be
BLAKE2b-256 e4c6ab657c2ba9615fc88bc8f83e5dee1d5c6e6ea2209b2ac55c3b1ef143a3be

See more details on using hashes here.

File details

Details for the file cortexhub-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: cortexhub-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for cortexhub-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3f100fccdbf94010c513f3fc257ec5150db54b4baba003c16b3bdc6369bf4255
MD5 0b279e529dcb02336605bfa4cde9cee6
BLAKE2b-256 20131404138fa46607bf98a8325bb7ace201a537f606cfd0540c59367d5c34e9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page