cortexhub 3.1.0__tar.gz → 3.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cortexhub-3.1.0 → cortexhub-3.1.1}/PKG-INFO +3 -3
- {cortexhub-3.1.0 → cortexhub-3.1.1}/README.md +2 -2
- {cortexhub-3.1.0 → cortexhub-3.1.1}/pyproject.toml +1 -1
- {cortexhub-3.1.0 → cortexhub-3.1.1}/src/cortexhub/__init__.py +1 -1
- cortexhub-3.1.1/src/cortexhub/session.py +89 -0
- cortexhub-3.1.0/src/cortexhub/session.py +0 -13
- {cortexhub-3.1.0 → cortexhub-3.1.1}/.gitignore +0 -0
- {cortexhub-3.1.0 → cortexhub-3.1.1}/LICENSE +0 -0
- {cortexhub-3.1.0 → cortexhub-3.1.1}/src/cortexhub/_config.py +0 -0
- {cortexhub-3.1.0 → cortexhub-3.1.1}/src/cortexhub/ai.py +0 -0
- {cortexhub-3.1.0 → cortexhub-3.1.1}/src/cortexhub/client.py +0 -0
- {cortexhub-3.1.0 → cortexhub-3.1.1}/src/cortexhub/errors.py +0 -0
- {cortexhub-3.1.0 → cortexhub-3.1.1}/src/cortexhub/mcp_key.py +0 -0
- {cortexhub-3.1.0 → cortexhub-3.1.1}/src/cortexhub/mcp_oauth.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: cortexhub
|
|
3
|
-
Version: 3.1.
|
|
3
|
+
Version: 3.1.1
|
|
4
4
|
Summary: CortexHub platform SDK: point your agent at the governed LLM router + MCP gateway.
|
|
5
5
|
Project-URL: Homepage, https://cortexhub.ai
|
|
6
6
|
Project-URL: Documentation, https://docs.cortexhub.ai
|
|
@@ -182,7 +182,6 @@ that to the user and poll until they decide in CortexHub. Needs both extras:
|
|
|
182
182
|
import asyncio, json
|
|
183
183
|
from cortexhub import Cortexhub
|
|
184
184
|
from mcp import ClientSession
|
|
185
|
-
from mcp.client.streamable_http import streamablehttp_client
|
|
186
185
|
|
|
187
186
|
cx = Cortexhub(api_key="cxh_key_...")
|
|
188
187
|
|
|
@@ -190,7 +189,8 @@ async def run_turn(user_text: str) -> str:
|
|
|
190
189
|
# One session for this end user's conversation -> LLM + tools share it.
|
|
191
190
|
s = cx.session(agent="support-bot", mcp_session_id="conv-42", end_user_subject="user_42")
|
|
192
191
|
|
|
193
|
-
|
|
192
|
+
# s.mcp.open() opens the transport across mcp client versions.
|
|
193
|
+
async with s.mcp.open() as (read, write):
|
|
194
194
|
async with ClientSession(read, write) as mcp:
|
|
195
195
|
await mcp.initialize()
|
|
196
196
|
|
|
@@ -153,7 +153,6 @@ that to the user and poll until they decide in CortexHub. Needs both extras:
|
|
|
153
153
|
import asyncio, json
|
|
154
154
|
from cortexhub import Cortexhub
|
|
155
155
|
from mcp import ClientSession
|
|
156
|
-
from mcp.client.streamable_http import streamablehttp_client
|
|
157
156
|
|
|
158
157
|
cx = Cortexhub(api_key="cxh_key_...")
|
|
159
158
|
|
|
@@ -161,7 +160,8 @@ async def run_turn(user_text: str) -> str:
|
|
|
161
160
|
# One session for this end user's conversation -> LLM + tools share it.
|
|
162
161
|
s = cx.session(agent="support-bot", mcp_session_id="conv-42", end_user_subject="user_42")
|
|
163
162
|
|
|
164
|
-
|
|
163
|
+
# s.mcp.open() opens the transport across mcp client versions.
|
|
164
|
+
async with s.mcp.open() as (read, write):
|
|
165
165
|
async with ClientSession(read, write) as mcp:
|
|
166
166
|
await mcp.initialize()
|
|
167
167
|
|
|
@@ -31,7 +31,7 @@ from .mcp_key import CortexhubKeyClient, McpKeySession
|
|
|
31
31
|
from .mcp_oauth import CortexhubMcpOAuthClient, McpOAuthSession, McpOAuthToken
|
|
32
32
|
from .session import SessionMcp
|
|
33
33
|
|
|
34
|
-
__version__ = "3.1.
|
|
34
|
+
__version__ = "3.1.1"
|
|
35
35
|
__all__ = [
|
|
36
36
|
"APIError",
|
|
37
37
|
"AiGateway",
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""Session types for the MCP gateway connection."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import inspect
|
|
6
|
+
from collections.abc import AsyncIterator
|
|
7
|
+
from contextlib import asynccontextmanager
|
|
8
|
+
from dataclasses import dataclass, field
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _streamable_http_opener() -> Any:
|
|
13
|
+
"""A ``(url, headers) -> transport`` opener over the installed ``mcp`` client.
|
|
14
|
+
|
|
15
|
+
The official ``mcp`` client's streamable-HTTP entry point is not stable across
|
|
16
|
+
releases: 1.x exposes ``streamablehttp_client(url, headers=...)``; 2.x renamed
|
|
17
|
+
it to ``streamable_http_client(url, *, http_client=...)`` (headers must be
|
|
18
|
+
baked into an httpx client) and dropped the old name. This adapts to whichever
|
|
19
|
+
is installed so callers never depend on a specific mcp version.
|
|
20
|
+
"""
|
|
21
|
+
from mcp.client import streamable_http as module
|
|
22
|
+
|
|
23
|
+
legacy = getattr(module, "streamablehttp_client", None)
|
|
24
|
+
if legacy is not None and "headers" in inspect.signature(legacy).parameters:
|
|
25
|
+
|
|
26
|
+
def _open(url: str, headers: dict[str, str]) -> Any:
|
|
27
|
+
return legacy(url, headers=headers)
|
|
28
|
+
|
|
29
|
+
return _open
|
|
30
|
+
|
|
31
|
+
modern = getattr(module, "streamable_http_client", None)
|
|
32
|
+
if modern is not None:
|
|
33
|
+
params = inspect.signature(modern).parameters
|
|
34
|
+
if "headers" in params:
|
|
35
|
+
|
|
36
|
+
def _open(url: str, headers: dict[str, str]) -> Any:
|
|
37
|
+
return modern(url, headers=headers)
|
|
38
|
+
|
|
39
|
+
return _open
|
|
40
|
+
if "http_client" in params:
|
|
41
|
+
from mcp.client.streamable_http import ( # type: ignore[attr-defined]
|
|
42
|
+
create_mcp_http_client,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
def _open(url: str, headers: dict[str, str]) -> Any:
|
|
46
|
+
return modern(url, http_client=create_mcp_http_client(headers=headers))
|
|
47
|
+
|
|
48
|
+
return _open
|
|
49
|
+
|
|
50
|
+
raise ImportError( # pragma: no cover - defensive across future renames
|
|
51
|
+
"The installed 'mcp' package has no usable streamable-HTTP client entry point. "
|
|
52
|
+
"Install a supported version with: pip install 'cortexhub[mcp]'"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@dataclass(frozen=True)
|
|
57
|
+
class SessionMcp:
|
|
58
|
+
"""MCP gateway connection: ``.url`` + ``.headers`` for your MCP transport.
|
|
59
|
+
|
|
60
|
+
Wire these into any MCP client, or use :meth:`open` to open the transport
|
|
61
|
+
directly without touching the mcp client's version-specific entry points.
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
url: str
|
|
65
|
+
headers: dict[str, str] = field(default_factory=dict)
|
|
66
|
+
|
|
67
|
+
@asynccontextmanager
|
|
68
|
+
async def open(self) -> AsyncIterator[tuple[Any, Any]]:
|
|
69
|
+
"""Open the streamable-HTTP transport, yielding ``(read, write)`` for
|
|
70
|
+
``mcp.ClientSession`` -- across mcp client versions (the entry-point name,
|
|
71
|
+
the ``headers`` vs ``http_client`` argument, and the 2- vs 3-tuple yield
|
|
72
|
+
all differ between mcp 1.x and 2.x). Requires ``cortexhub[mcp]``.
|
|
73
|
+
|
|
74
|
+
.. code-block:: python
|
|
75
|
+
|
|
76
|
+
from mcp import ClientSession
|
|
77
|
+
|
|
78
|
+
async with s.mcp.open() as (read, write):
|
|
79
|
+
async with ClientSession(read, write) as mcp:
|
|
80
|
+
await mcp.initialize()
|
|
81
|
+
tools = await mcp.list_tools()
|
|
82
|
+
"""
|
|
83
|
+
opener = _streamable_http_opener()
|
|
84
|
+
async with opener(self.url, self.headers) as streams:
|
|
85
|
+
# 2.x yields (read, write); older releases add get_session_id.
|
|
86
|
+
yield streams[0], streams[1]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
__all__ = ["SessionMcp"]
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"""Session types for MCP programmatic OAuth."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
from dataclasses import dataclass, field
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@dataclass(frozen=True)
|
|
9
|
-
class SessionMcp:
|
|
10
|
-
"""MCP streamable-HTTP connection details for your framework."""
|
|
11
|
-
|
|
12
|
-
url: str
|
|
13
|
-
headers: dict[str, str] = field(default_factory=dict)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|