deepquery-sdk 1.0.0__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 (46) hide show
  1. deepquery_sdk-1.0.0/.gitignore +35 -0
  2. deepquery_sdk-1.0.0/CHANGELOG.md +43 -0
  3. deepquery_sdk-1.0.0/LICENSE +190 -0
  4. deepquery_sdk-1.0.0/MIGRATIONS.md +47 -0
  5. deepquery_sdk-1.0.0/PKG-INFO +195 -0
  6. deepquery_sdk-1.0.0/README.md +165 -0
  7. deepquery_sdk-1.0.0/examples/bad_connector.py +34 -0
  8. deepquery_sdk-1.0.0/examples/jira_connector/__init__.py +5 -0
  9. deepquery_sdk-1.0.0/examples/jira_connector/connector.py +110 -0
  10. deepquery_sdk-1.0.0/examples/manual_action_flow.py +77 -0
  11. deepquery_sdk-1.0.0/examples/manual_client.py +105 -0
  12. deepquery_sdk-1.0.0/examples/run_jira_server.py +30 -0
  13. deepquery_sdk-1.0.0/my_tool/README.md +22 -0
  14. deepquery_sdk-1.0.0/my_tool/connector.py +74 -0
  15. deepquery_sdk-1.0.0/pyproject.toml +53 -0
  16. deepquery_sdk-1.0.0/src/deepquery_sdk/__init__.py +101 -0
  17. deepquery_sdk-1.0.0/src/deepquery_sdk/action.py +104 -0
  18. deepquery_sdk-1.0.0/src/deepquery_sdk/auth/__init__.py +45 -0
  19. deepquery_sdk-1.0.0/src/deepquery_sdk/auth/base.py +96 -0
  20. deepquery_sdk-1.0.0/src/deepquery_sdk/auth/oauth2.py +106 -0
  21. deepquery_sdk-1.0.0/src/deepquery_sdk/auth/strategies.py +91 -0
  22. deepquery_sdk-1.0.0/src/deepquery_sdk/classification.py +43 -0
  23. deepquery_sdk-1.0.0/src/deepquery_sdk/cli/__init__.py +5 -0
  24. deepquery_sdk-1.0.0/src/deepquery_sdk/cli/__main__.py +64 -0
  25. deepquery_sdk-1.0.0/src/deepquery_sdk/cli/commands.py +208 -0
  26. deepquery_sdk-1.0.0/src/deepquery_sdk/cli/loader.py +95 -0
  27. deepquery_sdk-1.0.0/src/deepquery_sdk/compat.py +79 -0
  28. deepquery_sdk-1.0.0/src/deepquery_sdk/connector.py +283 -0
  29. deepquery_sdk-1.0.0/src/deepquery_sdk/gate.py +83 -0
  30. deepquery_sdk-1.0.0/src/deepquery_sdk/harness/__init__.py +5 -0
  31. deepquery_sdk-1.0.0/src/deepquery_sdk/harness/mock_agent.py +119 -0
  32. deepquery_sdk-1.0.0/src/deepquery_sdk/manifest.py +78 -0
  33. deepquery_sdk-1.0.0/src/deepquery_sdk/mcp_emit/__init__.py +5 -0
  34. deepquery_sdk-1.0.0/src/deepquery_sdk/mcp_emit/emitter.py +174 -0
  35. deepquery_sdk-1.0.0/src/deepquery_sdk/provenance.py +65 -0
  36. deepquery_sdk-1.0.0/src/deepquery_sdk/resource.py +65 -0
  37. deepquery_sdk-1.0.0/src/deepquery_sdk/templates/connector/.gitignore.tmpl +9 -0
  38. deepquery_sdk-1.0.0/src/deepquery_sdk/templates/connector/README.md.tmpl +22 -0
  39. deepquery_sdk-1.0.0/src/deepquery_sdk/templates/connector/connector.py.tmpl +74 -0
  40. deepquery_sdk-1.0.0/src/deepquery_sdk/templates/connector/pyproject.toml.tmpl +23 -0
  41. deepquery_sdk-1.0.0/src/deepquery_sdk/templates/connector/tests/test_connector.py.tmpl +41 -0
  42. deepquery_sdk-1.0.0/src/deepquery_sdk/validation.py +201 -0
  43. deepquery_sdk-1.0.0/tests/test_phase1.py +118 -0
  44. deepquery_sdk-1.0.0/tests/test_phase2.py +210 -0
  45. deepquery_sdk-1.0.0/tests/test_phase3.py +135 -0
  46. deepquery_sdk-1.0.0/tests/test_phase4.py +112 -0
