redis-context-gateway 0.1.0a1__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.
Files changed (127) hide show
  1. redis_context_gateway-0.1.0a1/PKG-INFO +82 -0
  2. redis_context_gateway-0.1.0a1/README.md +60 -0
  3. redis_context_gateway-0.1.0a1/py.typed +1 -0
  4. redis_context_gateway-0.1.0a1/pyproject.toml +57 -0
  5. redis_context_gateway-0.1.0a1/src/redis_context_gateway/__init__.py +17 -0
  6. redis_context_gateway-0.1.0a1/src/redis_context_gateway/_hooks/__init__.py +5 -0
  7. redis_context_gateway-0.1.0a1/src/redis_context_gateway/_hooks/registration.py +142 -0
  8. redis_context_gateway-0.1.0a1/src/redis_context_gateway/_hooks/sdkhooks.py +76 -0
  9. redis_context_gateway-0.1.0a1/src/redis_context_gateway/_hooks/types.py +124 -0
  10. redis_context_gateway-0.1.0a1/src/redis_context_gateway/_version.py +17 -0
  11. redis_context_gateway-0.1.0a1/src/redis_context_gateway/basesdk.py +392 -0
  12. redis_context_gateway-0.1.0a1/src/redis_context_gateway/errors/__init__.py +122 -0
  13. redis_context_gateway-0.1.0a1/src/redis_context_gateway/errors/apierror.py +40 -0
  14. redis_context_gateway-0.1.0a1/src/redis_context_gateway/errors/authenticationerrorresponsecontent.py +47 -0
  15. redis_context_gateway-0.1.0a1/src/redis_context_gateway/errors/badrequesterrorresponsecontent.py +50 -0
  16. redis_context_gateway-0.1.0a1/src/redis_context_gateway/errors/contextgatewayconflicterrorresponsecontent.py +52 -0
  17. redis_context_gateway-0.1.0a1/src/redis_context_gateway/errors/contextgatewayerror.py +30 -0
  18. redis_context_gateway-0.1.0a1/src/redis_context_gateway/errors/contextgatewaynotfounderrorresponsecontent.py +48 -0
  19. redis_context_gateway-0.1.0a1/src/redis_context_gateway/errors/contextgatewayunprocessableerrorresponsecontent.py +52 -0
  20. redis_context_gateway-0.1.0a1/src/redis_context_gateway/errors/faileddependencyerrorresponsecontent.py +47 -0
  21. redis_context_gateway-0.1.0a1/src/redis_context_gateway/errors/forbiddenerrorresponsecontent.py +45 -0
  22. redis_context_gateway-0.1.0a1/src/redis_context_gateway/errors/no_response_error.py +17 -0
  23. redis_context_gateway-0.1.0a1/src/redis_context_gateway/errors/resourcesuspendederrorresponsecontent.py +47 -0
  24. redis_context_gateway-0.1.0a1/src/redis_context_gateway/errors/responsevalidationerror.py +27 -0
  25. redis_context_gateway-0.1.0a1/src/redis_context_gateway/errors/serviceunavailableerrorresponsecontent.py +44 -0
  26. redis_context_gateway-0.1.0a1/src/redis_context_gateway/errors/timeouterrorresponsecontent.py +45 -0
  27. redis_context_gateway-0.1.0a1/src/redis_context_gateway/errors/unexpectederrorresponsecontent.py +47 -0
  28. redis_context_gateway-0.1.0a1/src/redis_context_gateway/gateways.py +1138 -0
  29. redis_context_gateway-0.1.0a1/src/redis_context_gateway/health.py +313 -0
  30. redis_context_gateway-0.1.0a1/src/redis_context_gateway/httpclient.py +125 -0
  31. redis_context_gateway-0.1.0a1/src/redis_context_gateway/mcp.py +49 -0
  32. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/__init__.py +426 -0
  33. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/activecatalog.py +24 -0
  34. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/authenticationerrortype.py +8 -0
  35. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/authenticationinput.py +39 -0
  36. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/authenticationmethodinput.py +47 -0
  37. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/authenticationmethodoutput.py +39 -0
  38. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/authenticationoutput.py +22 -0
  39. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/badrequesterrortype.py +8 -0
  40. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/bearermethodinput.py +37 -0
  41. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/bearermethodoutput.py +13 -0
  42. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/catalogfailure.py +55 -0
  43. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/connection.py +21 -0
  44. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/connectiondatabase.py +19 -0
  45. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/contextgatewayconflicterrortype.py +17 -0
  46. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/contextgatewaynotfounderrortype.py +18 -0
  47. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/contextgatewayunprocessableerrortype.py +7 -0
  48. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/contextsurface.py +50 -0
  49. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/contextsurfaceconnection.py +16 -0
  50. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/creategatewayrequestcontent.py +60 -0
  51. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/creategatewayresponsecontent.py +87 -0
  52. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/createupstreamop.py +35 -0
  53. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/createupstreamrequestcontent.py +91 -0
  54. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/createupstreamresponsecontent.py +130 -0
  55. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/deletegatewayop.py +34 -0
  56. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/deleteupstreamop.py +70 -0
  57. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/droppedtoolpolicy.py +60 -0
  58. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/droppedtoolpolicyreason.py +14 -0
  59. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/faileddependencyerrortype.py +15 -0
  60. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/fielderror.py +29 -0
  61. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/forbiddenerrortype.py +8 -0
  62. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/gatewayoutput.py +87 -0
  63. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/getgatewayop.py +21 -0
  64. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/getgatewayresponsecontent.py +87 -0
  65. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/getupstreamop.py +30 -0
  66. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/getupstreamresponsecontent.py +114 -0
  67. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/headermethodinput.py +38 -0
  68. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/headermethodoutput.py +15 -0
  69. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/listgatewaysop.py +44 -0
  70. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/listgatewaysresponsecontent.py +44 -0
  71. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/listupstreamsop.py +57 -0
  72. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/listupstreamsresponsecontent.py +52 -0
  73. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/listupstreamtoolsop.py +30 -0
  74. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/listupstreamtoolsresponsecontent.py +17 -0
  75. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/liveresponsecontent.py +13 -0
  76. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/mcpconnection.py +37 -0
  77. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/notcacheablereason.py +15 -0
  78. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/readyresponsecontent.py +13 -0
  79. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/refreshupstreamcatalogop.py +30 -0
  80. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/refreshupstreamcatalogresponsecontent.py +114 -0
  81. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/resourcesuspendederrortype.py +8 -0
  82. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/resultcachepolicy.py +22 -0
  83. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/resulthandlecapture.py +7 -0
  84. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/resulthandlepolicy.py +48 -0
  85. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/security.py +42 -0
  86. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/serviceunavailableerrortype.py +7 -0
  87. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/timeouterrortype.py +8 -0
  88. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/toolexposuremode.py +17 -0
  89. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/toolpolicy.py +53 -0
  90. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/transport.py +7 -0
  91. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/unexpectederrortype.py +8 -0
  92. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/unreadablereason.py +7 -0
  93. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/unreadableupstream.py +23 -0
  94. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/updategatewayop.py +35 -0
  95. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/updategatewayrequestcontent.py +86 -0
  96. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/updategatewayresponsecontent.py +87 -0
  97. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/updateupstreamop.py +44 -0
  98. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/updateupstreamrequestcontent.py +85 -0
  99. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/updateupstreamresponsecontent.py +138 -0
  100. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/upstreamkind.py +14 -0
  101. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/upstreamsummary.py +73 -0
  102. redis_context_gateway-0.1.0a1/src/redis_context_gateway/models/upstreamtool.py +84 -0
  103. redis_context_gateway-0.1.0a1/src/redis_context_gateway/py.typed +1 -0
  104. redis_context_gateway-0.1.0a1/src/redis_context_gateway/sdk.py +192 -0
  105. redis_context_gateway-0.1.0a1/src/redis_context_gateway/sdkconfiguration.py +49 -0
  106. redis_context_gateway-0.1.0a1/src/redis_context_gateway/types/__init__.py +24 -0
  107. redis_context_gateway-0.1.0a1/src/redis_context_gateway/types/base64fileinput.py +43 -0
  108. redis_context_gateway-0.1.0a1/src/redis_context_gateway/types/basemodel.py +77 -0
  109. redis_context_gateway-0.1.0a1/src/redis_context_gateway/upstreams.py +1897 -0
  110. redis_context_gateway-0.1.0a1/src/redis_context_gateway/utils/__init__.py +180 -0
  111. redis_context_gateway-0.1.0a1/src/redis_context_gateway/utils/annotations.py +79 -0
  112. redis_context_gateway-0.1.0a1/src/redis_context_gateway/utils/datetimes.py +41 -0
  113. redis_context_gateway-0.1.0a1/src/redis_context_gateway/utils/dynamic_imports.py +54 -0
  114. redis_context_gateway-0.1.0a1/src/redis_context_gateway/utils/enums.py +134 -0
  115. redis_context_gateway-0.1.0a1/src/redis_context_gateway/utils/eventstreaming.py +326 -0
  116. redis_context_gateway-0.1.0a1/src/redis_context_gateway/utils/forms.py +239 -0
  117. redis_context_gateway-0.1.0a1/src/redis_context_gateway/utils/headers.py +136 -0
  118. redis_context_gateway-0.1.0a1/src/redis_context_gateway/utils/logger.py +22 -0
  119. redis_context_gateway-0.1.0a1/src/redis_context_gateway/utils/metadata.py +119 -0
  120. redis_context_gateway-0.1.0a1/src/redis_context_gateway/utils/queryparams.py +217 -0
  121. redis_context_gateway-0.1.0a1/src/redis_context_gateway/utils/requestbodies.py +67 -0
  122. redis_context_gateway-0.1.0a1/src/redis_context_gateway/utils/retries.py +372 -0
  123. redis_context_gateway-0.1.0a1/src/redis_context_gateway/utils/security.py +198 -0
  124. redis_context_gateway-0.1.0a1/src/redis_context_gateway/utils/serializers.py +326 -0
  125. redis_context_gateway-0.1.0a1/src/redis_context_gateway/utils/unmarshal_json_response.py +38 -0
  126. redis_context_gateway-0.1.0a1/src/redis_context_gateway/utils/url.py +154 -0
  127. redis_context_gateway-0.1.0a1/src/redis_context_gateway/utils/values.py +142 -0
