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

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
print(session.mcp.headers)    # {"X-API-Key": "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)

Add just the gateway URL — these clients bootstrap OAuth automatically. See docs.cortexhub.ai/frameworks/desktop-cursor.

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. There is no self-hosted mode and no base-URL override.

Attributing tool calls to a user

Every MCP request the gateway sees is attributed to one end-user — the person on whose behalf the agent is acting. Two ways to do this:

From this SDK

cortexhub.create(user_id="…") puts the value into the X-Cortexhub-End-User-Subject header automatically. That's it — every tool call from the resulting session is now attributed to that user in the audit log and uses their per-end-user OAuth tokens for any toolkit that needs them.

session = cortexhub.create(user_id="user_123")
# session.mcp.headers ==
#   {"X-API-Key": "ch_live_…", "X-Cortexhub-End-User-Subject": "user_123"}

From any other MCP client (no SDK)

Add the header directly on every MCP request:

X-Cortexhub-End-User-Subject: user_123

E.g. with curl:

curl -N "https://api.cortexhub.ai/v1/mcp" \
  -H "x-api-key: $CORTEXHUB_API_KEY" \
  -H "X-Cortexhub-End-User-Subject: user_123" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'

When you omit the header, the gateway falls back to mcp_session:<session_id> — every distinct MCP connection becomes its own anonymous "user". Fine for personal Claude Desktop / Cursor use; not what you want for a multi-tenant app.

What user_id is for

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
  • Scope per-end-user 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
Per-end-user OAuth resolution cortexhub MCP gateway
Per-tool policies + HITL approvals cortexhub MCP gateway
Audit log of every tool call 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.3

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.3.tar.gz (7.3 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.3-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cortexhub-1.0.3.tar.gz
  • Upload date:
  • Size: 7.3 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.3.tar.gz
Algorithm Hash digest
SHA256 eab47a04005da353072b7b7de56df7a86d65a045b548e2e94057c66e418b6561
MD5 445128cb95c5c73c813dbc7bf28ff2af
BLAKE2b-256 2baa251be45c4e33f4cbe9d6b4c5e02fd8059b5f8a8a1097e25e805acf18fe54

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cortexhub-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.4 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2d8f277bd814593148037669da2aa7eb648015d84c27f622165ea7cf0a1a191f
MD5 247253adc10f899b17507451c0b34f71
BLAKE2b-256 0d4ccd128c07ca895ddc4657cb5a22710d49078b5056195cf1682935b1cec8bd

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