cortexhub 2.0.1__tar.gz → 2.0.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cortexhub
3
- Version: 2.0.1
3
+ Version: 2.0.3
4
4
  Summary: MCP gateway client for CortexHub programmatic agent access.
5
5
  Project-URL: Homepage, https://cortexhub.ai
6
6
  Project-URL: Documentation, https://docs.cortexhub.ai
@@ -44,6 +44,8 @@ from cortexhub import Cortexhub
44
44
  session = Cortexhub().session(
45
45
  agent="helpdesk-bot",
46
46
  mcp_session_id="chat-42", # optional: separate conversations in Cloud
47
+ conversation_title="Engineering standup", # optional: shown to operators
48
+ last_user_message="Create a standup page in Engineering Confluence", # optional
47
49
  )
48
50
  # session.mcp.url and session.mcp.headers → pass to your MCP transport
49
51
  ```
@@ -22,6 +22,8 @@ from cortexhub import Cortexhub
22
22
  session = Cortexhub().session(
23
23
  agent="helpdesk-bot",
24
24
  mcp_session_id="chat-42", # optional: separate conversations in Cloud
25
+ conversation_title="Engineering standup", # optional: shown to operators
26
+ last_user_message="Create a standup page in Engineering Confluence", # optional
25
27
  )
26
28
  # session.mcp.url and session.mcp.headers → pass to your MCP transport
27
29
  ```
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "cortexhub"
3
- version = "2.0.1"
3
+ version = "2.0.3"
4
4
  description = "MCP gateway client for CortexHub programmatic agent access."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -15,7 +15,7 @@ from .errors import APIError, AuthenticationError, ConfigurationError, Cortexhub
15
15
  from .mcp_oauth import CortexhubMcpOAuthClient, McpOAuthSession, McpOAuthToken
16
16
  from .session import SessionMcp
17
17
 
18
- __version__ = "2.1.0"
18
+ __version__ = "2.2.0"
19
19
  __all__ = [
20
20
  "Cortexhub",
21
21
  "CortexhubMcpOAuthClient",
@@ -3,6 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import os
6
+ from typing import Literal
6
7
 
7
8
  from .errors import ConfigurationError
8
9
  from .mcp_oauth import CortexhubMcpOAuthClient, McpOAuthSession
@@ -47,11 +48,19 @@ class Cortexhub(CortexhubMcpOAuthClient):
47
48
  *,
48
49
  agent: str,
49
50
  mcp_session_id: str | None = None,
51
+ conversation_title: str | None = None,
52
+ last_user_message: str | None = None,
53
+ invocation_mode: Literal["interactive", "scheduled", "programmatic"] | None = None,
50
54
  refresh: bool = False,
51
55
  ) -> McpOAuthSession:
52
56
  """Return MCP headers for ``agent`` (required on every programmatic call)."""
53
57
  return super().session(
54
- agent=agent, mcp_session_id=mcp_session_id, refresh=refresh
58
+ agent=agent,
59
+ mcp_session_id=mcp_session_id,
60
+ conversation_title=conversation_title,
61
+ last_user_message=last_user_message,
62
+ invocation_mode=invocation_mode,
63
+ refresh=refresh,
55
64
  )
56
65
 
57
66
  def __repr__(self) -> str:
@@ -7,13 +7,16 @@ import urllib.error
7
7
  import urllib.parse
8
8
  import urllib.request
9
9
  from dataclasses import dataclass, field
10
- from typing import Any
10
+ from typing import Any, Literal
11
11
 
12
12
  from ._config import base_url
13
13
  from .errors import APIError, AuthenticationError
14
14
  from .session import SessionMcp
15
15
 
16
+ _INVOCATION_MODE_HEADER = "X-CortexHub-Invocation-Mode"
16
17
  _AGENT_HEADER = "X-CortexHub-Agent"
