学习目标
Resource 用于把只读数据交给模型作为上下文,与 Tool 的“可执行动作”区分开。
声明资源
@app.list_resources()
async def list_resources():
return [types.Resource(
uri="file:///docs/readme.md",
name="项目说明",
mimeType="text/markdown",
)]设计建议
- 用 URI 表达资源身份,便于客户端缓存与去重。
- 敏感数据应在 Server 侧做权限过滤,不要全量暴露。
练习任务
设计一个把本地某目录下 Markdown 文件列为 Resource 的方案,并说明如何限制可访问范围。