tba-capability-mcp-authorization 0.4.0.dev1__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.
- tba_capability_mcp_authorization-0.4.0.dev1/LICENSE +201 -0
- tba_capability_mcp_authorization-0.4.0.dev1/NOTICE +10 -0
- tba_capability_mcp_authorization-0.4.0.dev1/PKG-INFO +360 -0
- tba_capability_mcp_authorization-0.4.0.dev1/README.md +327 -0
- tba_capability_mcp_authorization-0.4.0.dev1/pyproject.toml +96 -0
- tba_capability_mcp_authorization-0.4.0.dev1/src/tba_capability_mcp_authorization/__init__.py +25 -0
- tba_capability_mcp_authorization-0.4.0.dev1/src/tba_capability_mcp_authorization/capability.py +191 -0
- tba_capability_mcp_authorization-0.4.0.dev1/src/tba_capability_mcp_authorization/py.typed +0 -0
|
@@ -0,0 +1,201 @@
|
|
|
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
|
|
95
|
+
Derivative 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,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative 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, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Tigrbl Auth (TBA)
|
|
2
|
+
|
|
3
|
+
Project: https://github.com/tigrbl/tigrbl_auth
|
|
4
|
+
Attribution: Jacob Stewart and the Tigrbl Auth contributors.
|
|
5
|
+
|
|
6
|
+
Distributed under the Apache License, Version 2.0.
|
|
7
|
+
See the accompanying LICENSE file for the license terms.
|
|
8
|
+
|
|
9
|
+
Distribution: tba-capability-mcp-authorization
|
|
10
|
+
Source: https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/040-capabilities/tba-capability-mcp-authorization
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tba-capability-mcp-authorization
|
|
3
|
+
Version: 0.4.0.dev1
|
|
4
|
+
Summary: MCP grant resolution, current scope authorization, and owned connection revocation.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
License-File: NOTICE
|
|
8
|
+
Keywords: tigrbl,tba,identity
|
|
9
|
+
Author: Jacob Stewart
|
|
10
|
+
Author-email: jacob@swarmauri.com
|
|
11
|
+
Requires-Python: >=3.10,<3.16
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
18
|
+
Classifier: Intended Audience :: Developers
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Development Status :: 3 - Alpha
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Dist: tba-concrete-capability (>=0.4.0.dev2,<=0.4.0.dev3)
|
|
23
|
+
Requires-Dist: tba-concrete-mcp-delegation (==0.4.0.dev1)
|
|
24
|
+
Requires-Dist: tba-contracts-identity (>=0.4.0.dev2,<=0.4.0.dev3)
|
|
25
|
+
Project-URL: Documentation, https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/040-capabilities/tba-capability-mcp-authorization#readme
|
|
26
|
+
Project-URL: Homepage, https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/040-capabilities/tba-capability-mcp-authorization#readme
|
|
27
|
+
Project-URL: Issues, https://github.com/tigrbl/tigrbl_auth/issues
|
|
28
|
+
Project-URL: PyPI, https://pypi.org/project/tba-capability-mcp-authorization/
|
|
29
|
+
Project-URL: Repository, https://github.com/tigrbl/tigrbl_auth
|
|
30
|
+
Project-URL: Source, https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/040-capabilities/tba-capability-mcp-authorization
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# tba-capability-mcp-authorization
|
|
34
|
+
|
|
35
|
+
<!-- readme-standards:begin branding -->
|
|
36
|
+
<p align="center"><a href="https://github.com/tigrbl/tigrbl_auth"><img src="https://raw.githubusercontent.com/tigrbl/tigrbl_auth/master/docs/assets/tba-brand.png" alt="TBA · Tigrbl Auth" width="300"></a></p>
|
|
37
|
+
<p align="center"><strong>tba-capability-mcp-authorization</strong></p>
|
|
38
|
+
<p align="center">MCP grant resolution, current scope authorization, and owned connection revocation.</p>
|
|
39
|
+
<p align="center">
|
|
40
|
+
<a href="https://pypi.org/project/tba-capability-mcp-authorization/"><img alt="pypi: tba-capability-mcp-authorization unpublished" src="https://img.shields.io/static/v1?label=pypi&message=tba-capability-mcp-authorization%20unpublished&labelColor=1E293B&color=92400E"></a>
|
|
41
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/pyproject.toml"><img alt="Source version: 0.4.0.dev1" src="https://img.shields.io/static/v1?label=Source%20version&message=0.4.0.dev1&labelColor=1E293B&color=4338CA"></a>
|
|
42
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/pyproject.toml"><img alt="Python: >=3.10,<3.16" src="https://img.shields.io/static/v1?label=Python&message=%3E%3D3.10%2C%3C3.16&labelColor=1E293B&color=0F766E"></a>
|
|
43
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/pyproject.toml"><img alt="Layer: 040-capabilities" src="https://img.shields.io/static/v1?label=Layer&message=040-capabilities&labelColor=1E293B&color=6D28D9"></a>
|
|
44
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/README.md#lifecycle-and-migration"><img alt="Lifecycle: active" src="https://img.shields.io/static/v1?label=Lifecycle&message=active&labelColor=1E293B&color=166534"></a>
|
|
45
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/LICENSE"><img alt="License: Apache-2.0" src="https://img.shields.io/static/v1?label=License&message=Apache-2.0&labelColor=1E293B&color=86198F"></a>
|
|
46
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/NOTICE"><img alt="Notice: attribution" src="https://img.shields.io/static/v1?label=Notice&message=attribution&labelColor=1E293B&color=86198F"></a>
|
|
47
|
+
</p>
|
|
48
|
+
<p align="center">
|
|
49
|
+
<a href="https://pypi.org/project/tba-capability-mcp-authorization/"><img alt="pypi downloads: tba-capability-mcp-authorization: unpublished" src="https://img.shields.io/static/v1?label=pypi%20downloads&message=tba-capability-mcp-authorization%3A%20unpublished&labelColor=1E293B&color=92400E"></a>
|
|
50
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/README.md"><img alt="README hits: tba-capability-mcp-authorization" src="https://hits.sh/github.com/tigrbl/tigrbl_auth/pkgs/040-capabilities/tba-capability-mcp-authorization/README.md.svg?label=README%20hits&labelColor=1E293B&color=0E7490"></a>
|
|
51
|
+
</p>
|
|
52
|
+
<p align="center">
|
|
53
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/actions/workflows/readme-standards.yml"><img alt="README standards: CI gate" src="https://img.shields.io/static/v1?label=README%20standards&message=CI%20gate&labelColor=1E293B&color=1D4ED8"></a>
|
|
54
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/docs/readme/test_examples.py"><img alt="Tests: example source" src="https://img.shields.io/static/v1?label=Tests&message=example%20source&labelColor=1E293B&color=0F766E"></a>
|
|
55
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/README.md#certification-status"><img alt="Certification: not certified" src="https://img.shields.io/static/v1?label=Certification&message=not%20certified&labelColor=1E293B&color=92400E"></a>
|
|
56
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/tools/readme/POLICY.md"><img alt="Governance: repository policy" src="https://img.shields.io/static/v1?label=Governance&message=repository%20policy&labelColor=1E293B&color=4338CA"></a>
|
|
57
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/actions/workflows/readme-standards.yml"><img alt="Evidence: source and CI" src="https://img.shields.io/static/v1?label=Evidence&message=source%20and%20CI&labelColor=1E293B&color=6D28D9"></a>
|
|
58
|
+
</p>
|
|
59
|
+
<p align="center"><a href="#overview">Overview</a> · <a href="#installation">Installation</a> · <a href="#quick-start">Quick Start</a> · <a href="#usage">Usage</a> · <a href="#public-api-and-import-surfaces">API</a> · <a href="#contributing">Contributing</a> · <a href="#governance">Governance</a> · <a href="#license">License</a></p>
|
|
60
|
+
<!-- readme-standards:end branding -->
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Overview
|
|
65
|
+
|
|
66
|
+
### Summary
|
|
67
|
+
|
|
68
|
+
Resolve current owner and bot permissions for an approved MCP connection.
|
|
69
|
+
|
|
70
|
+
### Why This Package
|
|
71
|
+
|
|
72
|
+
A stored grant records consent. Each request still needs to check the account, acting identity, and resource at the time of use.
|
|
73
|
+
|
|
74
|
+
### When to Use
|
|
75
|
+
|
|
76
|
+
Use it between OAuth validation and the product's MCP resource policy.
|
|
77
|
+
|
|
78
|
+
### Features
|
|
79
|
+
|
|
80
|
+
- Check browser consent against requested and currently held scopes.
|
|
81
|
+
- Resolve a live principal from a grant bound to the client, resource, and tenant.
|
|
82
|
+
- Require a tool's scopes and the application's own resource check.
|
|
83
|
+
- Delegate owned connection revocation to the authoritative store.
|
|
84
|
+
|
|
85
|
+
### Non-Goals
|
|
86
|
+
|
|
87
|
+
OAuth transport, token validation and issuance, transaction management, and application resource policy are provided by the host.
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Getting Started
|
|
92
|
+
|
|
93
|
+
### Prerequisites
|
|
94
|
+
|
|
95
|
+
Python 3.10 or later, an authenticated OAuth integration, and an application grant and identity store.
|
|
96
|
+
|
|
97
|
+
### Installation
|
|
98
|
+
|
|
99
|
+
The package is pre-release. Build from the repository with its pinned dependency sources.
|
|
100
|
+
|
|
101
|
+
#### uv
|
|
102
|
+
|
|
103
|
+
<!-- readme-standards:begin installation.uv -->
|
|
104
|
+
`tba-capability-mcp-authorization` is not declared published. From the source checkout:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
uv pip install .
|
|
108
|
+
```
|
|
109
|
+
<!-- readme-standards:end installation.uv -->
|
|
110
|
+
|
|
111
|
+
#### pip
|
|
112
|
+
|
|
113
|
+
<!-- readme-standards:begin installation.pip -->
|
|
114
|
+
`tba-capability-mcp-authorization` is not declared published. From the source checkout:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
python -m pip install .
|
|
118
|
+
```
|
|
119
|
+
<!-- readme-standards:end installation.pip -->
|
|
120
|
+
|
|
121
|
+
#### Poetry
|
|
122
|
+
|
|
123
|
+
<!-- readme-standards:begin installation.poetry -->
|
|
124
|
+
`tba-capability-mcp-authorization` is not declared published. From a separate Poetry project, replace the path with your checkout:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
poetry add /path/to/tba-capability-mcp-authorization
|
|
128
|
+
```
|
|
129
|
+
<!-- readme-standards:end installation.poetry -->
|
|
130
|
+
|
|
131
|
+
### Quick Start
|
|
132
|
+
|
|
133
|
+
#### Example
|
|
134
|
+
|
|
135
|
+
<!-- readme-standards:begin example.quick-start -->
|
|
136
|
+
Source: [docs/readme/quick_start.py](https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/docs/readme/quick_start.py).
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from tba_capability_mcp_authorization import MCPGrantBinding
|
|
140
|
+
|
|
141
|
+
binding = MCPGrantBinding(
|
|
142
|
+
grant_id="g-123",
|
|
143
|
+
tenant_id="example-tenant",
|
|
144
|
+
client_id="example-client",
|
|
145
|
+
resource="https://example.com/mcp",
|
|
146
|
+
)
|
|
147
|
+
assert binding.tenant_id == "example-tenant"
|
|
148
|
+
```
|
|
149
|
+
<!-- readme-standards:end example.quick-start -->
|
|
150
|
+
|
|
151
|
+
#### Expected Result
|
|
152
|
+
|
|
153
|
+
The binding identifies one grant, client, tenant and MCP resource.
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## Usage
|
|
158
|
+
|
|
159
|
+
### Common Workflows
|
|
160
|
+
|
|
161
|
+
Call `approve` after validating the browser principal and OAuth request. Persist consent and issue authorization codes through the product's transactional callback. Call `resolve` for live scope checks after OAuth validation, and `authorize_tool` to include the product's resource check.
|
|
162
|
+
|
|
163
|
+
<!-- readme-standards:begin example.usage -->
|
|
164
|
+
Source: [docs/readme/usage.py](https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/docs/readme/usage.py).
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
from collections.abc import Callable
|
|
168
|
+
|
|
169
|
+
from tba_capability_mcp_authorization import (
|
|
170
|
+
MCPAuthorizationCapability,
|
|
171
|
+
MCPGrantBinding,
|
|
172
|
+
MCPResourceCheck,
|
|
173
|
+
MCPPrincipal,
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
async def authorize_read(
|
|
178
|
+
capability: MCPAuthorizationCapability,
|
|
179
|
+
verified_binding: MCPGrantBinding,
|
|
180
|
+
verified_token_scopes: frozenset[str],
|
|
181
|
+
can_read_resource: MCPResourceCheck,
|
|
182
|
+
) -> MCPPrincipal | None:
|
|
183
|
+
return await capability.authorize_tool(
|
|
184
|
+
verified_binding,
|
|
185
|
+
verified_token_scopes,
|
|
186
|
+
required_scopes={"journal:read"},
|
|
187
|
+
check_resource=can_read_resource,
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
assert isinstance(authorize_read, Callable)
|
|
192
|
+
```
|
|
193
|
+
<!-- readme-standards:end example.usage -->
|
|
194
|
+
|
|
195
|
+
### Configuration
|
|
196
|
+
|
|
197
|
+
Inject a scoped grant store, a current subject lookup, and an optional clock. Use an absolute Unix timestamp for grant expiry.
|
|
198
|
+
|
|
199
|
+
### Error Handling
|
|
200
|
+
|
|
201
|
+
Invalid consent raises `PermissionError` or `ValueError`. An unavailable grant or failed tool check returns no principal. Infrastructure failures from injected operations propagate to the host.
|
|
202
|
+
|
|
203
|
+
### Best Practices
|
|
204
|
+
|
|
205
|
+
Build the binding from verified OAuth metadata and the expected resource. Use live subject snapshots for each check. Require scoped, atomic revocation and authorization-code redemption at the storage boundary.
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## Package Boundary
|
|
210
|
+
|
|
211
|
+
### What It Owns
|
|
212
|
+
|
|
213
|
+
Grant and subject binding comparison, current scope intersection, tool-scope enforcement, and orchestration of an owned revoke operation.
|
|
214
|
+
|
|
215
|
+
### Public API and Import Surfaces
|
|
216
|
+
|
|
217
|
+
`tba_capability_mcp_authorization` exports `MCPAuthorizationCapability`, `MCPGrantBinding`, `MCPGrant`, `MCPSubject`, `MCPPrincipal`, and adapter types. Use `resolve_mcp_grant` if the host already loads the current grant within its own token transaction.
|
|
218
|
+
|
|
219
|
+
### Entry Points
|
|
220
|
+
|
|
221
|
+
<!-- readme-standards:begin entry-points -->
|
|
222
|
+
This package declares no command-line, GUI, or plugin entry points in its manifest.
|
|
223
|
+
<!-- readme-standards:end entry-points -->
|
|
224
|
+
|
|
225
|
+
### Injected Dependencies
|
|
226
|
+
|
|
227
|
+
`MCPGrantStore` loads a bound grant and revokes it with owner and binding checks inside the write. The subject lookup returns the currently active account or the owner's bot.
|
|
228
|
+
|
|
229
|
+
### Protocol Consumers
|
|
230
|
+
|
|
231
|
+
Use with a server-side MCP OAuth integration. Refresh adapters can use live scope resolution before calling the token rotation operation.
|
|
232
|
+
|
|
233
|
+
### Extensions
|
|
234
|
+
|
|
235
|
+
Use `tba-concrete-mcp-delegation` for the browser consent permission matrix. Product adapters supply tool-specific resource checks and response projection.
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## Operations and Readiness
|
|
240
|
+
|
|
241
|
+
### Operational Requirements
|
|
242
|
+
|
|
243
|
+
OAuth and storage adapters enforce token validity, transactional issuance, current grant state and any product-specific mutation invariants.
|
|
244
|
+
|
|
245
|
+
### Health and Observability
|
|
246
|
+
|
|
247
|
+
The host owns adapter health, token lifecycles, audit events, and transport error responses.
|
|
248
|
+
|
|
249
|
+
### Security and Resource Limits
|
|
250
|
+
|
|
251
|
+
Only trusted callers construct the grant binding. Keep the mutation and its resource check consistent with the host transaction. Validate OAuth before delegating to this package.
|
|
252
|
+
|
|
253
|
+
### Compatibility
|
|
254
|
+
|
|
255
|
+
Scope and identifier strings are opaque to this package. Resource bindings are matched exactly. Adapters retain the product's existing credential and HTTP formats.
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## Verification
|
|
260
|
+
|
|
261
|
+
### Tests
|
|
262
|
+
|
|
263
|
+
The package tests exercise journal and forum scope fixtures, live status changes, grant expiry and scoped revocation. The README examples are runnable.
|
|
264
|
+
|
|
265
|
+
### Certification Status
|
|
266
|
+
|
|
267
|
+
Consumer integration and certification are pending.
|
|
268
|
+
|
|
269
|
+
### Evidence
|
|
270
|
+
|
|
271
|
+
Unit tests verify the capability's decision boundary. Application tests cover routing, token storage and grant transaction guarantees.
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## FAQ
|
|
276
|
+
|
|
277
|
+
### Why
|
|
278
|
+
|
|
279
|
+
Applications share the owner/bot scope intersection and enforce their own article, forum, or other resource rules.
|
|
280
|
+
|
|
281
|
+
### How
|
|
282
|
+
|
|
283
|
+
Pass the verified OAuth grant binding and scopes into the capability and supply the product's resource check before invoking a tool.
|
|
284
|
+
|
|
285
|
+
### When
|
|
286
|
+
|
|
287
|
+
Resolve current authorization at refresh, discovery, and tool invocation.
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Documentation and Related Packages
|
|
292
|
+
|
|
293
|
+
### More Documentation
|
|
294
|
+
|
|
295
|
+
The example files demonstrate grant binding and a tool authorization adapter.
|
|
296
|
+
|
|
297
|
+
### Related Packages
|
|
298
|
+
|
|
299
|
+
`tba-concrete-mcp-delegation`, `tba-durability-delegation`, and `tba-capability-token-issuance`.
|
|
300
|
+
|
|
301
|
+
### Project Links
|
|
302
|
+
|
|
303
|
+
<!-- readme-standards:begin project-links -->
|
|
304
|
+
- [Documentation](https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/040-capabilities/tba-capability-mcp-authorization#readme)
|
|
305
|
+
- [Homepage](https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/040-capabilities/tba-capability-mcp-authorization#readme)
|
|
306
|
+
- [Issues](https://github.com/tigrbl/tigrbl_auth/issues)
|
|
307
|
+
- [PyPI](https://pypi.org/project/tba-capability-mcp-authorization/)
|
|
308
|
+
- [Repository](https://github.com/tigrbl/tigrbl_auth)
|
|
309
|
+
- [Source](https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/040-capabilities/tba-capability-mcp-authorization)
|
|
310
|
+
- [pypi: tba-capability-mcp-authorization](https://pypi.org/project/tba-capability-mcp-authorization/)
|
|
311
|
+
<!-- readme-standards:end project-links -->
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
## Contributing
|
|
316
|
+
|
|
317
|
+
### How to Contribute
|
|
318
|
+
|
|
319
|
+
Add fixtures for shared authorization semantics and verify the relevant application adapters.
|
|
320
|
+
|
|
321
|
+
### Development Setup
|
|
322
|
+
|
|
323
|
+
Use the repository's uv environment and package test suite.
|
|
324
|
+
|
|
325
|
+
### Notes for Maintainers
|
|
326
|
+
|
|
327
|
+
Keep the package free of product-specific roles and resource identifiers.
|
|
328
|
+
|
|
329
|
+
---
|
|
330
|
+
|
|
331
|
+
## Governance
|
|
332
|
+
|
|
333
|
+
### Ownership and Decision Making
|
|
334
|
+
|
|
335
|
+
Tigrbl Auth owns the shared decision boundary. Consumer maintainers own storage adapters and resource policy.
|
|
336
|
+
|
|
337
|
+
### Standards and Policies
|
|
338
|
+
|
|
339
|
+
Use the existing OAuth and delegation contracts when composing an integration.
|
|
340
|
+
|
|
341
|
+
### Lifecycle and Migration
|
|
342
|
+
|
|
343
|
+
Adopt behind the current application routes and storage contracts first.
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## License and Attribution
|
|
348
|
+
|
|
349
|
+
### License
|
|
350
|
+
|
|
351
|
+
<!-- readme-standards:begin license -->
|
|
352
|
+
Licensed under `Apache-2.0`. See [LICENSE](https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/LICENSE).
|
|
353
|
+
<!-- readme-standards:end license -->
|
|
354
|
+
|
|
355
|
+
### Notices
|
|
356
|
+
|
|
357
|
+
<!-- readme-standards:begin notices -->
|
|
358
|
+
See [NOTICE](https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/NOTICE) for attribution.
|
|
359
|
+
<!-- readme-standards:end notices -->
|
|
360
|
+
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
# tba-capability-mcp-authorization
|
|
2
|
+
|
|
3
|
+
<!-- readme-standards:begin branding -->
|
|
4
|
+
<p align="center"><a href="https://github.com/tigrbl/tigrbl_auth"><img src="https://raw.githubusercontent.com/tigrbl/tigrbl_auth/master/docs/assets/tba-brand.png" alt="TBA · Tigrbl Auth" width="300"></a></p>
|
|
5
|
+
<p align="center"><strong>tba-capability-mcp-authorization</strong></p>
|
|
6
|
+
<p align="center">MCP grant resolution, current scope authorization, and owned connection revocation.</p>
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://pypi.org/project/tba-capability-mcp-authorization/"><img alt="pypi: tba-capability-mcp-authorization unpublished" src="https://img.shields.io/static/v1?label=pypi&message=tba-capability-mcp-authorization%20unpublished&labelColor=1E293B&color=92400E"></a>
|
|
9
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/pyproject.toml"><img alt="Source version: 0.4.0.dev1" src="https://img.shields.io/static/v1?label=Source%20version&message=0.4.0.dev1&labelColor=1E293B&color=4338CA"></a>
|
|
10
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/pyproject.toml"><img alt="Python: >=3.10,<3.16" src="https://img.shields.io/static/v1?label=Python&message=%3E%3D3.10%2C%3C3.16&labelColor=1E293B&color=0F766E"></a>
|
|
11
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/pyproject.toml"><img alt="Layer: 040-capabilities" src="https://img.shields.io/static/v1?label=Layer&message=040-capabilities&labelColor=1E293B&color=6D28D9"></a>
|
|
12
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/README.md#lifecycle-and-migration"><img alt="Lifecycle: active" src="https://img.shields.io/static/v1?label=Lifecycle&message=active&labelColor=1E293B&color=166534"></a>
|
|
13
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/LICENSE"><img alt="License: Apache-2.0" src="https://img.shields.io/static/v1?label=License&message=Apache-2.0&labelColor=1E293B&color=86198F"></a>
|
|
14
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/NOTICE"><img alt="Notice: attribution" src="https://img.shields.io/static/v1?label=Notice&message=attribution&labelColor=1E293B&color=86198F"></a>
|
|
15
|
+
</p>
|
|
16
|
+
<p align="center">
|
|
17
|
+
<a href="https://pypi.org/project/tba-capability-mcp-authorization/"><img alt="pypi downloads: tba-capability-mcp-authorization: unpublished" src="https://img.shields.io/static/v1?label=pypi%20downloads&message=tba-capability-mcp-authorization%3A%20unpublished&labelColor=1E293B&color=92400E"></a>
|
|
18
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/README.md"><img alt="README hits: tba-capability-mcp-authorization" src="https://hits.sh/github.com/tigrbl/tigrbl_auth/pkgs/040-capabilities/tba-capability-mcp-authorization/README.md.svg?label=README%20hits&labelColor=1E293B&color=0E7490"></a>
|
|
19
|
+
</p>
|
|
20
|
+
<p align="center">
|
|
21
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/actions/workflows/readme-standards.yml"><img alt="README standards: CI gate" src="https://img.shields.io/static/v1?label=README%20standards&message=CI%20gate&labelColor=1E293B&color=1D4ED8"></a>
|
|
22
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/docs/readme/test_examples.py"><img alt="Tests: example source" src="https://img.shields.io/static/v1?label=Tests&message=example%20source&labelColor=1E293B&color=0F766E"></a>
|
|
23
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/README.md#certification-status"><img alt="Certification: not certified" src="https://img.shields.io/static/v1?label=Certification&message=not%20certified&labelColor=1E293B&color=92400E"></a>
|
|
24
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/tools/readme/POLICY.md"><img alt="Governance: repository policy" src="https://img.shields.io/static/v1?label=Governance&message=repository%20policy&labelColor=1E293B&color=4338CA"></a>
|
|
25
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/actions/workflows/readme-standards.yml"><img alt="Evidence: source and CI" src="https://img.shields.io/static/v1?label=Evidence&message=source%20and%20CI&labelColor=1E293B&color=6D28D9"></a>
|
|
26
|
+
</p>
|
|
27
|
+
<p align="center"><a href="#overview">Overview</a> · <a href="#installation">Installation</a> · <a href="#quick-start">Quick Start</a> · <a href="#usage">Usage</a> · <a href="#public-api-and-import-surfaces">API</a> · <a href="#contributing">Contributing</a> · <a href="#governance">Governance</a> · <a href="#license">License</a></p>
|
|
28
|
+
<!-- readme-standards:end branding -->
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Overview
|
|
33
|
+
|
|
34
|
+
### Summary
|
|
35
|
+
|
|
36
|
+
Resolve current owner and bot permissions for an approved MCP connection.
|
|
37
|
+
|
|
38
|
+
### Why This Package
|
|
39
|
+
|
|
40
|
+
A stored grant records consent. Each request still needs to check the account, acting identity, and resource at the time of use.
|
|
41
|
+
|
|
42
|
+
### When to Use
|
|
43
|
+
|
|
44
|
+
Use it between OAuth validation and the product's MCP resource policy.
|
|
45
|
+
|
|
46
|
+
### Features
|
|
47
|
+
|
|
48
|
+
- Check browser consent against requested and currently held scopes.
|
|
49
|
+
- Resolve a live principal from a grant bound to the client, resource, and tenant.
|
|
50
|
+
- Require a tool's scopes and the application's own resource check.
|
|
51
|
+
- Delegate owned connection revocation to the authoritative store.
|
|
52
|
+
|
|
53
|
+
### Non-Goals
|
|
54
|
+
|
|
55
|
+
OAuth transport, token validation and issuance, transaction management, and application resource policy are provided by the host.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Getting Started
|
|
60
|
+
|
|
61
|
+
### Prerequisites
|
|
62
|
+
|
|
63
|
+
Python 3.10 or later, an authenticated OAuth integration, and an application grant and identity store.
|
|
64
|
+
|
|
65
|
+
### Installation
|
|
66
|
+
|
|
67
|
+
The package is pre-release. Build from the repository with its pinned dependency sources.
|
|
68
|
+
|
|
69
|
+
#### uv
|
|
70
|
+
|
|
71
|
+
<!-- readme-standards:begin installation.uv -->
|
|
72
|
+
`tba-capability-mcp-authorization` is not declared published. From the source checkout:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
uv pip install .
|
|
76
|
+
```
|
|
77
|
+
<!-- readme-standards:end installation.uv -->
|
|
78
|
+
|
|
79
|
+
#### pip
|
|
80
|
+
|
|
81
|
+
<!-- readme-standards:begin installation.pip -->
|
|
82
|
+
`tba-capability-mcp-authorization` is not declared published. From the source checkout:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
python -m pip install .
|
|
86
|
+
```
|
|
87
|
+
<!-- readme-standards:end installation.pip -->
|
|
88
|
+
|
|
89
|
+
#### Poetry
|
|
90
|
+
|
|
91
|
+
<!-- readme-standards:begin installation.poetry -->
|
|
92
|
+
`tba-capability-mcp-authorization` is not declared published. From a separate Poetry project, replace the path with your checkout:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
poetry add /path/to/tba-capability-mcp-authorization
|
|
96
|
+
```
|
|
97
|
+
<!-- readme-standards:end installation.poetry -->
|
|
98
|
+
|
|
99
|
+
### Quick Start
|
|
100
|
+
|
|
101
|
+
#### Example
|
|
102
|
+
|
|
103
|
+
<!-- readme-standards:begin example.quick-start -->
|
|
104
|
+
Source: [docs/readme/quick_start.py](https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/docs/readme/quick_start.py).
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from tba_capability_mcp_authorization import MCPGrantBinding
|
|
108
|
+
|
|
109
|
+
binding = MCPGrantBinding(
|
|
110
|
+
grant_id="g-123",
|
|
111
|
+
tenant_id="example-tenant",
|
|
112
|
+
client_id="example-client",
|
|
113
|
+
resource="https://example.com/mcp",
|
|
114
|
+
)
|
|
115
|
+
assert binding.tenant_id == "example-tenant"
|
|
116
|
+
```
|
|
117
|
+
<!-- readme-standards:end example.quick-start -->
|
|
118
|
+
|
|
119
|
+
#### Expected Result
|
|
120
|
+
|
|
121
|
+
The binding identifies one grant, client, tenant and MCP resource.
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Usage
|
|
126
|
+
|
|
127
|
+
### Common Workflows
|
|
128
|
+
|
|
129
|
+
Call `approve` after validating the browser principal and OAuth request. Persist consent and issue authorization codes through the product's transactional callback. Call `resolve` for live scope checks after OAuth validation, and `authorize_tool` to include the product's resource check.
|
|
130
|
+
|
|
131
|
+
<!-- readme-standards:begin example.usage -->
|
|
132
|
+
Source: [docs/readme/usage.py](https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/docs/readme/usage.py).
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from collections.abc import Callable
|
|
136
|
+
|
|
137
|
+
from tba_capability_mcp_authorization import (
|
|
138
|
+
MCPAuthorizationCapability,
|
|
139
|
+
MCPGrantBinding,
|
|
140
|
+
MCPResourceCheck,
|
|
141
|
+
MCPPrincipal,
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
async def authorize_read(
|
|
146
|
+
capability: MCPAuthorizationCapability,
|
|
147
|
+
verified_binding: MCPGrantBinding,
|
|
148
|
+
verified_token_scopes: frozenset[str],
|
|
149
|
+
can_read_resource: MCPResourceCheck,
|
|
150
|
+
) -> MCPPrincipal | None:
|
|
151
|
+
return await capability.authorize_tool(
|
|
152
|
+
verified_binding,
|
|
153
|
+
verified_token_scopes,
|
|
154
|
+
required_scopes={"journal:read"},
|
|
155
|
+
check_resource=can_read_resource,
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
assert isinstance(authorize_read, Callable)
|
|
160
|
+
```
|
|
161
|
+
<!-- readme-standards:end example.usage -->
|
|
162
|
+
|
|
163
|
+
### Configuration
|
|
164
|
+
|
|
165
|
+
Inject a scoped grant store, a current subject lookup, and an optional clock. Use an absolute Unix timestamp for grant expiry.
|
|
166
|
+
|
|
167
|
+
### Error Handling
|
|
168
|
+
|
|
169
|
+
Invalid consent raises `PermissionError` or `ValueError`. An unavailable grant or failed tool check returns no principal. Infrastructure failures from injected operations propagate to the host.
|
|
170
|
+
|
|
171
|
+
### Best Practices
|
|
172
|
+
|
|
173
|
+
Build the binding from verified OAuth metadata and the expected resource. Use live subject snapshots for each check. Require scoped, atomic revocation and authorization-code redemption at the storage boundary.
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## Package Boundary
|
|
178
|
+
|
|
179
|
+
### What It Owns
|
|
180
|
+
|
|
181
|
+
Grant and subject binding comparison, current scope intersection, tool-scope enforcement, and orchestration of an owned revoke operation.
|
|
182
|
+
|
|
183
|
+
### Public API and Import Surfaces
|
|
184
|
+
|
|
185
|
+
`tba_capability_mcp_authorization` exports `MCPAuthorizationCapability`, `MCPGrantBinding`, `MCPGrant`, `MCPSubject`, `MCPPrincipal`, and adapter types. Use `resolve_mcp_grant` if the host already loads the current grant within its own token transaction.
|
|
186
|
+
|
|
187
|
+
### Entry Points
|
|
188
|
+
|
|
189
|
+
<!-- readme-standards:begin entry-points -->
|
|
190
|
+
This package declares no command-line, GUI, or plugin entry points in its manifest.
|
|
191
|
+
<!-- readme-standards:end entry-points -->
|
|
192
|
+
|
|
193
|
+
### Injected Dependencies
|
|
194
|
+
|
|
195
|
+
`MCPGrantStore` loads a bound grant and revokes it with owner and binding checks inside the write. The subject lookup returns the currently active account or the owner's bot.
|
|
196
|
+
|
|
197
|
+
### Protocol Consumers
|
|
198
|
+
|
|
199
|
+
Use with a server-side MCP OAuth integration. Refresh adapters can use live scope resolution before calling the token rotation operation.
|
|
200
|
+
|
|
201
|
+
### Extensions
|
|
202
|
+
|
|
203
|
+
Use `tba-concrete-mcp-delegation` for the browser consent permission matrix. Product adapters supply tool-specific resource checks and response projection.
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## Operations and Readiness
|
|
208
|
+
|
|
209
|
+
### Operational Requirements
|
|
210
|
+
|
|
211
|
+
OAuth and storage adapters enforce token validity, transactional issuance, current grant state and any product-specific mutation invariants.
|
|
212
|
+
|
|
213
|
+
### Health and Observability
|
|
214
|
+
|
|
215
|
+
The host owns adapter health, token lifecycles, audit events, and transport error responses.
|
|
216
|
+
|
|
217
|
+
### Security and Resource Limits
|
|
218
|
+
|
|
219
|
+
Only trusted callers construct the grant binding. Keep the mutation and its resource check consistent with the host transaction. Validate OAuth before delegating to this package.
|
|
220
|
+
|
|
221
|
+
### Compatibility
|
|
222
|
+
|
|
223
|
+
Scope and identifier strings are opaque to this package. Resource bindings are matched exactly. Adapters retain the product's existing credential and HTTP formats.
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## Verification
|
|
228
|
+
|
|
229
|
+
### Tests
|
|
230
|
+
|
|
231
|
+
The package tests exercise journal and forum scope fixtures, live status changes, grant expiry and scoped revocation. The README examples are runnable.
|
|
232
|
+
|
|
233
|
+
### Certification Status
|
|
234
|
+
|
|
235
|
+
Consumer integration and certification are pending.
|
|
236
|
+
|
|
237
|
+
### Evidence
|
|
238
|
+
|
|
239
|
+
Unit tests verify the capability's decision boundary. Application tests cover routing, token storage and grant transaction guarantees.
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## FAQ
|
|
244
|
+
|
|
245
|
+
### Why
|
|
246
|
+
|
|
247
|
+
Applications share the owner/bot scope intersection and enforce their own article, forum, or other resource rules.
|
|
248
|
+
|
|
249
|
+
### How
|
|
250
|
+
|
|
251
|
+
Pass the verified OAuth grant binding and scopes into the capability and supply the product's resource check before invoking a tool.
|
|
252
|
+
|
|
253
|
+
### When
|
|
254
|
+
|
|
255
|
+
Resolve current authorization at refresh, discovery, and tool invocation.
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## Documentation and Related Packages
|
|
260
|
+
|
|
261
|
+
### More Documentation
|
|
262
|
+
|
|
263
|
+
The example files demonstrate grant binding and a tool authorization adapter.
|
|
264
|
+
|
|
265
|
+
### Related Packages
|
|
266
|
+
|
|
267
|
+
`tba-concrete-mcp-delegation`, `tba-durability-delegation`, and `tba-capability-token-issuance`.
|
|
268
|
+
|
|
269
|
+
### Project Links
|
|
270
|
+
|
|
271
|
+
<!-- readme-standards:begin project-links -->
|
|
272
|
+
- [Documentation](https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/040-capabilities/tba-capability-mcp-authorization#readme)
|
|
273
|
+
- [Homepage](https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/040-capabilities/tba-capability-mcp-authorization#readme)
|
|
274
|
+
- [Issues](https://github.com/tigrbl/tigrbl_auth/issues)
|
|
275
|
+
- [PyPI](https://pypi.org/project/tba-capability-mcp-authorization/)
|
|
276
|
+
- [Repository](https://github.com/tigrbl/tigrbl_auth)
|
|
277
|
+
- [Source](https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/040-capabilities/tba-capability-mcp-authorization)
|
|
278
|
+
- [pypi: tba-capability-mcp-authorization](https://pypi.org/project/tba-capability-mcp-authorization/)
|
|
279
|
+
<!-- readme-standards:end project-links -->
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## Contributing
|
|
284
|
+
|
|
285
|
+
### How to Contribute
|
|
286
|
+
|
|
287
|
+
Add fixtures for shared authorization semantics and verify the relevant application adapters.
|
|
288
|
+
|
|
289
|
+
### Development Setup
|
|
290
|
+
|
|
291
|
+
Use the repository's uv environment and package test suite.
|
|
292
|
+
|
|
293
|
+
### Notes for Maintainers
|
|
294
|
+
|
|
295
|
+
Keep the package free of product-specific roles and resource identifiers.
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
## Governance
|
|
300
|
+
|
|
301
|
+
### Ownership and Decision Making
|
|
302
|
+
|
|
303
|
+
Tigrbl Auth owns the shared decision boundary. Consumer maintainers own storage adapters and resource policy.
|
|
304
|
+
|
|
305
|
+
### Standards and Policies
|
|
306
|
+
|
|
307
|
+
Use the existing OAuth and delegation contracts when composing an integration.
|
|
308
|
+
|
|
309
|
+
### Lifecycle and Migration
|
|
310
|
+
|
|
311
|
+
Adopt behind the current application routes and storage contracts first.
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
## License and Attribution
|
|
316
|
+
|
|
317
|
+
### License
|
|
318
|
+
|
|
319
|
+
<!-- readme-standards:begin license -->
|
|
320
|
+
Licensed under `Apache-2.0`. See [LICENSE](https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/LICENSE).
|
|
321
|
+
<!-- readme-standards:end license -->
|
|
322
|
+
|
|
323
|
+
### Notices
|
|
324
|
+
|
|
325
|
+
<!-- readme-standards:begin notices -->
|
|
326
|
+
See [NOTICE](https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/NOTICE) for attribution.
|
|
327
|
+
<!-- readme-standards:end notices -->
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "tba-capability-mcp-authorization"
|
|
3
|
+
version = "0.4.0.dev1"
|
|
4
|
+
description = "MCP grant resolution, current scope authorization, and owned connection revocation."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10,<3.16"
|
|
7
|
+
classifiers = [
|
|
8
|
+
"Programming Language :: Python :: 3.10",
|
|
9
|
+
"Programming Language :: Python :: 3.11",
|
|
10
|
+
"Programming Language :: Python :: 3.12",
|
|
11
|
+
"Programming Language :: Python :: 3.13",
|
|
12
|
+
"Programming Language :: Python :: 3.14",
|
|
13
|
+
"Programming Language :: Python :: 3.15",
|
|
14
|
+
"Intended Audience :: Developers",
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Typing :: Typed",
|
|
18
|
+
]
|
|
19
|
+
license = "Apache-2.0"
|
|
20
|
+
dependencies = [
|
|
21
|
+
"tba-concrete-capability>=0.4.0.dev2,<=0.4.0.dev3",
|
|
22
|
+
"tba-contracts-identity>=0.4.0.dev2,<=0.4.0.dev3",
|
|
23
|
+
"tba-concrete-mcp-delegation==0.4.0.dev1",
|
|
24
|
+
]
|
|
25
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
26
|
+
keywords = ["tigrbl", "tba", "identity"]
|
|
27
|
+
|
|
28
|
+
[[project.authors]]
|
|
29
|
+
name = "Jacob Stewart"
|
|
30
|
+
email = "jacob@swarmauri.com"
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/040-capabilities/tba-capability-mcp-authorization#readme"
|
|
34
|
+
Documentation = "https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/040-capabilities/tba-capability-mcp-authorization#readme"
|
|
35
|
+
Repository = "https://github.com/tigrbl/tigrbl_auth"
|
|
36
|
+
Source = "https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/040-capabilities/tba-capability-mcp-authorization"
|
|
37
|
+
Issues = "https://github.com/tigrbl/tigrbl_auth/issues"
|
|
38
|
+
PyPI = "https://pypi.org/project/tba-capability-mcp-authorization/"
|
|
39
|
+
[build-system]
|
|
40
|
+
requires = ["poetry-core>=2.2.0,<3.0.0"]
|
|
41
|
+
build-backend = "poetry.core.masonry.api"
|
|
42
|
+
|
|
43
|
+
[tool.poetry]
|
|
44
|
+
packages = [{ include = "tba_capability_mcp_authorization", from = "src" }]
|
|
45
|
+
|
|
46
|
+
[tool.readme_standards]
|
|
47
|
+
policy = "package-guide-v1"
|
|
48
|
+
readme = "README.md"
|
|
49
|
+
brand = "tigrbl-auth"
|
|
50
|
+
brand_catalog = "../../../tools/readme/brands.toml"
|
|
51
|
+
repository = "https://github.com/tigrbl/tigrbl_auth"
|
|
52
|
+
ref = "master"
|
|
53
|
+
package_path = "pkgs/040-capabilities/tba-capability-mcp-authorization"
|
|
54
|
+
layer = "040-capabilities"
|
|
55
|
+
lifecycle = "active"
|
|
56
|
+
license_file = "LICENSE"
|
|
57
|
+
notice_file = "NOTICE"
|
|
58
|
+
|
|
59
|
+
[tool.readme_standards.distributions.pypi]
|
|
60
|
+
name = "tba-capability-mcp-authorization"
|
|
61
|
+
published = false
|
|
62
|
+
|
|
63
|
+
[tool.readme_standards.examples.quick_start]
|
|
64
|
+
source = "docs/readme/quick_start.py"
|
|
65
|
+
test = "docs/readme/test_examples.py"
|
|
66
|
+
language = "python"
|
|
67
|
+
expected_exit_code = 0
|
|
68
|
+
|
|
69
|
+
[tool.readme_standards.examples.usage]
|
|
70
|
+
source = "docs/readme/usage.py"
|
|
71
|
+
test = "docs/readme/test_examples.py"
|
|
72
|
+
language = "python"
|
|
73
|
+
expected_exit_code = 0
|
|
74
|
+
|
|
75
|
+
[tool.readme_standards.statuses.readme]
|
|
76
|
+
label = "CI gate"
|
|
77
|
+
url = "https://github.com/tigrbl/tigrbl_auth/actions/workflows/readme-standards.yml"
|
|
78
|
+
|
|
79
|
+
[tool.readme_standards.statuses.tests]
|
|
80
|
+
label = "example source"
|
|
81
|
+
url = "https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/docs/readme/test_examples.py"
|
|
82
|
+
|
|
83
|
+
[tool.readme_standards.statuses.certification]
|
|
84
|
+
label = "not certified"
|
|
85
|
+
url = "https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/040-capabilities/tba-capability-mcp-authorization/README.md#certification-status"
|
|
86
|
+
|
|
87
|
+
[tool.readme_standards.statuses.governance]
|
|
88
|
+
label = "repository policy"
|
|
89
|
+
url = "https://github.com/tigrbl/tigrbl_auth/blob/master/tools/readme/POLICY.md"
|
|
90
|
+
|
|
91
|
+
[tool.readme_standards.statuses.evidence]
|
|
92
|
+
label = "source and CI"
|
|
93
|
+
url = "https://github.com/tigrbl/tigrbl_auth/actions/workflows/readme-standards.yml"
|
|
94
|
+
|
|
95
|
+
[dependency-groups]
|
|
96
|
+
dev = ["readme-standards==0.1.3; python_version >= \"3.11\""]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Shared grant authorization for MCP resource servers."""
|
|
2
|
+
|
|
3
|
+
from .capability import (
|
|
4
|
+
MCPAuthorizationCapability,
|
|
5
|
+
MCPGrant,
|
|
6
|
+
MCPGrantBinding,
|
|
7
|
+
MCPGrantStore,
|
|
8
|
+
MCPPrincipal,
|
|
9
|
+
MCPResourceCheck,
|
|
10
|
+
MCPSubject,
|
|
11
|
+
MCPSubjectLookup,
|
|
12
|
+
resolve_mcp_grant,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"MCPAuthorizationCapability",
|
|
17
|
+
"MCPGrant",
|
|
18
|
+
"MCPGrantBinding",
|
|
19
|
+
"MCPGrantStore",
|
|
20
|
+
"MCPPrincipal",
|
|
21
|
+
"MCPResourceCheck",
|
|
22
|
+
"MCPSubject",
|
|
23
|
+
"MCPSubjectLookup",
|
|
24
|
+
"resolve_mcp_grant",
|
|
25
|
+
]
|
tba_capability_mcp_authorization-0.4.0.dev1/src/tba_capability_mcp_authorization/capability.py
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"""Revalidate approved grants and their subjects at each MCP authorization boundary."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
from collections.abc import Awaitable, Callable, Iterable
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from typing import Protocol
|
|
9
|
+
|
|
10
|
+
from tba_concrete_capability import Capability
|
|
11
|
+
from tba_concrete_mcp_delegation import approve_scopes, effective_scopes
|
|
12
|
+
from tba_contracts_identity.capabilities import CapabilityDefinition, CapabilityOperation
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass(frozen=True, slots=True)
|
|
16
|
+
class MCPGrantBinding:
|
|
17
|
+
"""Grant identity taken from validated OAuth state and the expected resource."""
|
|
18
|
+
|
|
19
|
+
grant_id: str
|
|
20
|
+
tenant_id: str
|
|
21
|
+
client_id: str
|
|
22
|
+
resource: str
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass(frozen=True, slots=True)
|
|
26
|
+
class MCPGrant:
|
|
27
|
+
binding: MCPGrantBinding
|
|
28
|
+
owner_id: str
|
|
29
|
+
bot_id: str | None
|
|
30
|
+
scopes: frozenset[str]
|
|
31
|
+
active: bool
|
|
32
|
+
expires_at: float | None = None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass(frozen=True, slots=True)
|
|
36
|
+
class MCPSubject:
|
|
37
|
+
"""Current account or bot returned by the application's authoritative store."""
|
|
38
|
+
|
|
39
|
+
tenant_id: str
|
|
40
|
+
subject_id: str
|
|
41
|
+
scopes: frozenset[str]
|
|
42
|
+
active: bool
|
|
43
|
+
owner_id: str | None = None
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass(frozen=True, slots=True)
|
|
47
|
+
class MCPPrincipal:
|
|
48
|
+
grant: MCPGrant
|
|
49
|
+
owner: MCPSubject
|
|
50
|
+
actor: MCPSubject
|
|
51
|
+
scopes: frozenset[str]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class MCPGrantStore(Protocol):
|
|
55
|
+
"""Adapter over the app's durable grant store or TBA delegation operations."""
|
|
56
|
+
|
|
57
|
+
async def load(self, binding: MCPGrantBinding) -> MCPGrant | None: ...
|
|
58
|
+
|
|
59
|
+
async def revoke(self, binding: MCPGrantBinding, owner_id: str) -> bool:
|
|
60
|
+
"""Revoke the grant with the binding and owner checked in the write."""
|
|
61
|
+
...
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
MCPSubjectLookup = Callable[[str, str], Awaitable[MCPSubject | None]]
|
|
65
|
+
MCPResourceCheck = Callable[[MCPPrincipal], Awaitable[bool]]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
async def _current_subject(
|
|
69
|
+
load_subject: MCPSubjectLookup,
|
|
70
|
+
tenant_id: str,
|
|
71
|
+
subject_id: str,
|
|
72
|
+
owner_id: str | None,
|
|
73
|
+
) -> MCPSubject | None:
|
|
74
|
+
subject = await load_subject(tenant_id, subject_id)
|
|
75
|
+
if (
|
|
76
|
+
subject is None
|
|
77
|
+
or not subject.active
|
|
78
|
+
or subject.tenant_id != tenant_id
|
|
79
|
+
or subject.subject_id != subject_id
|
|
80
|
+
or subject.owner_id != owner_id
|
|
81
|
+
):
|
|
82
|
+
return None
|
|
83
|
+
return subject
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
async def resolve_mcp_grant(
|
|
87
|
+
grant: MCPGrant,
|
|
88
|
+
binding: MCPGrantBinding,
|
|
89
|
+
token_scopes: Iterable[str],
|
|
90
|
+
*,
|
|
91
|
+
load_subject: MCPSubjectLookup,
|
|
92
|
+
clock: Callable[[], float] = time.time,
|
|
93
|
+
) -> MCPPrincipal | None:
|
|
94
|
+
"""Evaluate a current snapshot loaded by an application's own transaction."""
|
|
95
|
+
if grant.binding != binding or not grant.active:
|
|
96
|
+
return None
|
|
97
|
+
if grant.expires_at is not None and not grant.expires_at > clock():
|
|
98
|
+
return None
|
|
99
|
+
owner = await _current_subject(load_subject, binding.tenant_id, grant.owner_id, None)
|
|
100
|
+
if owner is None:
|
|
101
|
+
return None
|
|
102
|
+
actor = owner
|
|
103
|
+
bot_scopes = None
|
|
104
|
+
if grant.bot_id is not None:
|
|
105
|
+
bot = await _current_subject(
|
|
106
|
+
load_subject, binding.tenant_id, grant.bot_id, grant.owner_id
|
|
107
|
+
)
|
|
108
|
+
if bot is None:
|
|
109
|
+
return None
|
|
110
|
+
actor = bot
|
|
111
|
+
bot_scopes = bot.scopes
|
|
112
|
+
scopes = effective_scopes(token_scopes, grant.scopes, owner.scopes, bot_scopes)
|
|
113
|
+
return MCPPrincipal(grant, owner, actor, scopes) if scopes else None
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class MCPAuthorizationCapability(Capability):
|
|
117
|
+
"""Combine validated OAuth state, consent and current app authorization."""
|
|
118
|
+
|
|
119
|
+
def __init__(
|
|
120
|
+
self,
|
|
121
|
+
grants: MCPGrantStore,
|
|
122
|
+
load_subject: MCPSubjectLookup,
|
|
123
|
+
*,
|
|
124
|
+
clock: Callable[[], float] = time.time,
|
|
125
|
+
) -> None:
|
|
126
|
+
self._grants = grants
|
|
127
|
+
self._load_subject = load_subject
|
|
128
|
+
self._clock = clock
|
|
129
|
+
super().__init__(
|
|
130
|
+
CapabilityDefinition("mcp.authorization", "1.0"),
|
|
131
|
+
operations={
|
|
132
|
+
"approve": CapabilityOperation(target=self.approve),
|
|
133
|
+
"resolve": CapabilityOperation(target=self.resolve),
|
|
134
|
+
"authorize_tool": CapabilityOperation(target=self.authorize_tool),
|
|
135
|
+
"revoke": CapabilityOperation(target=self.revoke),
|
|
136
|
+
},
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
async def approve(
|
|
140
|
+
self,
|
|
141
|
+
*,
|
|
142
|
+
tenant_id: str,
|
|
143
|
+
owner_id: str,
|
|
144
|
+
bot_id: str | None,
|
|
145
|
+
selected: Iterable[str],
|
|
146
|
+
requested: Iterable[str],
|
|
147
|
+
) -> frozenset[str]:
|
|
148
|
+
"""Validate browser consent after OAuth and browser identity validation."""
|
|
149
|
+
owner = await _current_subject(self._load_subject, tenant_id, owner_id, None)
|
|
150
|
+
if owner is None:
|
|
151
|
+
raise PermissionError("The authorizing account is unavailable.")
|
|
152
|
+
bot = None
|
|
153
|
+
if bot_id is not None:
|
|
154
|
+
bot = await _current_subject(self._load_subject, tenant_id, bot_id, owner_id)
|
|
155
|
+
if bot is None:
|
|
156
|
+
raise PermissionError("The selected bot is unavailable.")
|
|
157
|
+
return approve_scopes(
|
|
158
|
+
selected,
|
|
159
|
+
requested,
|
|
160
|
+
owner.scopes,
|
|
161
|
+
bot.scopes if bot is not None else None,
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
async def resolve(
|
|
165
|
+
self, binding: MCPGrantBinding, token_scopes: Iterable[str]
|
|
166
|
+
) -> MCPPrincipal | None:
|
|
167
|
+
"""Resolve the acting identity after the token or grant is authenticated."""
|
|
168
|
+
grant = await self._grants.load(binding)
|
|
169
|
+
if grant is None:
|
|
170
|
+
return None
|
|
171
|
+
return await resolve_mcp_grant(
|
|
172
|
+
grant, binding, token_scopes, load_subject=self._load_subject, clock=self._clock
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
async def authorize_tool(
|
|
176
|
+
self,
|
|
177
|
+
binding: MCPGrantBinding,
|
|
178
|
+
token_scopes: Iterable[str],
|
|
179
|
+
*,
|
|
180
|
+
required_scopes: Iterable[str],
|
|
181
|
+
check_resource: MCPResourceCheck,
|
|
182
|
+
) -> MCPPrincipal | None:
|
|
183
|
+
"""Recheck the grant and the app's own resource policy before a tool call."""
|
|
184
|
+
principal = await self.resolve(binding, token_scopes)
|
|
185
|
+
if principal is None or not frozenset(required_scopes) <= principal.scopes:
|
|
186
|
+
return None
|
|
187
|
+
return principal if await check_resource(principal) else None
|
|
188
|
+
|
|
189
|
+
async def revoke(self, binding: MCPGrantBinding, *, owner_id: str) -> bool:
|
|
190
|
+
"""Revoke from an authenticated account's browser connection list."""
|
|
191
|
+
return await self._grants.revoke(binding, owner_id)
|
|
File without changes
|