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 runs where

Concern Where it runs
Authentication, session construction This SDK (local, fully offline)
Tool discovery, tool execution cortexhub MCP gateway → toolkits you've attached
Policies, budget caps, approvals cortexhub MCP gateway
Per-end-user OAuth resolution cortexhub MCP gateway
Audit log, telemetry cortexhub MCP gateway
Safety guardrails (PII, secrets, prompt injection) cortexhub MCP gateway

The SDK itself is a thin wrapper around two strings (URL + headers). Everything else is server-side.

License

MIT.

Project details


Release history Release notifications | RSS feed

This version

1.0.1

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.1.tar.gz (6.7 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.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cortexhub-1.0.1.tar.gz
  • Upload date:
  • Size: 6.7 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.1.tar.gz
Algorithm Hash digest
SHA256 97480763854bef9a3585a1b137fad46899af6597bbdb1e65d2f2ec7d03ee462a
MD5 9fcaf3523afd0d4e35377de2cb8299b1
BLAKE2b-256 0d43a07af5029840fe663a2d7828d577187a88e36e29ed439a8f74272787504c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cortexhub-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.8 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ce7e9e39020b2f20d98e46afa008314e891abc0483c0c79aa17352833cd68bcf
MD5 4621a91ea7ebeaf20e1e1f2d86e27f20
BLAKE2b-256 87b5a3f324bc6aa497a8936d6ec64ad8657251eed5b771e1bc1a3a3f9a9079d8

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