a207-policy
A207 统一身份注入 / 权限矩阵 / 状态路径策略包(Plan A 单一事实源)。
13 个 MCP 统一依赖本包,取代原先散落在 M1/M2/M4/M11/M13 的多份权限副本。
用法
from a207_policy import get_caller, enforce_read, enforce_write, LIS_READ_FULL
def get_labs(patient_id: str) -> dict:
caller = get_caller() # 来自 env A207_CALLER,模型碰不到
enforce_read("a207-lis-mcp") # 确定性拒绝越权(fail-closed)
...
- 身份注入:
A207_CALLER环境变量由部署配置写入,模型无法自证(修复 P0-1)。 - 测试:
from a207_policy import set_caller; set_caller("doctor_assistant")。 - 状态路径:
from a207_policy import resolve_state_path; resolve_state_path("followup_store.json")落到A207_DATA_DIR或系统临时目录,避免只读安装目录崩溃(修复 P1-3)。
| 值 | 对应角色 | 能干什么(举例) |
|---|---|---|
doctor_assistant |
医生助手 | 全量读写、写化验、生成报告 |
parent_assistant |
家长助手 | 只看受限视图(没有原始数值) |
nutritionist |
营养师 | 出食谱、算目标 |
child_companion |
患儿伙伴 | 打卡、科普、简单记录 |
orchestrator |
编排层 | 调度所有服务 |
risk_warning |
风险预警 | 发预警通知 |
魔搭社区添加环境变量如下
| 弹窗字段 | 应该填什么 | 详细说明 |
|---|---|---|
| 变量名 | A207_CALLER |
(必填) 必须与 Python 代码中 os.environ.get('A207_CALLER') 的键名完全一致 |
| 描述 | 调用方身份标识 |
写给人类看的备注信息,方便你自己或别人理解这个变量是干嘛的 |
| 详细指引 | (可留空) |
如果有特殊格式要求可以写提示,没有就留空 |
| 是否必填 | 建议开启(拨到必填) | 如果缺少这个变量 Python 代码会报错退出,就开启必填 |
| 类型 | string |
保持默认的 string 即可 |
| 测试值 | parent_assistant |
(最关键!) 魔搭容器运行时真正注入的值,直接填你的实际业务值 |
| 弹窗字段 | 应该填什么 | 详细说明 |
|---|---|---|
| 变量名 | A207_DATA_DIR |
(必填) 必须与 Python 代码中 os.environ.get('A207_DATA_DIR') 的键名完全一致 |
| 描述 | 数据存储路径 |
写给人类看的备注信息,方便你自己或别人理解这个变量是干嘛的 |
| 详细指引 | (可留空) |
如果有特殊格式要求可以写提示,没有就留空 |
| 是否必填 | 建议开启(拨到必填) | 如果缺少这个变量 Python 代码会报错退出,就开启必填 |
| 类型 | string |
保持默认的 string 即可 |
| 测试值 | /data/a207 |
(最关键!) 魔搭容器运行时真正注入的值,直接填你的实际业务值 |
但是在云函数条件下,大概率是没有权限写/data目录的,可以改为/tmp/a207
Metadata
Release files for a207-policy 0.3.46
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| a207_policy-0.3.46.tar.gz | 55.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| a207_policy-0.3.46-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 100.5 kB
Release files / a207_policy-0.3.46.tar.gz
| Download URL | a207_policy-0.3.46.tar.gz |
|---|---|
| Size | 55.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4f7d79a29d54cb49e9633960a21574e38fef06311e8e89a84585bcb774d08463
|
|
BLAKE2b-256 checksum How to use checksums |
a725cd0591c50923d3b74808b3194786db4ca40cd64f7404371c49661c4446d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 21, 2026.
Transparency logRelease files / a207_policy-0.3.46-py3-none-any.whl
| Download URL | a207_policy-0.3.46-py3-none-any.whl |
|---|---|
| Size | 44.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
302679040df216c086ec42b945f853505887507a4735c12f15a892574eb08b52
|
|
BLAKE2b-256 checksum How to use checksums |
c3195528555c9b1d8a2b594372ae19239c2d16fe0cf9b504d3a869013bac6336
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 21, 2026.
Transparency log