@@ -0,0 +1,82 @@
1
+ Metadata-Version: 2.4
2
+ Name: redis-context-gateway
3
+ Version: 0.1.0a1
4
+ Summary: Redis Context Gateway REST and MCP SDK
5
+ License: MIT
6
+ Author: Redis AI Services Team
7
+ Requires-Python: >=3.10
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Programming Language :: Python :: 3.15
16
+ Requires-Dist: httpcore (>=1.0.9)
17
+ Requires-Dist: httpx (>=0.28.1,<1)
18
+ Requires-Dist: mcp (>=1.30.0,<2)
19
+ Requires-Dist: pydantic (>=2.11.2)
20
+ Description-Content-Type: text/markdown
21
+
22
+ # redis-context-gateway
23
+
24
+ Python SDK for Redis Context Gateway. The REST client is generated by Speakeasy from the Gateway control-plane API, the same way as the other Iris SDKs. A small helper connects agents to a Gateway's MCP endpoint with the official `mcp` library.
25
+
26
+ Unpublished first increment, generated from `redislabsdev/iris@7b8fb322e`. Python 3.10 or later.
27
+
28
+ ## Control plane
29
+
30
+ ```python
31
+ from redis_context_gateway import ContextGatewayClient
32
+
33
+ with ContextGatewayClient(server_url=control_plane_url, admin_token=admin_token) as client:
34
+ gateway = client.gateways.create(display_name="Docs", tool_exposure_mode="search")
35
+ upstream = client.upstreams.create(
36
+ gateway_id=gateway.id,
37
+ display_name="Docs MCP",
38
+ namespace="docs",
39
+ connection={"endpoint": upstream_mcp_url},
40
+ authentication={"methods": [{"bearer": {"value": upstream_token}}]},
41
+ )
42
+ ```
43
+
44
+ Every product call sends the admin token. The health probes (`client.health.live()`, `client.health.ready()`) send no credential. Async variants end in `_async`. See [USAGE.md](USAGE.md) and [docs/](docs/) for every operation and model.
45
+
46
+ ## Agents (MCP)
47
+
48
+ ```python
49
+ from redis_context_gateway.mcp import connect
50
+
51
+ async with connect(gateway.mcp_endpoint, agent_key) as session:
52
+ found = await session.call_tool("search_tools", {"query": "find an issue"})
53
+ result = await session.call_tool(
54
+ "run_tool", {"tool": {"upstreamId": upstream.id, "originalName": "get_issue"}, "toolArgs": {"id": 42}}
55
+ )
56
+ ```
57
+
58
+ `connect` returns an initialized official `mcp.ClientSession`, so Lens instrumentation applies as is. The agent key is an Identity Service key with a `context-retriever` / `cr-gateway` / `use` grant for the Gateway. Search tools, `run_tool` and the result handle tools are ordinary tool calls. A tool failure comes back as a result with `isError: true`, not an exception.
59
+
60
+ MCP reads default to a 300-second inactivity timeout, with 30-second connect, write and connection-pool budgets. Pass `timeout=10` to use ten seconds for every HTTP timeout, or `timeout=httpx.Timeout(30, read=600)` for a separate read budget. These are HTTP inactivity limits, not a total tool-call deadline. REST timeout defaults are unchanged.
61
+
62
+ ## Safety
63
+
64
+ - Neither client follows redirects, so the admin token and agent keys stay on the Gateway.
65
+ - Plain HTTP is refused unless the host is loopback (localhost, 127.0.0.0/8 or ::1).
66
+ - Each request must match its own operation's method, path and query names, so an ID like `../../v1/gateways` fails before anything is sent. A custom HTTP client that can't turn redirects off is refused with a `TypeError`.
67
+ - The SDK never reads credentials from environment variables. Pass them in explicitly. The `redis-iris` CLI and goal objects own `IRIS_CONTEXT_GATEWAY_*` settings and the `[context_gateway]` config table.
68
+ - Upstream secrets are write-only: no response model carries them.
69
+ - Generated payload debugging is disabled, even when `debug_logger` is supplied, because it would log request secrets. Application logging and custom HTTP transports are outside this guarantee. Do not log whole generated exceptions: validation diagnostics can retain supplied credentials, and response errors retain server-provided bodies.
70
+ - No call is retried automatically.
71
+
72
+ ## Development
73
+
74
+ ```sh
75
+ uv venv && uv pip install -e . pytest pytest-asyncio ruff
76
+ # Python 3.11+: install the local Lens package for its integration test.
77
+ uv pip install ../lens-python-sdk
78
+ .venv/bin/python -m pytest tests
79
+ ```
80
+
81
+ Hand-written files are `src/redis_context_gateway/_hooks/registration.py`, `src/redis_context_gateway/mcp.py`, `tests/` and this README, protected by `.genignore`. Everything else is regenerated by `node scripts/generate-context-gateway.mjs` from the repository root.
82
+
@@ -0,0 +1,60 @@
1
+ # redis-context-gateway
2
+
3
+ Python SDK for Redis Context Gateway. The REST client is generated by Speakeasy from the Gateway control-plane API, the same way as the other Iris SDKs. A small helper connects agents to a Gateway's MCP endpoint with the official `mcp` library.
4
+
5
+ Unpublished first increment, generated from `redislabsdev/iris@7b8fb322e`. Python 3.10 or later.
6
+
7
+ ## Control plane
8
+
9
+ ```python
10
+ from redis_context_gateway import ContextGatewayClient
11
+
12
+ with ContextGatewayClient(server_url=control_plane_url, admin_token=admin_token) as client:
13
+ gateway = client.gateways.create(display_name="Docs", tool_exposure_mode="search")
14
+ upstream = client.upstreams.create(
15
+ gateway_id=gateway.id,
16
+ display_name="Docs MCP",
17
+ namespace="docs",
18
+ connection={"endpoint": upstream_mcp_url},
19
+ authentication={"methods": [{"bearer": {"value": upstream_token}}]},
20
+ )
21
+ ```
22
+
23
+ Every product call sends the admin token. The health probes (`client.health.live()`, `client.health.ready()`) send no credential. Async variants end in `_async`. See [USAGE.md](USAGE.md) and [docs/](docs/) for every operation and model.
24
+
25
+ ## Agents (MCP)
26
+
27
+ ```python
28
+ from redis_context_gateway.mcp import connect
29
+
30
+ async with connect(gateway.mcp_endpoint, agent_key) as session:
31
+ found = await session.call_tool("search_tools", {"query": "find an issue"})
32
+ result = await session.call_tool(
33
+ "run_tool", {"tool": {"upstreamId": upstream.id, "originalName": "get_issue"}, "toolArgs": {"id": 42}}
34
+ )
35
+ ```
36
+
37
+ `connect` returns an initialized official `mcp.ClientSession`, so Lens instrumentation applies as is. The agent key is an Identity Service key with a `context-retriever` / `cr-gateway` / `use` grant for the Gateway. Search tools, `run_tool` and the result handle tools are ordinary tool calls. A tool failure comes back as a result with `isError: true`, not an exception.
38
+
39
+ MCP reads default to a 300-second inactivity timeout, with 30-second connect, write and connection-pool budgets. Pass `timeout=10` to use ten seconds for every HTTP timeout, or `timeout=httpx.Timeout(30, read=600)` for a separate read budget. These are HTTP inactivity limits, not a total tool-call deadline. REST timeout defaults are unchanged.
40
+
41
+ ## Safety
42
+
43
+ - Neither client follows redirects, so the admin token and agent keys stay on the Gateway.
44
+ - Plain HTTP is refused unless the host is loopback (localhost, 127.0.0.0/8 or ::1).
45
+ - Each request must match its own operation's method, path and query names, so an ID like `../../v1/gateways` fails before anything is sent. A custom HTTP client that can't turn redirects off is refused with a `TypeError`.
46
+ - The SDK never reads credentials from environment variables. Pass them in explicitly. The `redis-iris` CLI and goal objects own `IRIS_CONTEXT_GATEWAY_*` settings and the `[context_gateway]` config table.
47
+ - Upstream secrets are write-only: no response model carries them.
48
+ - Generated payload debugging is disabled, even when `debug_logger` is supplied, because it would log request secrets. Application logging and custom HTTP transports are outside this guarantee. Do not log whole generated exceptions: validation diagnostics can retain supplied credentials, and response errors retain server-provided bodies.
49
+ - No call is retried automatically.
50
+
51
+ ## Development
52
+
53
+ ```sh
54
+ uv venv && uv pip install -e . pytest pytest-asyncio ruff
55
+ # Python 3.11+: install the local Lens package for its integration test.
56
+ uv pip install ../lens-python-sdk
57
+ .venv/bin/python -m pytest tests
58
+ ```
59
+
60
+ Hand-written files are `src/redis_context_gateway/_hooks/registration.py`, `src/redis_context_gateway/mcp.py`, `tests/` and this README, protected by `.genignore`. Everything else is regenerated by `node scripts/generate-context-gateway.mjs` from the repository root.
@@ -0,0 +1 @@
1
+ # Marker file for PEP 561. The package enables type hints.
@@ -0,0 +1,57 @@
1
+
2
+ [project]
3
+ name = "redis-context-gateway"
4
+ version = "0.1.0-alpha.1"
5
+ description = "Redis Context Gateway REST and MCP SDK"
6
+ authors = [{ name = "Redis AI Services Team" },]
7
+ readme = "README.md"
8
+ requires-python = ">=3.10"
9
+ dependencies = [
10
+ "httpcore >=1.0.9",
11
+ "httpx >=0.28.1,<1",
12
+ "mcp >=1.30.0,<2",
13
+ "pydantic >=2.11.2",
14
+ ]
15
+ license = { text = "MIT" }
16
+
17
+ [tool.poetry]
18
+ packages = [
19
+ { include = "redis_context_gateway", from = "src" }
20
+ ]
21
+ include = ["py.typed", "src/redis_context_gateway/py.typed"]
22
+
23
+ [tool.setuptools.package-data]
24
+ "*" = ["py.typed", "src/redis_context_gateway/py.typed"]
25
+
26
+ [virtualenvs]
27
+ in-project = true
28
+
29
+ [tool.poetry.group.dev.dependencies]
30
+ mypy = "==1.15.0"
31
+ pylint = "==3.2.3"
32
+ pyright = "==1.1.398"
33
+
34
+ [build-system]
35
+ requires = ["poetry-core"]
36
+ build-backend = "poetry.core.masonry.api"
37
+
38
+ [tool.pytest.ini_options]
39
+ asyncio_default_fixture_loop_scope = "function"
40
+ pythonpath = ["src"]
41
+
42
+ [tool.mypy]
43
+ disable_error_code = "misc"
44
+ explicit_package_bases = true
45
+ mypy_path = "src"
46
+
47
+ [[tool.mypy.overrides]]
48
+ module = "typing_inspect"
49
+ ignore_missing_imports = true
50
+
51
+ [[tool.mypy.overrides]]
52
+ module = "jsonpath"
53
+ ignore_missing_imports = true
54
+
55
+ [tool.pyright]
56
+ venvPath = "."
57
+ venv = ".venv"
@@ -0,0 +1,17 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from ._version import (
4
+ __title__,
5
+ __version__,
6
+ __openapi_doc_version__,
7
+ __gen_version__,
8
+ __user_agent__,
9
+ )
10
+ from .sdk import *
11
+ from .sdkconfiguration import *
12
+
13
+
14
+ VERSION: str = __version__
15
+ OPENAPI_DOC_VERSION = __openapi_doc_version__
16
+ SPEAKEASY_GENERATOR_VERSION = __gen_version__
17
+ USER_AGENT = __user_agent__
@@ -0,0 +1,5 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from .sdkhooks import *
4
+ from .types import *
5
+ from .registration import *
@@ -0,0 +1,142 @@
1
+ import ipaddress
2
+ import re
3
+ from collections.abc import Iterable
4
+ from typing import Any, cast
5
+
6
+ import httpx
7
+
8
+ from ..utils.logger import NoOpLogger
9
+ from .types import BeforeRequestHook, Hooks, SDKInitHook
10
+
11
+ # This file is only ever generated once on the first generation and then is free to be modified.
12
+ # Any hooks you wish to add should be registered in the init_hooks function. Feel free to define them
13
+ # in this file or in separate files in the hooks folder.
14
+
15
+ _ID = "[0-9a-f]{32}"
16
+ _PAGE = frozenset({"nextToken", "maxResults"})
17
+
18
+
19
+ def _route(method, path, queries: Iterable[str] = ()):
20
+ return method, re.compile(path), frozenset(queries)
21
+
22
+
23
+ # The request shape of every operation in the pinned openapi-context-gateway.json. A path
24
+ # parameter is narrowed to the spec's own pattern. tests/test_control_plane.py fails when this
25
+ # table and the pinned paths disagree, so a regenerated SDK can't drift from it silently.
26
+ CONTROL_PLANE_ROUTES = {
27
+ "ListGateways": _route("GET", "/v1/gateways", _PAGE),
28
+ "CreateGateway": _route("POST", "/v1/gateways"),
29
+ "DeleteGateway": _route("DELETE", f"/v1/gateways/{_ID}", {"expectedRevision"}),
30
+ "GetGateway": _route("GET", f"/v1/gateways/{_ID}"),
31
+ "UpdateGateway": _route("PATCH", f"/v1/gateways/{_ID}"),
32
+ "ListUpstreams": _route("GET", f"/v1/gateways/{_ID}/upstreams", _PAGE),
33
+ "CreateUpstream": _route("POST", f"/v1/gateways/{_ID}/upstreams"),
34
+ "DeleteUpstream": _route(
35
+ "DELETE",
36
+ f"/v1/gateways/{_ID}/upstreams/{_ID}",
37
+ {"expectedRevision", "ignoreIndexSweepFailure"},
38
+ ),
39
+ "GetUpstream": _route("GET", f"/v1/gateways/{_ID}/upstreams/{_ID}"),
40
+ "UpdateUpstream": _route("PATCH", f"/v1/gateways/{_ID}/upstreams/{_ID}"),
41
+ "RefreshUpstreamCatalog": _route(
42
+ "POST", f"/v1/gateways/{_ID}/upstreams/{_ID}/refresh"
43
+ ),
44
+ "ListUpstreamTools": _route("GET", f"/v1/gateways/{_ID}/upstreams/{_ID}/tools"),
45
+ "Live": _route("GET", "/v1/health/live"),
46
+ "Ready": _route("GET", "/v1/health/ready"),
47
+ }
48
+
49
+
50
+ def _is_loopback(host: str) -> bool:
51
+ if host.lower() == "localhost":
52
+ return True
53
+ try:
54
+ return ipaddress.ip_address(host).is_loopback
55
+ except ValueError:
56
+ return False
57
+
58
+
59
+ def require_safe_transport_url(url) -> None:
60
+ """Refuse a URL that would carry a credential in clear text off this machine.
61
+
62
+ HTTPS is always allowed. Plain HTTP is allowed only to a loopback host (``localhost``,
63
+ ``127.0.0.0/8`` or ``::1``) for local development.
64
+ """
65
+ parsed = httpx.URL(str(url))
66
+ if parsed.scheme == "https":
67
+ return
68
+ if parsed.scheme == "http" and _is_loopback(parsed.host):
69
+ return
70
+ raise ValueError(
71
+ f"Context Gateway URL {parsed.scheme}://{parsed.host} must use HTTPS. "
72
+ "Plain HTTP is allowed only to localhost, 127.0.0.0/8 or ::1."
73
+ )
74
+
75
+
76
+ def _encoded_path(url: httpx.URL) -> str:
77
+ return url.raw_path.split(b"?", 1)[0].decode("ascii")
78
+
79
+
80
+ class SafeTransport(SDKInitHook):
81
+ """Disable redirects and generated payload logging for credential-bearing calls."""
82
+
83
+ def sdk_init(self, config):
84
+ # Generated debug logging includes write-only Upstream credentials.
85
+ config.debug_logger = NoOpLogger()
86
+ for client in (config.client, config.async_client):
87
+ if client is None:
88
+ continue
89
+ if not hasattr(client, "follow_redirects"):
90
+ raise TypeError(
91
+ f"{type(client).__name__} has no follow_redirects attribute, so the "
92
+ "Context Gateway SDK can't turn redirects off and keep the admin token "
93
+ "on the Gateway. Pass an httpx.Client or httpx.AsyncClient, or a client "
94
+ "with a follow_redirects attribute."
95
+ )
96
+ cast(Any, client).follow_redirects = False
97
+ return config
98
+
99
+
100
+ class SafeRequest(BeforeRequestHook):
101
+ """Send a request only over HTTPS (or loopback HTTP) and only in its operation's shape.
102
+
103
+ The generated SDK puts path parameters into the URL unencoded, so an ID such as
104
+ ``../../v1/gateways`` or ``x?y=1#`` would reach a different resource. Every request must
105
+ match the method, path and query names of its own operation in the pinned spec.
106
+ """
107
+
108
+ def before_request(self, hook_ctx, request):
109
+ require_safe_transport_url(request.url)
110
+ route = CONTROL_PLANE_ROUTES.get(hook_ctx.operation_id)
111
+ if route is None:
112
+ raise ValueError(
113
+ f"Unknown Context Gateway operation {hook_ctx.operation_id!r}. "
114
+ "Add its path to CONTROL_PLANE_ROUTES."
115
+ )
116
+ method, path, queries = route
117
+ base_url = hook_ctx.base_url or hook_ctx.config.get_server_details()[0]
118
+ base_path = _encoded_path(httpx.URL(base_url)).rstrip("/")
119
+ request_path = _encoded_path(request.url)
120
+ names = {name for name, _ in request.url.params.multi_items()}
121
+ if (
122
+ request.method != method
123
+ # An ID ending in "#" leaves an empty fragment that url.fragment reports as "".
124
+ or "#" in str(request.url)
125
+ or not request_path.startswith(base_path)
126
+ or not path.fullmatch(request_path[len(base_path) :])
127
+ or not names <= queries
128
+ ):
129
+ raise ValueError(
130
+ f"Refusing {hook_ctx.operation_id}: request path {request_path!r} does not "
131
+ f"match {method} {path.pattern}. Gateway and Upstream IDs are 32 lowercase "
132
+ "hexadecimal characters."
133
+ )
134
+ return request
135
+
136
+
137
+ def init_hooks(hooks: Hooks):
138
+ """Add hooks by calling hooks.register{sdk_init/before_request/after_success/after_error}Hook
139
+ with an instance of a hook that implements that specific Hook interface
140
+ Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance"""
141
+ hooks.register_sdk_init_hook(SafeTransport())
142
+ hooks.register_before_request_hook(SafeRequest())
@@ -0,0 +1,76 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ import httpx
4
+ from .types import (
5
+ SDKInitHook,
6
+ BeforeRequestContext,
7
+ BeforeRequestHook,
8
+ AfterSuccessContext,
9
+ AfterSuccessHook,
10
+ AfterErrorContext,
11
+ AfterErrorHook,
12
+ Hooks,
13
+ )
14
+ from .registration import init_hooks
15
+ from typing import List, Optional, Tuple
16
+ from redis_context_gateway.sdkconfiguration import SDKConfiguration
17
+
18
+
19
+ class SDKHooks(Hooks):
20
+ def __init__(self) -> None:
21
+ self.sdk_init_hooks: List[SDKInitHook] = []
22
+ self.before_request_hooks: List[BeforeRequestHook] = []
23
+ self.after_success_hooks: List[AfterSuccessHook] = []
24
+ self.after_error_hooks: List[AfterErrorHook] = []
25
+ init_hooks(self)
26
+
27
+ def register_sdk_init_hook(self, hook: SDKInitHook) -> None:
28
+ self.sdk_init_hooks.append(hook)
29
+
30
+ def register_before_request_hook(self, hook: BeforeRequestHook) -> None:
31
+ self.before_request_hooks.append(hook)
32
+
33
+ def register_after_success_hook(self, hook: AfterSuccessHook) -> None:
34
+ self.after_success_hooks.append(hook)
35
+
36
+ def register_after_error_hook(self, hook: AfterErrorHook) -> None:
37
+ self.after_error_hooks.append(hook)
38
+
39
+ def sdk_init(self, config: SDKConfiguration) -> SDKConfiguration:
40
+ for hook in self.sdk_init_hooks:
41
+ config = hook.sdk_init(config)
42
+ return config
43
+
44
+ def before_request(
45
+ self, hook_ctx: BeforeRequestContext, request: httpx.Request
46
+ ) -> httpx.Request:
47
+ for hook in self.before_request_hooks:
48
+ out = hook.before_request(hook_ctx, request)
49
+ if isinstance(out, Exception):
50
+ raise out
51
+ request = out
52
+
53
+ return request
54
+
55
+ def after_success(
56
+ self, hook_ctx: AfterSuccessContext, response: httpx.Response
57
+ ) -> httpx.Response:
58
+ for hook in self.after_success_hooks:
59
+ out = hook.after_success(hook_ctx, response)
60
+ if isinstance(out, Exception):
61
+ raise out
62
+ response = out
63
+ return response
64
+
65
+ def after_error(
66
+ self,
67
+ hook_ctx: AfterErrorContext,
68
+ response: Optional[httpx.Response],
69
+ error: Optional[Exception],
70
+ ) -> Tuple[Optional[httpx.Response], Optional[Exception]]:
71
+ for hook in self.after_error_hooks:
72
+ result = hook.after_error(hook_ctx, response, error)
73
+ if isinstance(result, Exception):
74
+ raise result
75
+ response, error = result
76
+ return response, error
@@ -0,0 +1,124 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from abc import ABC, abstractmethod
4
+ import httpx
5
+ from redis_context_gateway.sdkconfiguration import SDKConfiguration
6
+ from typing import Any, Callable, Dict, List, Optional, Tuple, Union
7
+
8
+
9
+ class HookContext:
10
+ config: SDKConfiguration
11
+ base_url: str
12
+ operation_id: str
13
+ oauth2_scopes: Optional[List[str]] = None
14
+ security_source: Optional[Union[Any, Callable[[], Any]]] = None
15
+ tags: Optional[List[str]] = None
16
+ extensions: Optional[Dict[str, Any]] = None
17
+
18
+ def __init__(
19
+ self,
20
+ config: SDKConfiguration,
21
+ base_url: str,
22
+ operation_id: str,
23
+ oauth2_scopes: Optional[List[str]],
24
+ security_source: Optional[Union[Any, Callable[[], Any]]],
25
+ tags: Optional[List[str]],
26
+ extensions: Optional[Dict[str, Any]],
27
+ ):
28
+ self.config = config
29
+ self.base_url = base_url
30
+ self.operation_id = operation_id
31
+ self.oauth2_scopes = oauth2_scopes
32
+ self.security_source = security_source
33
+ self.tags = tags
34
+ self.extensions = extensions
35
+
36
+
37
+ class BeforeRequestContext(HookContext):
38
+ def __init__(self, hook_ctx: HookContext):
39
+ super().__init__(
40
+ hook_ctx.config,
41
+ hook_ctx.base_url,
42
+ hook_ctx.operation_id,
43
+ hook_ctx.oauth2_scopes,
44
+ hook_ctx.security_source,
45
+ hook_ctx.tags,
46
+ hook_ctx.extensions,
47
+ )
48
+
49
+
50
+ class AfterSuccessContext(HookContext):
51
+ def __init__(self, hook_ctx: HookContext):
52
+ super().__init__(
53
+ hook_ctx.config,
54
+ hook_ctx.base_url,
55
+ hook_ctx.operation_id,
56
+ hook_ctx.oauth2_scopes,
57
+ hook_ctx.security_source,
58
+ hook_ctx.tags,
59
+ hook_ctx.extensions,
60
+ )
61
+
62
+
63
+ class AfterErrorContext(HookContext):
64
+ def __init__(self, hook_ctx: HookContext):
65
+ super().__init__(
66
+ hook_ctx.config,
67
+ hook_ctx.base_url,
68
+ hook_ctx.operation_id,
69
+ hook_ctx.oauth2_scopes,
70
+ hook_ctx.security_source,
71
+ hook_ctx.tags,
72
+ hook_ctx.extensions,
73
+ )
74
+
75
+
76
+ class SDKInitHook(ABC):
77
+ @abstractmethod
78
+ def sdk_init(self, config: SDKConfiguration) -> SDKConfiguration:
79
+ pass
80
+
81
+
82
+ class BeforeRequestHook(ABC):
83
+ @abstractmethod
84
+ def before_request(
85
+ self, hook_ctx: BeforeRequestContext, request: httpx.Request
86
+ ) -> Union[httpx.Request, Exception]:
87
+ pass
88
+
89
+
90
+ class AfterSuccessHook(ABC):
91
+ @abstractmethod
92
+ def after_success(
93
+ self, hook_ctx: AfterSuccessContext, response: httpx.Response
94
+ ) -> Union[httpx.Response, Exception]:
95
+ pass
96
+
97
+
98
+ class AfterErrorHook(ABC):
99
+ @abstractmethod
100
+ def after_error(
101
+ self,
102
+ hook_ctx: AfterErrorContext,
103
+ response: Optional[httpx.Response],
104
+ error: Optional[Exception],
105
+ ) -> Union[Tuple[Optional[httpx.Response], Optional[Exception]], Exception]:
106
+ pass
107
+
108
+
109
+ class Hooks(ABC):
110
+ @abstractmethod
111
+ def register_sdk_init_hook(self, hook: SDKInitHook):
112
+ pass
113
+
114
+ @abstractmethod
115
+ def register_before_request_hook(self, hook: BeforeRequestHook):
116
+ pass
117
+
118
+ @abstractmethod
119
+ def register_after_success_hook(self, hook: AfterSuccessHook):
120
+ pass
121
+
122
+ @abstractmethod
123
+ def register_after_error_hook(self, hook: AfterErrorHook):
124
+ pass
@@ -0,0 +1,17 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ import importlib.metadata
4
+
5
+ __title__: str = "redis-context-gateway"
6
+ __version__: str = "0.1.0-alpha.1"
7
+ __openapi_doc_version__: str = "0.0.1"
8
+ __gen_version__: str = "2.948.4"
9
+ __user_agent__: str = (
10
+ "speakeasy-sdk/python 0.1.0-alpha.1 2.948.4 0.0.1 redis-context-gateway"
11
+ )
12
+
13
+ try:
14
+ if __package__ is not None:
15
+ __version__ = importlib.metadata.version(__package__)
16
+ except importlib.metadata.PackageNotFoundError:
17
+ pass