18
+ _CONVERSATION_TITLE_HEADER = "X-CortexHub-Conversation-Title"
19
+ _LAST_USER_MESSAGE_HEADER = "X-CortexHub-Last-User-Message"
17
20
  _BEARER_HEADER = "Authorization"
18
21
 
19
22
 
@@ -26,6 +29,11 @@ class McpOAuthToken:
26
29
  scope: str = ""
27
30
 
28
31
 
32
+ InvocationMode = Literal["interactive", "scheduled", "programmatic"]
33
+
34
+ _VALID_INVOCATION_MODES = frozenset({"interactive", "scheduled", "programmatic"})
35
+
36
+
29
37
  @dataclass
30
38
  class McpOAuthSession:
31
39
  """MCP connection using Bearer JWT + optional agent and session headers."""
@@ -33,6 +41,9 @@ class McpOAuthSession:
33
41
  access_token: str
34
42
  agent: str | None = None
35
43
  mcp_session_id: str | None = None
44
+ conversation_title: str | None = None
45
+ last_user_message: str | None = None
46
+ invocation_mode: InvocationMode | None = None
36
47
  mcp: SessionMcp = field(init=False)
37
48
 
38
49
  def __post_init__(self) -> None:
@@ -43,6 +54,12 @@ class McpOAuthSession:
43
54
  headers[_AGENT_HEADER] = self.agent
44
55
  if self.mcp_session_id:
45
56
  headers["Mcp-Session-Id"] = self.mcp_session_id
57
+ if self.conversation_title:
58
+ headers[_CONVERSATION_TITLE_HEADER] = self.conversation_title
59
+ if self.last_user_message:
60
+ headers[_LAST_USER_MESSAGE_HEADER] = self.last_user_message
61
+ if self.invocation_mode:
62
+ headers[_INVOCATION_MODE_HEADER] = self.invocation_mode
46
63
  self.mcp = SessionMcp(url=f"{base_url()}/v1/mcp", headers=headers)
47
64
 
48
65
 
@@ -97,21 +114,43 @@ class CortexhubMcpOAuthClient:
97
114
  *,
98
115
  agent: str,
99
116
  mcp_session_id: str | None = None,
117
+ conversation_title: str | None = None,
118
+ last_user_message: str | None = None,
119
+ invocation_mode: InvocationMode | None = None,
100
120
  refresh: bool = False,
101
121
  ) -> McpOAuthSession:
102
122
  """Return MCP headers for ``agent`` (required on every programmatic call).
103
123
 
104
124
  Pass ``mcp_session_id`` (your chat or conversation id) to group tool
105
125
  activity into separate rows in CortexHub Cloud.
126
+
127
+ Pass ``conversation_title`` and ``last_user_message`` so operators can
128
+ see session context in the portal (sent on every MCP request via headers).
129
+
130
+ Pass ``invocation_mode`` for cron or background workers when policy allows
131
+ unattended execution; omit for interactive sessions (gateway default).
106
132
  """
107
133
  if not agent or not agent.strip():
108
134
  raise ValueError("agent= is required for programmatic MCP OAuth.")
135
+ if invocation_mode is not None and invocation_mode not in _VALID_INVOCATION_MODES:
136
+ raise ValueError(
137
+ "invocation_mode must be interactive, scheduled, or programmatic."
138
+ )
109
139
  token = self.fetch_token(refresh=refresh)
110
140
  session_id = (mcp_session_id or "").strip() or None
141
+ title = (conversation_title or "").strip() or None
142
+ user_message = (last_user_message or "").strip() or None
143
+ if title and len(title) > 500:
144
+ title = title[:500]
145
+ if user_message and len(user_message) > 500:
146
+ user_message = user_message[:500]
111
147
  return McpOAuthSession(
112
148
  access_token=token.access_token,
113
149
  agent=agent.strip(),
114
150
  mcp_session_id=session_id,
151
+ conversation_title=title,
152
+ last_user_message=user_message,
153
+ invocation_mode=invocation_mode,
115
154
  )
116
155
 
117
156
 
File without changes
File without changes