@@ -0,0 +1,35 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+
7
+ # Packaging / build artifacts
8
+ build/
9
+ dist/
10
+ *.egg-info/
11
+ .eggs/
12
+
13
+ # Virtual environments
14
+ venv/
15
+ .venv/
16
+ env/
17
+
18
+ # Test / tooling caches
19
+ .pytest_cache/
20
+ .mypy_cache/
21
+ .ruff_cache/
22
+ htmlcov/
23
+ .coverage
24
+ coverage.xml
25
+
26
+ # Environment / secrets
27
+ .env
28
+ .env.*
29
+ .pypirc
30
+
31
+ # OS / editor
32
+ .DS_Store
33
+ Thumbs.db
34
+ .vscode/
35
+ .idea/
@@ -0,0 +1,43 @@
1
+ # Changelog
2
+
3
+ All notable changes to DeepQuerySDK are documented here. The SDK follows
4
+ [Semantic Versioning](https://semver.org). A breaking change to the base
5
+ `Connector` class, the provenance envelope, or the manifest schema is a **major**
6
+ bump and ships with an entry in [MIGRATIONS.md](MIGRATIONS.md).
7
+
8
+ ## [1.0.0] — 2026-06-07
9
+
10
+ First stable release. Establishes the SDK contract at **major version 1**:
11
+ connectors declaring `sdk_major_version = 1` are loadable by this runtime.
12
+
13
+ ### Core contracts (Phase 1)
14
+ - Base `Connector`, `@resource`, and `@action` abstractions.
15
+ - Read/action classification, surfaced as `dq.mutates` / `dq.kind` MCP metadata.
16
+ - The provenance envelope and `self.cite(...)` helper.
17
+ - `mcp_emit` layer wrapping the official MCP server SDK — every connector emits a
18
+ compliant MCP server.
19
+
20
+ ### Safety & auth (Phase 2)
21
+ - Gated action lifecycle: **preview → approve → execute** and **reject**, driven
22
+ by single-use, argument-bound approval tokens and the `dq.execute_action` /
23
+ `dq.reject_action` control tools.
24
+ - Auth strategies (`ApiKeyAuth`, `BasicAuth`, `BearerAuth`, `OAuth2Auth`,
25
+ `MTLSAuth`) and OAuth 2.1 PKCE flow-construction scaffolding.
26
+ - Gateway credential injection via a call-scoped provider; connectors never store
27
+ credentials.
28
+
29
+ ### Tooling & harness (Phase 3)
30
+ - `deepquery` CLI: `scaffold`, `validate`, `run-dev`, `emit`, `manifest`.
31
+ - `validate` encodes the §5/§6/§13 safety contracts, including AST detection of a
32
+ resource that mutates (a misclassified action).
33
+ - `MockAgent` dev harness driving reads and the full action/approval flow over a
34
+ real in-memory MCP session.
35
+
36
+ ### Packaging & versioning (Phase 4)
37
+ - Semver compatibility contract and manifest version negotiation
38
+ (`assert_compatible`); the gateway refuses connectors built against an
39
+ incompatible SDK major with a clear error.
40
+ - `scaffold` generates a complete, shippable connector project.
41
+ - Published to PyPI as `deepquery-sdk`.
42
+
43
+ [1.0.0]: https://github.com/GilbertAshivaka/deepquery-sdk/releases/tag/v1.0.0
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work, excluding
103
+ those notices that do not pertain to any part of the Derivative
104
+ Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works.
111
+
112
+ You may add Your own copyright statement to Your modifications and
113
+ may provide additional or different license terms and conditions
114
+ for use, reproduction, or distribution of Your modifications, or
115
+ for any such Derivative Works as a whole, provided Your use,
116
+ reproduction, and distribution of the Work otherwise complies with
117
+ the conditions stated in this License.
118
+
119
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
120
+ any Contribution intentionally submitted for inclusion in the Work
121
+ by You to the Licensor shall be under the terms and conditions of
122
+ this License, without any additional terms or conditions.
123
+ Notwithstanding the above, nothing herein shall supersede or modify
124
+ the terms of any separate license agreement you may have executed
125
+ with Licensor regarding such Contributions.
126
+
127
+ 6. Trademarks. This License does not grant permission to use the trade
128
+ names, trademarks, service marks, or product names of the Licensor,
129
+ except as required for reasonable and customary use in describing the
130
+ origin of the Work and reproducing the content of the NOTICE file.
131
+
132
+ 7. Disclaimer of Warranty. Unless required by applicable law or
133
+ agreed to in writing, Licensor provides the Work (and each
134
+ Contributor provides its Contributions) on an "AS IS" BASIS,
135
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
136
+ implied, including, without limitation, any warranties or conditions
137
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
138
+ PARTICULAR PURPOSE. You are solely responsible for determining the
139
+ appropriateness of using or redistributing the Work and assume any
140
+ risks associated with Your exercise of permissions under this License.
141
+
142
+ 8. Limitation of Liability. In no event and under no legal theory,
143
+ whether in tort (including negligence), contract, or otherwise,
144
+ unless required by applicable law (such as deliberate and grossly
145
+ negligent acts) or agreed to in writing, shall any Contributor be
146
+ liable to You for damages, including any direct, indirect, special,
147
+ incidental, or consequential damages of any character arising as a
148
+ result of this License or out of the use or inability to use the
149
+ Work (including but not limited to damages for loss of goodwill,
150
+ work stoppage, computer failure or malfunction, or any and all
151
+ other commercial damages or losses), even if such Contributor
152
+ has been advised of the possibility of such damages.
153
+
154
+ 9. Accepting Warranty or Additional Liability. While redistributing
155
+ the Work or Derivative Works thereof, You may choose to offer,
156
+ and charge a fee for, acceptance of support, warranty, indemnity,
157
+ or other liability obligations and/or rights consistent with this
158
+ License. However, in accepting such obligations, You may act only
159
+ on Your own behalf and on Your sole responsibility, not on behalf
160
+ of any other Contributor, and only if You agree to indemnify,
161
+ defend, and hold each Contributor harmless for any liability
162
+ incurred by, or claims asserted against, such Contributor by reason
163
+ of your accepting any such warranty or additional liability.
164
+
165
+ END OF TERMS AND CONDITIONS
166
+
167
+ APPENDIX: How to apply the Apache License to your work.
168
+
169
+ To apply the Apache License to your work, attach the following
170
+ boilerplate notice, with the fields enclosed by brackets "[]"
171
+ replaced with your own identifying information. (Don't include
172
+ the brackets!) The text should be enclosed in the appropriate
173
+ comment syntax for the file format. We also recommend that a
174
+ file or class name and description of purpose be included on the
175
+ same "printed page" as the copyright notice for easier
176
+ identification within third-party archives.
177
+
178
+ Copyright 2026 Deep Query
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,47 @@
1
+ # Migration Guides
2
+
3
+ This document describes **how** DeepQuerySDK handles breaking changes, and holds
4
+ a migration guide for every major-version bump.
5
+
6
+ ## The compatibility contract (§11)
7
+
8
+ - Every connector manifest declares the SDK **major** version it targets
9
+ (`sdk_major_version`).
10
+ - At load time the Connector Gateway calls `assert_compatible(manifest)`:
11
+ - same major as the runtime → **loads**.
12
+ - newer major than the runtime → **refused**: upgrade the deployment's SDK.
13
+ - older major than the runtime → **refused**: the connector must be migrated to
14
+ the current major using the guide below.
15
+ - This protects deployments: an admin who approved Connector X v1 can trust that
16
+ a v1.x auto-upgrade won't change what the connector can do, and that a v2
17
+ upgrade is flagged as requiring fresh review.
18
+
19
+ ## What forces a major bump
20
+
21
+ A change is **major** (and requires a migration guide entry) if it breaks any of:
22
+
23
+ - the base `Connector` class surface (method names/signatures developers override),
24
+ - the `@resource` / `@action` decorator contracts,
25
+ - the provenance envelope fields,
26
+ - the manifest schema,
27
+ - the emitted MCP shape that the gateway depends on (e.g. `dq.*` metadata keys,
28
+ the control-tool protocol).
29
+
30
+ Adding a capability or an optional field is **minor**; fixing behavior without
31
+ changing any interface is a **patch**.
32
+
33
+ ## The process for shipping a major version
34
+
35
+ 1. Land the breaking change behind a new `SDK_MAJOR_VERSION`.
36
+ 2. Add a `## v(N-1) → vN` section below with concrete before/after steps.
37
+ 3. Add a `CHANGELOG.md` entry referencing this guide.
38
+ 4. Where feasible, ship a deprecation period: support both shapes for one minor
39
+ release with a runtime warning before removing the old one.
40
+
41
+ ---
42
+
43
+ ## v1 → v2
44
+
45
+ _No v2 yet._ When the first breaking change lands, this section will list each
46
+ change with a before/after example and the minimum edits a connector author must
47
+ make to retarget `sdk_major_version = 2`.
@@ -0,0 +1,195 @@
1
+ Metadata-Version: 2.4
2
+ Name: deepquery-sdk
3
+ Version: 1.0.0
4
+ Summary: Connector Development Kit for Deep Query — build MCP-emitting connectors with built-in read/action safety classification and provenance.
5
+ Project-URL: Homepage, https://github.com/GilbertAshivaka/deepquery-sdk
6
+ Project-URL: Repository, https://github.com/GilbertAshivaka/deepquery-sdk
7
+ Project-URL: Changelog, https://github.com/GilbertAshivaka/deepquery-sdk/blob/main/CHANGELOG.md
8
+ Project-URL: Documentation, https://github.com/GilbertAshivaka/deepquery-sdk/blob/main/README.md
9
+ Author-email: Gilbert Ashivaka <gilbertashivaka@gmail.com>
10
+ License: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: connector,deepquery,mcp,model-context-protocol,rag
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
22
+ Requires-Python: >=3.10
23
+ Requires-Dist: mcp<2,>=1.10
24
+ Requires-Dist: pydantic<3,>=2
25
+ Provides-Extra: dev
26
+ Requires-Dist: build>=1.2; extra == 'dev'
27
+ Requires-Dist: pytest-asyncio>=0.25; extra == 'dev'
28
+ Requires-Dist: pytest>=8; extra == 'dev'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # DeepQuerySDK — Connector Development Kit
32
+
33
+ Build connectors for Deep Query. A connector you write with this SDK **emits a
34
+ standard [Model Context Protocol](https://modelcontextprotocol.io) (MCP) server**
35
+ — so Deep Query consumes it through the exact same interface as any public MCP
36
+ server. You never touch JSON-RPC, transport, or schema plumbing.
37
+
38
+ > **Status: v1.0.0 — all four build phases complete.** Core contracts (Phase 1),
39
+ > the gated **preview → approve → execute / reject** lifecycle + OAuth 2.1 PKCE
40
+ > scaffolding + credential injection (Phase 2), the `deepquery` **CLI** and
41
+ > **mock-agent harness** with the §5/§6/§13 contracts encoded as `validate`
42
+ > checks (Phase 3), and the semver **compatibility contract** + packaging
43
+ > (Phase 4). The SDK contract is at **major version 1**: connectors declaring
44
+ > `sdk_major_version = 1` are loadable by this runtime.
45
+
46
+ ## What you define
47
+
48
+ A connector is a subclass of `Connector` that declares three things:
49
+
50
+ | You define | What it is | Gated? |
51
+ |---|---|---|
52
+ | **Resources** | read-only data the agent can retrieve and **cite** | no |
53
+ | **Actions** | operations that change external state | yes (preview → execute) |
54
+ | **Auth** | how the connector authenticates to the external system | n/a |
55
+
56
+ Every read carries a **provenance envelope** so live data can be cited honestly.
57
+ Every action is tagged `dq.mutates: true` in the emitted MCP server so Deep
58
+ Query's approval gate knows it must be confirmed by a human.
59
+
60
+ ## Install (development)
61
+
62
+ ```powershell
63
+ # from the DeepQuerySDK/ folder, using the bundled venv
64
+ venv\Scripts\python.exe -m pip install -e .
65
+ ```
66
+
67
+ ## 60-second example
68
+
69
+ ```python
70
+ from deepquery_sdk import Connector, OAuth2Auth, resource, action
71
+
72
+ class JiraConnector(Connector):
73
+ name = "jira"
74
+ version = "0.1.0"
75
+ description = "Read and act on Jira issues."
76
+
77
+ # Declare OAuth 2.1 with least-privilege scopes. The gateway runs/stores the
78
+ # grant and injects the token; this connector never stores credentials.
79
+ auth = OAuth2Auth(
80
+ authorize_endpoint="https://auth.atlassian.com/authorize",
81
+ token_endpoint="https://auth.atlassian.com/oauth/token",
82
+ scopes=["read:jira-work", "write:jira-work"],
83
+ )
84
+ requires_network = True
85
+
86
+ @resource(description="Search Jira issues by text query.",
87
+ input_schema={"type": "object",
88
+ "properties": {"query": {"type": "string"}},
89
+ "required": ["query"]})
90
+ def search_issues(self, query: str):
91
+ # ... call the real Jira API here ...
92
+ return [
93
+ self.cite(
94
+ {"key": "DQ-431", "summary": "Login flow broken", "status": "In Review"},
95
+ source_object_id="DQ-431",
96
+ title_or_label="DQ-431 — Login flow broken",
97
+ deep_link="https://example.atlassian.net/browse/DQ-431",
98
+ mutability_note="live status field",
99
+ )
100
+ ]
101
+
102
+ @action(description="Create a new Jira issue.",
103
+ input_schema={"type": "object",
104
+ "properties": {"project": {"type": "string"},
105
+ "summary": {"type": "string"}},
106
+ "required": ["project", "summary"]})
107
+ def create_issue(self, project: str, summary: str):
108
+ # only ever called after the approval gate confirms the preview.
109
+ auth = self.apply_auth() # headers built from the injected credential
110
+ return {"created": f"{project}-NEW", "summary": summary}
111
+
112
+ @create_issue.preview
113
+ def _(self, project: str, summary: str) -> str:
114
+ return f"Will create a new issue in project '{project}' titled '{summary}'."
115
+ ```
116
+
117
+ Emit and serve it as an MCP server (the gateway injects the credential):
118
+
119
+ ```python
120
+ from deepquery_sdk import Credential, static_credential_provider
121
+ from deepquery_sdk.mcp_emit import run_stdio
122
+
123
+ connector = JiraConnector()
124
+ connector.set_credential_provider(static_credential_provider(Credential(token="...")))
125
+ run_stdio(connector)
126
+ ```
127
+
128
+ ## The gated action lifecycle
129
+
130
+ Calling an action does **not** execute it. It returns a preview and a single-use
131
+ approval token; the gateway drives the decision through two control tools:
132
+
133
+ ```
134
+ call create_issue(args) -> { status: "preview", approval_token, preview, arguments }
135
+ call dq.execute_action(token) -> runs execute() for exactly those args (after human approval)
136
+ call dq.reject_action(token) -> discards the action; it never runs
137
+ ```
138
+
139
+ The token binds the previewed arguments, so execute can never drift from what the
140
+ human approved, and a rejected/used token can never run.
141
+
142
+ ## The `deepquery` CLI
143
+
144
+ ```bash
145
+ deepquery scaffold acme-crm # generate a new connector from the template
146
+ deepquery validate connector.py # enforce the §5/§6/§13 safety contracts
147
+ deepquery manifest connector.py # print/export the connector manifest
148
+ deepquery run-dev connector.py # drive it interactively with the mock agent
149
+ deepquery emit connector.py --out dist/ # produce the deployable MCP server artifact
150
+ ```
151
+
152
+ A target can be a `path/to/connector.py`, a directory containing `connector.py`,
153
+ or a `module.path:ClassName`. `validate` is the gatekeeper: it statically scans
154
+ `@resource` bodies for mutating calls and **fails a resource that writes** (a
155
+ misclassified action), plus checks descriptions, manifest, deployment honesty,
156
+ and least-privilege scopes.
157
+
158
+ The dev harness (`deepquery_sdk.harness.MockAgent`) discovers a connector over a
159
+ real in-memory MCP session and drives reads (inspecting provenance) and the full
160
+ preview → approve / reject action flow — the same sequence the real Agent Layer
161
+ uses.
162
+
163
+ ## Try it without the test suite
164
+
165
+ ```powershell
166
+ # read path + classification + provenance, over a real stdio MCP server
167
+ venv\Scripts\python.exe examples\manual_client.py
168
+
169
+ # the full preview -> approve -> execute and preview -> reject flow
170
+ venv\Scripts\python.exe examples\manual_action_flow.py
171
+ ```
172
+
173
+ See [`examples/jira_connector/`](examples/jira_connector/) for the full runnable
174
+ connector used in the Phase 1 and Phase 2 tests.
175
+
176
+ ## Versioning & compatibility
177
+
178
+ The SDK follows [SemVer](https://semver.org); see [CHANGELOG.md](CHANGELOG.md).
179
+ Every connector manifest declares the SDK **major** version it targets, and the
180
+ gateway calls `assert_compatible(manifest)` before loading — refusing a connector
181
+ built against an incompatible major with a clear error. Breaking changes ship
182
+ with a guide in [MIGRATIONS.md](MIGRATIONS.md).
183
+
184
+ ## Release / publishing (maintainers)
185
+
186
+ Distributions are built with `python -m build` into `dist/`. To publish to PyPI:
187
+
188
+ ```bash
189
+ python -m build # build sdist + wheel into dist/
190
+ python -m twine check dist/* # validate metadata
191
+ python -m twine upload dist/* # publish (requires PyPI credentials)
192
+ ```
193
+
194
+ Tag the release `v<version>` and ensure `version` in `pyproject.toml` matches
195
+ `SDK_VERSION` (a test enforces this against the installed package).
@@ -0,0 +1,165 @@
1
+ # DeepQuerySDK — Connector Development Kit
2
+
3
+ Build connectors for Deep Query. A connector you write with this SDK **emits a
4
+ standard [Model Context Protocol](https://modelcontextprotocol.io) (MCP) server**
5
+ — so Deep Query consumes it through the exact same interface as any public MCP
6
+ server. You never touch JSON-RPC, transport, or schema plumbing.
7
+
8
+ > **Status: v1.0.0 — all four build phases complete.** Core contracts (Phase 1),
9
+ > the gated **preview → approve → execute / reject** lifecycle + OAuth 2.1 PKCE
10
+ > scaffolding + credential injection (Phase 2), the `deepquery` **CLI** and
11
+ > **mock-agent harness** with the §5/§6/§13 contracts encoded as `validate`
12
+ > checks (Phase 3), and the semver **compatibility contract** + packaging
13
+ > (Phase 4). The SDK contract is at **major version 1**: connectors declaring
14
+ > `sdk_major_version = 1` are loadable by this runtime.
15
+
16
+ ## What you define
17
+
18
+ A connector is a subclass of `Connector` that declares three things:
19
+
20
+ | You define | What it is | Gated? |
21
+ |---|---|---|
22
+ | **Resources** | read-only data the agent can retrieve and **cite** | no |
23
+ | **Actions** | operations that change external state | yes (preview → execute) |
24
+ | **Auth** | how the connector authenticates to the external system | n/a |
25
+
26
+ Every read carries a **provenance envelope** so live data can be cited honestly.
27
+ Every action is tagged `dq.mutates: true` in the emitted MCP server so Deep
28
+ Query's approval gate knows it must be confirmed by a human.
29
+
30
+ ## Install (development)
31
+
32
+ ```powershell
33
+ # from the DeepQuerySDK/ folder, using the bundled venv
34
+ venv\Scripts\python.exe -m pip install -e .
35
+ ```
36
+
37
+ ## 60-second example
38
+
39
+ ```python
40
+ from deepquery_sdk import Connector, OAuth2Auth, resource, action
41
+
42
+ class JiraConnector(Connector):
43
+ name = "jira"
44
+ version = "0.1.0"
45
+ description = "Read and act on Jira issues."
46
+
47
+ # Declare OAuth 2.1 with least-privilege scopes. The gateway runs/stores the
48
+ # grant and injects the token; this connector never stores credentials.
49
+ auth = OAuth2Auth(
50
+ authorize_endpoint="https://auth.atlassian.com/authorize",
51
+ token_endpoint="https://auth.atlassian.com/oauth/token",
52
+ scopes=["read:jira-work", "write:jira-work"],
53
+ )
54
+ requires_network = True
55
+
56
+ @resource(description="Search Jira issues by text query.",
57
+ input_schema={"type": "object",
58
+ "properties": {"query": {"type": "string"}},
59
+ "required": ["query"]})
60
+ def search_issues(self, query: str):
61
+ # ... call the real Jira API here ...
62
+ return [
63
+ self.cite(
64
+ {"key": "DQ-431", "summary": "Login flow broken", "status": "In Review"},
65
+ source_object_id="DQ-431",
66
+ title_or_label="DQ-431 — Login flow broken",
67
+ deep_link="https://example.atlassian.net/browse/DQ-431",
68
+ mutability_note="live status field",
69
+ )
70
+ ]
71
+
72
+ @action(description="Create a new Jira issue.",
73
+ input_schema={"type": "object",
74
+ "properties": {"project": {"type": "string"},
75
+ "summary": {"type": "string"}},
76
+ "required": ["project", "summary"]})
77
+ def create_issue(self, project: str, summary: str):
78
+ # only ever called after the approval gate confirms the preview.
79
+ auth = self.apply_auth() # headers built from the injected credential
80
+ return {"created": f"{project}-NEW", "summary": summary}
81
+
82
+ @create_issue.preview
83
+ def _(self, project: str, summary: str) -> str:
84
+ return f"Will create a new issue in project '{project}' titled '{summary}'."
85
+ ```
86
+
87
+ Emit and serve it as an MCP server (the gateway injects the credential):
88
+
89
+ ```python
90
+ from deepquery_sdk import Credential, static_credential_provider
91
+ from deepquery_sdk.mcp_emit import run_stdio
92
+
93
+ connector = JiraConnector()
94
+ connector.set_credential_provider(static_credential_provider(Credential(token="...")))
95
+ run_stdio(connector)
96
+ ```
97
+
98
+ ## The gated action lifecycle
99
+
100
+ Calling an action does **not** execute it. It returns a preview and a single-use
101
+ approval token; the gateway drives the decision through two control tools:
102
+
103
+ ```
104
+ call create_issue(args) -> { status: "preview", approval_token, preview, arguments }
105
+ call dq.execute_action(token) -> runs execute() for exactly those args (after human approval)
106
+ call dq.reject_action(token) -> discards the action; it never runs
107
+ ```
108
+
109
+ The token binds the previewed arguments, so execute can never drift from what the
110
+ human approved, and a rejected/used token can never run.
111
+
112
+ ## The `deepquery` CLI
113
+
114
+ ```bash
115
+ deepquery scaffold acme-crm # generate a new connector from the template
116
+ deepquery validate connector.py # enforce the §5/§6/§13 safety contracts
117
+ deepquery manifest connector.py # print/export the connector manifest
118
+ deepquery run-dev connector.py # drive it interactively with the mock agent
119
+ deepquery emit connector.py --out dist/ # produce the deployable MCP server artifact
120
+ ```
121
+
122
+ A target can be a `path/to/connector.py`, a directory containing `connector.py`,
123
+ or a `module.path:ClassName`. `validate` is the gatekeeper: it statically scans
124
+ `@resource` bodies for mutating calls and **fails a resource that writes** (a
125
+ misclassified action), plus checks descriptions, manifest, deployment honesty,
126
+ and least-privilege scopes.
127
+
128
+ The dev harness (`deepquery_sdk.harness.MockAgent`) discovers a connector over a
129
+ real in-memory MCP session and drives reads (inspecting provenance) and the full
130
+ preview → approve / reject action flow — the same sequence the real Agent Layer
131
+ uses.
132
+
133
+ ## Try it without the test suite
134
+
135
+ ```powershell
136
+ # read path + classification + provenance, over a real stdio MCP server
137
+ venv\Scripts\python.exe examples\manual_client.py
138
+
139
+ # the full preview -> approve -> execute and preview -> reject flow
140
+ venv\Scripts\python.exe examples\manual_action_flow.py
141
+ ```
142
+
143
+ See [`examples/jira_connector/`](examples/jira_connector/) for the full runnable
144
+ connector used in the Phase 1 and Phase 2 tests.
145
+
146
+ ## Versioning & compatibility
147
+
148
+ The SDK follows [SemVer](https://semver.org); see [CHANGELOG.md](CHANGELOG.md).
149
+ Every connector manifest declares the SDK **major** version it targets, and the
150
+ gateway calls `assert_compatible(manifest)` before loading — refusing a connector
151
+ built against an incompatible major with a clear error. Breaking changes ship
152
+ with a guide in [MIGRATIONS.md](MIGRATIONS.md).
153
+
154
+ ## Release / publishing (maintainers)
155
+
156
+ Distributions are built with `python -m build` into `dist/`. To publish to PyPI:
157
+
158
+ ```bash
159
+ python -m build # build sdist + wheel into dist/
160
+ python -m twine check dist/* # validate metadata
161
+ python -m twine upload dist/* # publish (requires PyPI credentials)
162
+ ```
163
+
164
+ Tag the release `v<version>` and ensure `version` in `pyproject.toml` matches
165
+ `SDK_VERSION` (a test enforces this against the installed package).