hyperforge 1.0.0.post450__tar.gz → 1.0.0.post460__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.
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/PKG-INFO +86 -6
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/README.md +85 -5
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/pyproject.toml +1 -1
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/pyproject.toml.orig +1 -1
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/app.py +3 -1
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/mcp_server_pool.py +38 -58
- hyperforge-1.0.0.post460/src/hyperforge/api/mcp_sessions.py +257 -0
- hyperforge-1.0.0.post460/src/hyperforge/api/mcp_transport.py +398 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/v1/interaction.py +3 -3
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/v1/mcp_interaction.py +129 -87
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/standalone/app.py +6 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/VERSION +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/__init__.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/a2a/__init__.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/a2a/auth.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/a2a/card.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/a2a/context.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/a2a/executor.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/a2a/run.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/a2a/server.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/a2a/settings.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/a2a/task_store.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/agent.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/alembic/README +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/alembic/env.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/alembic/script.py.mako +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/alembic/versions/049a4aed19e1_create_generation_table.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/alembic/versions/1416cb41bd49_add_downloads_table.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/alembic/versions/2847934e2d59_unique_driver.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/alembic/versions/4d89a36c8bda_memory.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/alembic/versions/6a23d8ef74c1_add_sync_oauth_credentials.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/alembic/versions/72b997edb05d_identifier_for_drivers.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/alembic/versions/8c7d2e4f91ab_structure_legacy_llm_fields.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/alembic/versions/9c6f6a1b4e7f_workflows_default_fk.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/alembic/versions/b8edb72295e0_.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/alembic/versions/f3d2c1b0a9e8_soft_delete_workflows.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/alembic.ini +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/__init__.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/authentication.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/commands.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/logging.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/models.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/session.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/settings.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/utils.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/v1/__init__.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/v1/agents.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/v1/mcp_content.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/v1/oauth.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/v1/prompt.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/v1/router.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/v1/schema.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/v1/session.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/v1/utils.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/api/v1/workflows.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/arag.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/broker/__init__.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/broker/local.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/broker/redis.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/codemode/__init__.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/codemode/model.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/codemode/sandbox.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/codemode/worker.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/completions.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/configure.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/context/__init__.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/context/agent.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/context/config.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/database.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/db/__init__.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/db/agents.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/db/encryption.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/db/exceptions.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/db/legacy_llm_migration.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/db/llm_migration_utils.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/db/settings.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/db/workflow_cleanup.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/definition.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/driver.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/dummy.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/engine.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/errors.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/exceptions.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/feature_flag.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/fixtures.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/harness/__init__.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/harness/agent.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/harness/config.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/harness_sdk/__init__.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/harness_sdk/agents.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/harness_sdk/clients.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/harness_sdk/context.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/harness_sdk/harness.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/harness_sdk/models.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/harness_sdk/schema.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/harness_sdk/storage.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/harness_sdk/tools/__init__.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/harness_sdk/tools/codemode.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/harness_sdk/tools/core.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/harness_sdk/tools/utils.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/harness_sdk/usage.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/interaction.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/json_schema.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/llm.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/llm_config.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/manager.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/memory/__init__.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/memory/memory.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/minimal_fixtures.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/models.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/openapi.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/procedural/__init__.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/procedural/adapters.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/procedural/cli.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/procedural/evolution.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/procedural/graph.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/procedural/guidance.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/prompts.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/pubsub.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/py.typed +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/redis_utils.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/result_payload.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/retrieval/__init__.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/retrieval/agent.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/retrieval/config.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/server/__init__.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/server/cache.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/server/run.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/server/sandbox.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/server/session.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/server/settings.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/server/utils.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/server/web.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/settings.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/standalone/__init__.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/standalone/agent.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/standalone/config.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/standalone/const.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/standalone/oauth.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/standalone/run.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/standalone/settings.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/standalone/ui_router.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/static/assets/index-DLejS5jC.js +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/static/assets/index-MoxkZ1_3.css +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/static/favicon.svg +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/static/index.html +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/trace.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/utils/__init__.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/utils/http.py +0 -0
- {hyperforge-1.0.0.post450 → hyperforge-1.0.0.post460}/src/hyperforge/workflows.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hyperforge
|
|
3
|
-
Version: 1.0.0.
|
|
3
|
+
Version: 1.0.0.post460
|
|
4
4
|
Summary: Agentic Framework for Orchestrated Runtime, Governance, and Execution
|
|
5
5
|
Author: AI Data Team
|
|
6
6
|
Author-email: AI Data Team <learning@nuclia.com>
|
|
@@ -152,11 +152,91 @@ after a 404, not reuse the expired ID.
|
|
|
152
152
|
Managers whose last connection has closed can be evicted immediately when the
|
|
153
153
|
pool is full.
|
|
154
154
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
155
|
+
API replicas share logical session metadata through the existing Redis/Valkey
|
|
156
|
+
broker. Each HTTP request runs in the receiving process, reconstructing the
|
|
157
|
+
SDK's initialization context from the stored client capabilities. No HTTP request,
|
|
158
|
+
authorization header, tool result or SSE frame is relayed between replicas.
|
|
159
|
+
This uses the existing MCP 2025 protocol and SDK 1.x, not MRTR. Standalone uses
|
|
160
|
+
the same adapter only when `BROKER_REDIS_DSN` is configured. Without Redis it uses
|
|
161
|
+
the SDK's native stateful transport, restricted to a single process/instance;
|
|
162
|
+
there is no in-memory implementation of the shared session store.
|
|
163
|
+
|
|
164
|
+
With Redis, tool calls use their original POST's SSE connection for elicitation,
|
|
165
|
+
progress and the final result. Separate GET streams and SSE reconnection using
|
|
166
|
+
Last-Event-ID are not supported (GET returns 405); clients must accept both JSON
|
|
167
|
+
and SSE. Initialization, tools/prompts listings and prompt retrieval retain JSON
|
|
168
|
+
responses. Standalone without Redis follows native SDK transport behavior:
|
|
169
|
+
request responses use SSE and GET streams are supported, without an event store
|
|
170
|
+
for replay.
|
|
171
|
+
|
|
172
|
+
Elicitation replies may arrive on any replica. Unique wire request IDs prevent
|
|
173
|
+
collisions even when concurrent calls in one MCP session execute in different
|
|
174
|
+
processes. Only pending replies and cancellation markers cross processes through
|
|
175
|
+
Redis. Replies are retained until delivered to the waiting SDK request; identical
|
|
176
|
+
duplicates cannot execute the tool again. Each session is bound to the complete
|
|
177
|
+
authenticated account/user/account-type/agent/session identity, not to an access
|
|
178
|
+
token or a pod. Deleting a session cancels its requests on all replicas without
|
|
179
|
+
affecting other clients.
|
|
180
|
+
|
|
181
|
+
Declined or cancelled URL/form elicitations fail the tool instead of resuming
|
|
182
|
+
the workflow with an empty response.
|
|
183
|
+
|
|
184
|
+
Sync Service Ask Agent OAuth is supported over MCP for ShareFile
|
|
185
|
+
(`sharefile_oauth`), Google Drive (`google_oauth`) and SharePoint/OneDrive
|
|
186
|
+
(`azure_oauth`). The MCP client must support URL elicitation. Authentication
|
|
187
|
+
uses the existing Sync service authorization flow and Hyperforge OAuth callback;
|
|
188
|
+
the client receives the authorization URL, not the credentials.
|
|
189
|
+
Credentials are encrypted and scoped by account, user, agent, provider and Sync
|
|
190
|
+
configuration. API deployments persist them in PostgreSQL; standalone keeps them
|
|
191
|
+
in process memory, so a restart requires authentication again. SharePoint
|
|
192
|
+
certificate connections (`azure_certificate_credentials`) are not supported by
|
|
193
|
+
this interactive OAuth flow.
|
|
194
|
+
|
|
195
|
+
Requests are registered before waiting for a local handler, so cancellation
|
|
196
|
+
received during handler creation prevents the tool from starting. Failed or
|
|
197
|
+
interrupted admission releases that request's cancellation marker.
|
|
198
|
+
Session and call TTLs are renewed during admission until transport polling
|
|
199
|
+
takes over; a slow handler startup does not expire an active request.
|
|
200
|
+
|
|
201
|
+
Requests renew their session and reply/cancellation mailboxes while active,
|
|
202
|
+
including while waiting for user input. Mailboxes use ordinary Redis keys with
|
|
203
|
+
TTLs, not execution leases or a distributed execution registry. Small
|
|
204
|
+
WATCH/MULTI transactions protect session admission and mailbox updates; there
|
|
205
|
+
are no custom Lua scripts. Session and registry TTLs are renewed atomically so
|
|
206
|
+
valid sessions remain included in admission accounting.
|
|
207
|
+
Store operations have bounded timeouts;
|
|
208
|
+
failed coordination stops the local execution instead of falling back to
|
|
209
|
+
uncoordinated state. Redis failures return 503 before a response starts, or
|
|
210
|
+
terminate an already-started stream. Idle sessions expire independently using
|
|
211
|
+
`MCP_SESSION_IDLE_TTL_SECONDS`. A pod shutdown does not remove shared sessions;
|
|
212
|
+
other replicas can handle subsequent requests.
|
|
213
|
+
|
|
214
|
+
Live Python tasks are not migrated and tools are never automatically replayed.
|
|
215
|
+
A pod failure or interrupted SSE connection can leave the outcome of an in-flight
|
|
216
|
+
call unknown; clients must not blindly retry tools with side effects. Existing
|
|
217
|
+
connections from the previous owner/relay implementation require reinitialization
|
|
218
|
+
when deploying this version. Drain the previous version before admitting traffic
|
|
219
|
+
to the new replicas; do not mix both session implementations behind one service.
|
|
220
|
+
|
|
221
|
+
With the Redis adapter, admission is bounded to 100 active HTTP requests per
|
|
222
|
+
process, including requests waiting for handler creation, and 100 pending server
|
|
223
|
+
requests per HTTP request. Slots are reserved before Redis call registration and
|
|
224
|
+
released on admission failure or response cleanup. There is no distributed
|
|
225
|
+
concurrent-call quota.
|
|
226
|
+
Control messages and replies
|
|
227
|
+
bypass that admission limit so full capacity cannot prevent completing or
|
|
228
|
+
cancelling a tool. `MCP_MAX_SESSIONS_PER_SERVER` limits shared sessions per
|
|
229
|
+
authenticated server identity, while `MCP_MAX_SERVERS` bounds each process's
|
|
230
|
+
cached handlers. Native SDK streams provide bounded in-process buffering.
|
|
231
|
+
`MCP_MAX_REQUEST_BYTES` limits incoming messages in both modes.
|
|
232
|
+
`MCP_MAX_RESPONSE_BYTES` limits each outgoing protocol message in the Redis
|
|
233
|
+
adapter; the native standalone transport uses SDK defaults for outgoing messages.
|
|
234
|
+
|
|
235
|
+
Use a private, trusted Redis deployment: pending elicitation replies may contain
|
|
236
|
+
sensitive user input. They are deleted after delivery or request cleanup; all
|
|
237
|
+
session and mailbox records have TTLs so a dead process cannot retain them
|
|
238
|
+
indefinitely. Coordination keys use hashed identities and a common
|
|
239
|
+
Redis Cluster hash tag so atomic operations stay within one slot.
|
|
160
240
|
|
|
161
241
|
### Standalone A2A
|
|
162
242
|
|
|
@@ -101,11 +101,91 @@ after a 404, not reuse the expired ID.
|
|
|
101
101
|
Managers whose last connection has closed can be evicted immediately when the
|
|
102
102
|
pool is full.
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
104
|
+
API replicas share logical session metadata through the existing Redis/Valkey
|
|
105
|
+
broker. Each HTTP request runs in the receiving process, reconstructing the
|
|
106
|
+
SDK's initialization context from the stored client capabilities. No HTTP request,
|
|
107
|
+
authorization header, tool result or SSE frame is relayed between replicas.
|
|
108
|
+
This uses the existing MCP 2025 protocol and SDK 1.x, not MRTR. Standalone uses
|
|
109
|
+
the same adapter only when `BROKER_REDIS_DSN` is configured. Without Redis it uses
|
|
110
|
+
the SDK's native stateful transport, restricted to a single process/instance;
|
|
111
|
+
there is no in-memory implementation of the shared session store.
|
|
112
|
+
|
|
113
|
+
With Redis, tool calls use their original POST's SSE connection for elicitation,
|
|
114
|
+
progress and the final result. Separate GET streams and SSE reconnection using
|
|
115
|
+
Last-Event-ID are not supported (GET returns 405); clients must accept both JSON
|
|
116
|
+
and SSE. Initialization, tools/prompts listings and prompt retrieval retain JSON
|
|
117
|
+
responses. Standalone without Redis follows native SDK transport behavior:
|
|
118
|
+
request responses use SSE and GET streams are supported, without an event store
|
|
119
|
+
for replay.
|
|
120
|
+
|
|
121
|
+
Elicitation replies may arrive on any replica. Unique wire request IDs prevent
|
|
122
|
+
collisions even when concurrent calls in one MCP session execute in different
|
|
123
|
+
processes. Only pending replies and cancellation markers cross processes through
|
|
124
|
+
Redis. Replies are retained until delivered to the waiting SDK request; identical
|
|
125
|
+
duplicates cannot execute the tool again. Each session is bound to the complete
|
|
126
|
+
authenticated account/user/account-type/agent/session identity, not to an access
|
|
127
|
+
token or a pod. Deleting a session cancels its requests on all replicas without
|
|
128
|
+
affecting other clients.
|
|
129
|
+
|
|
130
|
+
Declined or cancelled URL/form elicitations fail the tool instead of resuming
|
|
131
|
+
the workflow with an empty response.
|
|
132
|
+
|
|
133
|
+
Sync Service Ask Agent OAuth is supported over MCP for ShareFile
|
|
134
|
+
(`sharefile_oauth`), Google Drive (`google_oauth`) and SharePoint/OneDrive
|
|
135
|
+
(`azure_oauth`). The MCP client must support URL elicitation. Authentication
|
|
136
|
+
uses the existing Sync service authorization flow and Hyperforge OAuth callback;
|
|
137
|
+
the client receives the authorization URL, not the credentials.
|
|
138
|
+
Credentials are encrypted and scoped by account, user, agent, provider and Sync
|
|
139
|
+
configuration. API deployments persist them in PostgreSQL; standalone keeps them
|
|
140
|
+
in process memory, so a restart requires authentication again. SharePoint
|
|
141
|
+
certificate connections (`azure_certificate_credentials`) are not supported by
|
|
142
|
+
this interactive OAuth flow.
|
|
143
|
+
|
|
144
|
+
Requests are registered before waiting for a local handler, so cancellation
|
|
145
|
+
received during handler creation prevents the tool from starting. Failed or
|
|
146
|
+
interrupted admission releases that request's cancellation marker.
|
|
147
|
+
Session and call TTLs are renewed during admission until transport polling
|
|
148
|
+
takes over; a slow handler startup does not expire an active request.
|
|
149
|
+
|
|
150
|
+
Requests renew their session and reply/cancellation mailboxes while active,
|
|
151
|
+
including while waiting for user input. Mailboxes use ordinary Redis keys with
|
|
152
|
+
TTLs, not execution leases or a distributed execution registry. Small
|
|
153
|
+
WATCH/MULTI transactions protect session admission and mailbox updates; there
|
|
154
|
+
are no custom Lua scripts. Session and registry TTLs are renewed atomically so
|
|
155
|
+
valid sessions remain included in admission accounting.
|
|
156
|
+
Store operations have bounded timeouts;
|
|
157
|
+
failed coordination stops the local execution instead of falling back to
|
|
158
|
+
uncoordinated state. Redis failures return 503 before a response starts, or
|
|
159
|
+
terminate an already-started stream. Idle sessions expire independently using
|
|
160
|
+
`MCP_SESSION_IDLE_TTL_SECONDS`. A pod shutdown does not remove shared sessions;
|
|
161
|
+
other replicas can handle subsequent requests.
|
|
162
|
+
|
|
163
|
+
Live Python tasks are not migrated and tools are never automatically replayed.
|
|
164
|
+
A pod failure or interrupted SSE connection can leave the outcome of an in-flight
|
|
165
|
+
call unknown; clients must not blindly retry tools with side effects. Existing
|
|
166
|
+
connections from the previous owner/relay implementation require reinitialization
|
|
167
|
+
when deploying this version. Drain the previous version before admitting traffic
|
|
168
|
+
to the new replicas; do not mix both session implementations behind one service.
|
|
169
|
+
|
|
170
|
+
With the Redis adapter, admission is bounded to 100 active HTTP requests per
|
|
171
|
+
process, including requests waiting for handler creation, and 100 pending server
|
|
172
|
+
requests per HTTP request. Slots are reserved before Redis call registration and
|
|
173
|
+
released on admission failure or response cleanup. There is no distributed
|
|
174
|
+
concurrent-call quota.
|
|
175
|
+
Control messages and replies
|
|
176
|
+
bypass that admission limit so full capacity cannot prevent completing or
|
|
177
|
+
cancelling a tool. `MCP_MAX_SESSIONS_PER_SERVER` limits shared sessions per
|
|
178
|
+
authenticated server identity, while `MCP_MAX_SERVERS` bounds each process's
|
|
179
|
+
cached handlers. Native SDK streams provide bounded in-process buffering.
|
|
180
|
+
`MCP_MAX_REQUEST_BYTES` limits incoming messages in both modes.
|
|
181
|
+
`MCP_MAX_RESPONSE_BYTES` limits each outgoing protocol message in the Redis
|
|
182
|
+
adapter; the native standalone transport uses SDK defaults for outgoing messages.
|
|
183
|
+
|
|
184
|
+
Use a private, trusted Redis deployment: pending elicitation replies may contain
|
|
185
|
+
sensitive user input. They are deleted after delivery or request cleanup; all
|
|
186
|
+
session and mailbox records have TTLs so a dead process cannot retain them
|
|
187
|
+
indefinitely. Coordination keys use hashed identities and a common
|
|
188
|
+
Redis Cluster hash tag so atomic operations stay within one slot.
|
|
109
189
|
|
|
110
190
|
### Standalone A2A
|
|
111
191
|
|
|
@@ -4,7 +4,7 @@ build-backend = "uv_build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "hyperforge"
|
|
7
|
-
version = "1.0.0.
|
|
7
|
+
version = "1.0.0.post460"
|
|
8
8
|
authors = [{ name = "AI Data Team", email = "learning@nuclia.com" }]
|
|
9
9
|
description = "Agentic Framework for Orchestrated Runtime, Governance, and Execution"
|
|
10
10
|
readme = "README.md"
|
|
@@ -15,6 +15,7 @@ from hyperforge.api import SERVICE_NAME, logger, v1
|
|
|
15
15
|
from hyperforge.api.authentication import RaoAuthenticationBackend
|
|
16
16
|
from hyperforge.api.logging import set_sentry
|
|
17
17
|
from hyperforge.api.mcp_server_pool import MCPServerPool
|
|
18
|
+
from hyperforge.api.mcp_sessions import MCPSessionStore
|
|
18
19
|
from hyperforge.api.settings import Settings
|
|
19
20
|
from hyperforge.broker import Broker
|
|
20
21
|
from hyperforge.broker.redis import RedisBroker
|
|
@@ -45,6 +46,7 @@ async def health_alive():
|
|
|
45
46
|
|
|
46
47
|
|
|
47
48
|
class HTTPApplication(FastAPI):
|
|
49
|
+
mcp_sessions: MCPSessionStore
|
|
48
50
|
agent_manager: AgentManager
|
|
49
51
|
arag_search: NucliaDBAsync
|
|
50
52
|
arag_writer: NucliaDBAsync
|
|
@@ -153,7 +155,7 @@ class HTTPApplication(FastAPI):
|
|
|
153
155
|
settings=self.data_manager_settings
|
|
154
156
|
)
|
|
155
157
|
await self.agent_manager.initialize()
|
|
156
|
-
|
|
158
|
+
self.mcp_sessions = MCPSessionStore(self.broker.client)
|
|
157
159
|
for load_module in self.settings.load_modules:
|
|
158
160
|
try:
|
|
159
161
|
scan(load_module)
|
|
@@ -5,27 +5,28 @@ from typing import Any
|
|
|
5
5
|
|
|
6
6
|
import anyio
|
|
7
7
|
from fastapi import HTTPException
|
|
8
|
-
from mcp.server.streamable_http import MCP_SESSION_ID_HEADER
|
|
9
8
|
from mcp.server.streamable_http_manager import StreamableHTTPSessionManager
|
|
10
|
-
from starlette.
|
|
11
|
-
from starlette.
|
|
12
|
-
from starlette.types import Message, Receive, Scope, Send
|
|
9
|
+
from starlette.datastructures import Headers
|
|
10
|
+
from starlette.types import Receive, Scope, Send
|
|
13
11
|
|
|
14
12
|
from hyperforge.api import logger
|
|
13
|
+
from hyperforge.api.mcp_sessions import MCPServerKey
|
|
14
|
+
from hyperforge.api.mcp_transport import MCPTransport
|
|
15
15
|
|
|
16
|
-
MCPServerKey = tuple[str, str, str, str, str]
|
|
17
16
|
MCPServerFactory = Callable[[], Awaitable["ManagedMCPServer"]]
|
|
18
17
|
|
|
19
18
|
|
|
20
19
|
class ManagedMCPServer:
|
|
21
|
-
def __init__(
|
|
20
|
+
def __init__(
|
|
21
|
+
self,
|
|
22
|
+
manager: MCPTransport | StreamableHTTPSessionManager,
|
|
23
|
+
max_sessions: int = 100,
|
|
24
|
+
):
|
|
22
25
|
self.manager = manager
|
|
26
|
+
self.max_sessions = max_sessions
|
|
27
|
+
self._initialization_lock = anyio.Lock()
|
|
23
28
|
self.started = asyncio.Event()
|
|
24
29
|
self.task: asyncio.Task[None] | None = None
|
|
25
|
-
self.active_sessions = 0
|
|
26
|
-
self.max_sessions = max_sessions
|
|
27
|
-
self._session_creation_lock = anyio.Lock()
|
|
28
|
-
self._session_closed = anyio.Event()
|
|
29
30
|
self.has_been_leased = False
|
|
30
31
|
self.active_requests = 0
|
|
31
32
|
self.last_used = time.monotonic()
|
|
@@ -73,42 +74,27 @@ class ManagedMCPServer:
|
|
|
73
74
|
self.active_requests -= 1
|
|
74
75
|
self.last_used = time.monotonic()
|
|
75
76
|
|
|
76
|
-
def release_session(self) -> None:
|
|
77
|
-
self.active_sessions -= 1
|
|
78
|
-
self._session_closed.set()
|
|
79
|
-
self._session_closed = anyio.Event()
|
|
80
|
-
|
|
81
77
|
async def handle_request(self, scope: Scope, receive: Receive, send: Send) -> None:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return
|
|
78
|
+
if (
|
|
79
|
+
isinstance(self.manager, StreamableHTTPSessionManager)
|
|
80
|
+
and scope["method"] == "POST"
|
|
81
|
+
and not Headers(scope=scope).get("mcp-session-id")
|
|
82
|
+
):
|
|
83
|
+
async with self._initialization_lock:
|
|
84
|
+
if await self.session_count() >= self.max_sessions:
|
|
85
|
+
raise HTTPException(503, "MCP session capacity is exhausted")
|
|
91
86
|
await self.manager.handle_request(scope, receive, send)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
await self.manager.handle_request(scope, receive, observe_send)
|
|
104
|
-
if status == 200:
|
|
105
|
-
await session_closed.wait()
|
|
106
|
-
# SDK 1.x retains explicitly terminated transports.
|
|
107
|
-
session_id = request.headers["mcp-session-id"]
|
|
108
|
-
self.manager._server_instances.pop(session_id, None)
|
|
109
|
-
self.manager._session_owners.pop(session_id, None)
|
|
110
|
-
else:
|
|
111
|
-
await self.manager.handle_request(scope, receive, send)
|
|
87
|
+
return
|
|
88
|
+
await self.manager.handle_request(scope, receive, send)
|
|
89
|
+
|
|
90
|
+
async def session_count(self) -> int:
|
|
91
|
+
if isinstance(self.manager, MCPTransport):
|
|
92
|
+
return await self.manager.session_count()
|
|
93
|
+
# SDK 1.x has no public session counter; exclude transports awaiting teardown.
|
|
94
|
+
return sum(
|
|
95
|
+
not transport.is_terminated
|
|
96
|
+
for transport in self.manager._server_instances.values()
|
|
97
|
+
)
|
|
112
98
|
|
|
113
99
|
|
|
114
100
|
class MCPRequestLease:
|
|
@@ -143,8 +129,6 @@ class MCPServerPool:
|
|
|
143
129
|
async def acquire(
|
|
144
130
|
self,
|
|
145
131
|
key: MCPServerKey,
|
|
146
|
-
request: Request,
|
|
147
|
-
body: bytes,
|
|
148
132
|
factory: MCPServerFactory,
|
|
149
133
|
) -> MCPRequestLease:
|
|
150
134
|
stale_server = None
|
|
@@ -163,13 +147,9 @@ class MCPServerPool:
|
|
|
163
147
|
server = None
|
|
164
148
|
if server is not None:
|
|
165
149
|
return self._lease(server)
|
|
166
|
-
if request.headers.get(MCP_SESSION_ID_HEADER):
|
|
167
|
-
raise HTTPException(status_code=404, detail="MCP session not found")
|
|
168
|
-
if request.method != "POST":
|
|
169
|
-
raise HTTPException(status_code=400, detail="Missing Mcp-Session-Id")
|
|
170
150
|
creating_task = self._creating.get(key)
|
|
171
151
|
if creating_task is None:
|
|
172
|
-
self._reserve_capacity()
|
|
152
|
+
await self._reserve_capacity()
|
|
173
153
|
creating_task = asyncio.create_task(
|
|
174
154
|
self._create_server(key, factory, stale_server)
|
|
175
155
|
)
|
|
@@ -201,7 +181,7 @@ class MCPServerPool:
|
|
|
201
181
|
|
|
202
182
|
async with self._lock:
|
|
203
183
|
self._ensure_running()
|
|
204
|
-
self._evict_for_capacity()
|
|
184
|
+
await self._evict_for_capacity()
|
|
205
185
|
self._servers[key] = candidate
|
|
206
186
|
self._creating.pop(key, None)
|
|
207
187
|
registered = True
|
|
@@ -298,22 +278,22 @@ class MCPServerPool:
|
|
|
298
278
|
server.reserve_request()
|
|
299
279
|
return MCPRequestLease(server)
|
|
300
280
|
|
|
301
|
-
def _evict_for_capacity(self) -> None:
|
|
281
|
+
async def _evict_for_capacity(self) -> None:
|
|
302
282
|
while len(self._servers) >= self._max_servers:
|
|
303
|
-
self._evict_one()
|
|
283
|
+
await self._evict_one()
|
|
304
284
|
|
|
305
|
-
def _reserve_capacity(self) -> None:
|
|
285
|
+
async def _reserve_capacity(self) -> None:
|
|
306
286
|
while len(self._servers) + len(self._creating) >= self._max_servers:
|
|
307
|
-
self._evict_one()
|
|
287
|
+
await self._evict_one()
|
|
308
288
|
|
|
309
|
-
def _evict_one(self) -> None:
|
|
289
|
+
async def _evict_one(self) -> None:
|
|
310
290
|
now = time.monotonic()
|
|
311
291
|
candidates = [
|
|
312
292
|
(key, server)
|
|
313
293
|
for key, server in self._servers.items()
|
|
314
294
|
if server.active_requests == 0
|
|
315
295
|
and (
|
|
316
|
-
(server.has_been_leased and server.
|
|
296
|
+
(server.has_been_leased and await server.session_count() == 0)
|
|
317
297
|
or now - server.last_used >= self._idle_ttl_seconds
|
|
318
298
|
)
|
|
319
299
|
]
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import hashlib
|
|
3
|
+
import json
|
|
4
|
+
import uuid
|
|
5
|
+
from collections.abc import Callable
|
|
6
|
+
from contextlib import asynccontextmanager
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from fastapi import HTTPException
|
|
10
|
+
from mcp.types import InitializeRequestParams, RequestId
|
|
11
|
+
from pydantic import BaseModel
|
|
12
|
+
from redis.asyncio import Redis
|
|
13
|
+
from redis.exceptions import RedisError, WatchError
|
|
14
|
+
|
|
15
|
+
from hyperforge.api import logger
|
|
16
|
+
|
|
17
|
+
MCPServerKey = tuple[str, str, str, str, str]
|
|
18
|
+
MAX_ACTIVE_CALLS = 100
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class MCPSession(BaseModel):
|
|
22
|
+
params: InitializeRequestParams
|
|
23
|
+
ready: bool = False
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class MCPUpdates(BaseModel):
|
|
27
|
+
cancelled: bool = False
|
|
28
|
+
replies: dict[str, str] = {}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class MCPSessionStore:
|
|
32
|
+
"""Session metadata and TTL-backed mailboxes; executions remain local."""
|
|
33
|
+
|
|
34
|
+
def __init__(self, client: Redis):
|
|
35
|
+
self.client = client
|
|
36
|
+
self.active_requests: set[asyncio.Task[Any]] = set()
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
def keys(key: MCPServerKey, session_id: str) -> tuple[str, str]:
|
|
40
|
+
digest = hashlib.sha256(json.dumps(key).encode()).hexdigest()
|
|
41
|
+
prefix = f"mcp:{{{digest}}}"
|
|
42
|
+
return prefix + ":sessions", prefix + ":" + session_id
|
|
43
|
+
|
|
44
|
+
@asynccontextmanager
|
|
45
|
+
async def _available(self, ttl: int):
|
|
46
|
+
try:
|
|
47
|
+
async with asyncio.timeout(min(5, ttl / 3)):
|
|
48
|
+
yield
|
|
49
|
+
except (RedisError, TimeoutError) as exc:
|
|
50
|
+
logger.warning("MCP coordination unavailable (%s)", type(exc).__name__)
|
|
51
|
+
raise HTTPException(503, "MCP coordination is unavailable") from exc
|
|
52
|
+
|
|
53
|
+
async def _read(self, names: list[str], ttl: int) -> list[str | None]:
|
|
54
|
+
async with (
|
|
55
|
+
self._available(ttl),
|
|
56
|
+
self.client.pipeline(transaction=True) as pipe,
|
|
57
|
+
):
|
|
58
|
+
for name in names:
|
|
59
|
+
pipe.getex(name, ex=ttl)
|
|
60
|
+
return await pipe.execute()
|
|
61
|
+
|
|
62
|
+
async def _add(self, name: str, value: str, ttl: int) -> None:
|
|
63
|
+
async with self._available(ttl):
|
|
64
|
+
added = await self.client.set(name, value, ex=ttl, nx=True)
|
|
65
|
+
if not added:
|
|
66
|
+
raise HTTPException(409, "MCP request is already active")
|
|
67
|
+
|
|
68
|
+
async def _change(
|
|
69
|
+
self, name: str, change: Callable[[str | None], str | None], ttl: int
|
|
70
|
+
) -> str | None:
|
|
71
|
+
async with (
|
|
72
|
+
self._available(ttl),
|
|
73
|
+
self.client.pipeline(transaction=True) as pipe,
|
|
74
|
+
):
|
|
75
|
+
while True:
|
|
76
|
+
try:
|
|
77
|
+
await pipe.watch(name)
|
|
78
|
+
previous = await pipe.get(name)
|
|
79
|
+
value = change(previous)
|
|
80
|
+
if value == previous:
|
|
81
|
+
return previous
|
|
82
|
+
pipe.multi()
|
|
83
|
+
if value is None:
|
|
84
|
+
pipe.delete(name)
|
|
85
|
+
else:
|
|
86
|
+
pipe.set(name, value, keepttl=True)
|
|
87
|
+
await pipe.execute()
|
|
88
|
+
return previous
|
|
89
|
+
except WatchError:
|
|
90
|
+
continue
|
|
91
|
+
|
|
92
|
+
async def _delete(self, names: list[str], ttl: int) -> None:
|
|
93
|
+
async with self._available(ttl):
|
|
94
|
+
await self.client.delete(*names)
|
|
95
|
+
|
|
96
|
+
async def session_count(self, key: MCPServerKey, ttl: int) -> int:
|
|
97
|
+
registry, prefix = self.keys(key, "")
|
|
98
|
+
async with self._available(ttl):
|
|
99
|
+
ids = list(await self.client.smembers(registry))
|
|
100
|
+
if not ids:
|
|
101
|
+
return 0
|
|
102
|
+
expired = await self._expired(prefix, ids)
|
|
103
|
+
if expired:
|
|
104
|
+
await self.client.srem(registry, *expired)
|
|
105
|
+
return len(ids) - len(expired)
|
|
106
|
+
|
|
107
|
+
async def _expired(self, prefix: str, ids: list[str]) -> list[str]:
|
|
108
|
+
async with self.client.pipeline(transaction=False) as pipe:
|
|
109
|
+
for sid in ids:
|
|
110
|
+
pipe.exists(prefix + sid)
|
|
111
|
+
present = await pipe.execute()
|
|
112
|
+
return [sid for sid, exists in zip(ids, present) if not exists]
|
|
113
|
+
|
|
114
|
+
async def create(
|
|
115
|
+
self, key: MCPServerKey, params: InitializeRequestParams, ttl: int, limit: int
|
|
116
|
+
) -> str:
|
|
117
|
+
sid = uuid.uuid4().hex
|
|
118
|
+
registry, name = self.keys(key, sid)
|
|
119
|
+
value = MCPSession(params=params).model_dump_json(by_alias=True)
|
|
120
|
+
async with (
|
|
121
|
+
self._available(ttl),
|
|
122
|
+
self.client.pipeline(transaction=True) as pipe,
|
|
123
|
+
):
|
|
124
|
+
while True:
|
|
125
|
+
try:
|
|
126
|
+
await pipe.watch(registry)
|
|
127
|
+
ids = list(await pipe.smembers(registry))
|
|
128
|
+
expired = await self._expired(self.keys(key, "")[1], ids)
|
|
129
|
+
if len(ids) - len(expired) >= limit:
|
|
130
|
+
raise HTTPException(503, "MCP session capacity is exhausted")
|
|
131
|
+
remaining = await pipe.ttl(registry)
|
|
132
|
+
pipe.multi()
|
|
133
|
+
if expired:
|
|
134
|
+
pipe.srem(registry, *expired)
|
|
135
|
+
pipe.set(name, value, ex=ttl)
|
|
136
|
+
pipe.sadd(registry, sid)
|
|
137
|
+
pipe.expire(registry, max(ttl, remaining))
|
|
138
|
+
await pipe.execute()
|
|
139
|
+
break
|
|
140
|
+
except WatchError:
|
|
141
|
+
continue
|
|
142
|
+
return sid
|
|
143
|
+
|
|
144
|
+
async def get(self, key: MCPServerKey, sid: str, ttl: int) -> MCPSession:
|
|
145
|
+
registry, name = self.keys(key, sid)
|
|
146
|
+
async with (
|
|
147
|
+
self._available(ttl),
|
|
148
|
+
self.client.pipeline(transaction=True) as pipe,
|
|
149
|
+
):
|
|
150
|
+
pipe.getex(name, ex=ttl)
|
|
151
|
+
pipe.expire(registry, ttl, gt=True)
|
|
152
|
+
value, _ = await pipe.execute()
|
|
153
|
+
if value is None:
|
|
154
|
+
raise HTTPException(404, "MCP session not found")
|
|
155
|
+
return MCPSession.model_validate_json(value)
|
|
156
|
+
|
|
157
|
+
async def ready(self, key: MCPServerKey, sid: str, ttl: int) -> None:
|
|
158
|
+
session = await self.get(key, sid, ttl)
|
|
159
|
+
session.ready = True
|
|
160
|
+
await self._change(
|
|
161
|
+
self.keys(key, sid)[1],
|
|
162
|
+
lambda value: session.model_dump_json(by_alias=True) if value else value,
|
|
163
|
+
ttl,
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
async def delete(self, key: MCPServerKey, sid: str, ttl: int) -> None:
|
|
167
|
+
await self._delete([self.keys(key, sid)[1]], ttl)
|
|
168
|
+
|
|
169
|
+
def _call_key(self, key: MCPServerKey, sid: str, request_id: RequestId) -> str:
|
|
170
|
+
digest = hashlib.sha256(json.dumps(request_id).encode()).hexdigest()
|
|
171
|
+
return self.keys(key, sid)[1] + ":call:" + digest
|
|
172
|
+
|
|
173
|
+
async def start(
|
|
174
|
+
self, key: MCPServerKey, sid: str, request_id: RequestId, ttl: int
|
|
175
|
+
) -> str:
|
|
176
|
+
token = uuid.uuid4().hex
|
|
177
|
+
await self._add(self._call_key(key, sid, request_id), token, ttl)
|
|
178
|
+
return token
|
|
179
|
+
|
|
180
|
+
async def cancel(
|
|
181
|
+
self, key: MCPServerKey, sid: str, request_id: RequestId, ttl: int
|
|
182
|
+
) -> None:
|
|
183
|
+
await self._change(
|
|
184
|
+
self._call_key(key, sid, request_id),
|
|
185
|
+
lambda value: (
|
|
186
|
+
"cancelled:" + value
|
|
187
|
+
if value and not value.startswith("cancelled:")
|
|
188
|
+
else value
|
|
189
|
+
),
|
|
190
|
+
ttl,
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
def _reply_key(self, key: MCPServerKey, sid: str, wire_id: str) -> str:
|
|
194
|
+
return self.keys(key, sid)[1] + ":reply:" + wire_id
|
|
195
|
+
|
|
196
|
+
async def pending(
|
|
197
|
+
self, key: MCPServerKey, sid: str, wire_id: str, ttl: int
|
|
198
|
+
) -> None:
|
|
199
|
+
await self._add(self._reply_key(key, sid, wire_id), "", ttl)
|
|
200
|
+
|
|
201
|
+
async def reply(
|
|
202
|
+
self, key: MCPServerKey, sid: str, wire_id: str, body: str, ttl: int
|
|
203
|
+
) -> bool:
|
|
204
|
+
previous = await self._change(
|
|
205
|
+
self._reply_key(key, sid, wire_id),
|
|
206
|
+
lambda value: body if value == "" else value,
|
|
207
|
+
ttl,
|
|
208
|
+
)
|
|
209
|
+
if previous not in {None, "", body}:
|
|
210
|
+
raise HTTPException(409, "MCP request already has a different response")
|
|
211
|
+
return previous is not None
|
|
212
|
+
|
|
213
|
+
async def poll(
|
|
214
|
+
self,
|
|
215
|
+
key: MCPServerKey,
|
|
216
|
+
sid: str,
|
|
217
|
+
request_id: RequestId,
|
|
218
|
+
token: str,
|
|
219
|
+
pending: list[str],
|
|
220
|
+
ttl: int,
|
|
221
|
+
) -> MCPUpdates:
|
|
222
|
+
await self.get(key, sid, ttl)
|
|
223
|
+
call, *replies = await self._read(
|
|
224
|
+
[
|
|
225
|
+
self._call_key(key, sid, request_id),
|
|
226
|
+
*(self._reply_key(key, sid, wire_id) for wire_id in pending),
|
|
227
|
+
],
|
|
228
|
+
ttl,
|
|
229
|
+
)
|
|
230
|
+
return MCPUpdates(
|
|
231
|
+
cancelled=call != token or any(reply is None for reply in replies),
|
|
232
|
+
replies={
|
|
233
|
+
wire_id: reply for wire_id, reply in zip(pending, replies) if reply
|
|
234
|
+
},
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
async def acknowledge(
|
|
238
|
+
self, key: MCPServerKey, sid: str, ids: list[str], ttl: int
|
|
239
|
+
) -> None:
|
|
240
|
+
if ids:
|
|
241
|
+
await self._delete([self._reply_key(key, sid, id_) for id_ in ids], ttl)
|
|
242
|
+
|
|
243
|
+
async def finish(
|
|
244
|
+
self,
|
|
245
|
+
key: MCPServerKey,
|
|
246
|
+
sid: str,
|
|
247
|
+
request_id: RequestId,
|
|
248
|
+
token: str,
|
|
249
|
+
pending: list[str],
|
|
250
|
+
ttl: int,
|
|
251
|
+
) -> None:
|
|
252
|
+
await self._change(
|
|
253
|
+
self._call_key(key, sid, request_id),
|
|
254
|
+
lambda value: None if value in {token, "cancelled:" + token} else value,
|
|
255
|
+
ttl,
|
|
256
|
+
)
|
|
257
|
+
await self.acknowledge(key, sid, pending, ttl)
|