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

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.2

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.2.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.2-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cortexhub-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 216212c7a37d3c0e0b96cf3817cf86246ca45abd595ddda0f6d8c5aaaa7d7d09
MD5 e08f2a1f95e2ad79661f9e5fd19ff741
BLAKE2b-256 4a313bd54611febe89be6d1030e9d17c68fe70a791622a5eed16b52ef6f39d50

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cortexhub-1.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b80ee71daf53edf3745a5e3d52470a8225afc4657fc98f7c980c3ca8c28f07ea
MD5 d153e76b0ef62103eb698bc1595625be
BLAKE2b-256 4086a64b48e116ee77478bf2ba9bec7d3ab3cd05563aa3222955dae16bb06259

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