Skip to content

feat(mcp): model-facing resource tools with paginated list/read/templates (RFC-0058) - #385

Open
ykf173 wants to merge 6 commits into
mainfrom
feature/kaifeng.yan/unify_mcp_read_resource
Open

feat(mcp): model-facing resource tools with paginated list/read/templates (RFC-0058)#385
ykf173 wants to merge 6 commits into
mainfrom
feature/kaifeng.yan/unify_mcp_read_resource

Conversation

@ykf173

@ykf173 ykf173 commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Background

PR #372 (RFC-0058) unified MCP server registration for tool and resource access, establishing the McpServerCap registration layer at POOL scope, tool_prefix, ResourceAccess delegation, and title-preferred list_resources(). This PR builds on that foundation to expose the full model-facing resource tool surface to agents.

What This PR Adds

Three model-facing tools in ResourceCapability:

  • list_mcp_resources(server=None, cursor=None, limit=50) — paginated resource listing with host cursors
  • list_mcp_resource_templates(server=None, cursor=None, limit=50) — paginated template listing
  • read_mcp_resource(server, uri) — bounded resource reads with text truncation and binary size limits

Key Design Decisions

  • Server-qualified resource keys: Host catalog entries use escaped server:uri keys (resource_catalog_key()), isolating identical URIs from different MCP providers
  • Title-preferred display names: Per RFC-0058, ResourceEntry.name prefers the server-provided title over raw name; the raw title is also preserved in its own field
  • Per-provider capability negotiation: supports_resources() filters servers that omitted resources in their initialize handshake
  • Fault isolation: One failing server's list_resources() does not discard results from other servers
  • Gated model surface: The three resource tools are gated by resources.enabled in the agent config; the host catalog endpoint is always available

Incremental Value vs #372

PR #372 established the registration infrastructure:

  • McpServerCap as a ResourceAccess provider
  • POOL-scoped registration with tool_prefix and ResourceAccess delegation
  • Title-preferred list_resources() in the experimental catalog endpoint

This PR adds the model-visible tool surface:

  • ResourceCapability implementing McpResourceProvider (paginated, cursor-based)
  • Three tools the agent can call at runtime
  • ResourceSource injection with client_name-scoped resolution
  • ExtensionRegistry integration for MCP resource providers at SESSION scope
  • Capability negotiation and fault isolation in the host catalog

Related RFCs

Commit Structure

  1. feat(resources): paginated MCP resource provider contract — protocols, runtime types, server-qualified resolver
  2. feat(resources): model-facing MCP resource tools in ResourceCapability — three tools, gated by resources.enabled
  3. feat(mcp): paginated resource list/read/templates on McpServerCap — paginated implementation, ResourceEntry with server/title/metadata
  4. feat(mcp): register MCP resource providers in ExtensionRegistry — SESSION-scope registration, independent of resources.enabled
  5. feat(opencode): server-qualified MCP resource catalog and tool discovery — rekeyed catalog, capability negotiation, tool discovery
  6. docs(changelog): add MCP resource integration entry

@Million-mo

Copy link
Copy Markdown
Collaborator

PR 质量问题

  1. 标题「初版提交」无意义 — 不符合 conventional commit 规范,无法从标题判断改动内容,应为 feat(mcp): ... 格式
  2. 描述过于简略 — 仅一句话 + 3 个 bullet,缺少问题背景、设计方案、与现有功能的关系说明
  3. 单 commit 包含 23 个文件 — 无法增量 review
  4. 缺少 RFC / OpenSpec 关联和文档

与已合入 PR #372 的功能重叠

PR #372(RFC-0058: Unified MCP Server Registration)已合入 main,实现了统一的 MCP 资源注册和访问。本 PR 与 #372 在 7 个文件上重叠:

  • capabilities/mcp_server_cap.py
  • agents/native_agent/agent.py
  • delegation/pool.py
  • mcp_server/client.py / manager.py
  • routes/agent_routes.py
  • tests/capabilities/test_mcp_server_cap.py

与 PR #383 的高度重叠

本 PR 与 #383(同来自 kaifeng.yan 的分支)在 18 个文件上完全重叠,疑似同一工作的不同迭代。建议合并为一个 PR。

建议

  1. 明确本 PR 相对于 feat(mcp): unified MCP server registration for tool and resource access (RFC-0058) #372 已合入内容的增量价值是什么
  2. 如果只是 feat(mcp): unified MCP server registration for tool and resource access (RFC-0058) #372 的重复实现,建议关闭
  3. 如果有增量功能,请 rebase 到最新 main,拆分为小 commit,补充标题/描述/文档/RFC

Related: #372 #383

@ykf173
ykf173 force-pushed the feature/kaifeng.yan/unify_mcp_read_resource branch from 86aaeb7 to 62b848b Compare August 21, 2026 02:10
@ykf173 ykf173 changed the title 初版提交 打通外部资源读取能力,输出对应unikb资源读取方案,实现资源的统一渐进式读取 Aug 21, 2026
闫凯峰 added 6 commits August 21, 2026 10:44
Introduce the McpResourceProvider protocol with paginated
list/read/list-templates operations, opaque host cursors, and
structured resource errors, plus runtime JSON value types for
MCP metadata.

Extend resolve_resource_content() with an optional client_name
parameter so host-injected resources resolve against the exact
MCP server that advertised them, and skip servers whose
initialize handshake omitted the resources capability.
Expose three model-facing tools through ResourceCapability:
list_mcp_resources, list_mcp_resource_templates, and
read_mcp_resource. Listings paginate with host cursors, reads
truncate long text and bound binary payloads, and failures are
reported as structured errors the model can act on.

Wire the resource capability into AgentPool and gate it behind
the per-agent resources.enabled config.
Implement the McpResourceProvider contract on McpServerCap so
each connected MCP server serves paginated resource listings,
template listings, and reads. ResourceEntry now carries the
configured server name plus MCP metadata (title, size,
annotations, meta), preserving the title-preferred display name
behavior introduced in RFC-0058.

Extend MCPClient and McpServerManager with the underlying
paginated protocol calls.
Register every connected McpServerCap as an MCP resource
provider in the ExtensionRegistry, independent of the
per-agent resources.enabled gate. The gate controls only the
model-facing tool surface; host catalog enumeration and
ResourceSource injection stay available for protocol servers.

Host catalog enumeration and ResourceSource injection use the
configured server display name, keeping identical URIs from
different providers isolated.
Key the experimental resource catalog by escaped server:uri
instead of synthesized names, preserving the configured server
name per entry, and negotiate resource support per provider so
one failing server no longer discards the rest.

Surface the model-facing resource tools in the OpenCode tool
discovery endpoints behind the resources.enabled gate, and pass
the owning server name through resource resolution so
host-injected reads route to the correct provider.
@ykf173
ykf173 force-pushed the feature/kaifeng.yan/unify_mcp_read_resource branch from 62b848b to 9270f5c Compare August 21, 2026 02:44
@ykf173 ykf173 changed the title 打通外部资源读取能力,输出对应unikb资源读取方案,实现资源的统一渐进式读取 feat(mcp): model-facing resource tools with paginated list/read/templates (RFC-0058) Aug 21, 2026
@ykf173

ykf173 commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator Author

@Million-mo 已按建议修改,逐条回复如下:

1. 标题 → conventional commit

已改为 feat(mcp): model-facing resource tools with paginated list/read/templates (RFC-0058)

2. 描述补充

已在 PR description 中补充了背景、设计方案、与 #372 的增量价值说明、RFC 关联。

3. 拆分 commit

原单 commit 已拆分为 6 个逻辑 conventional commit:

  1. feat(resources): paginated MCP resource provider contract — 协议、运行时类型、server-qualified resolver
  2. feat(resources): model-facing MCP resource tools in ResourceCapability — 三个 model-facing 工具
  3. feat(mcp): paginated resource list/read/templates on McpServerCap — paginated 实现,ResourceEntry 增加 server/title/metadata
  4. feat(mcp): register MCP resource providers in ExtensionRegistry — SESSION scope 注册,独立于 resources.enabled 开关
  5. feat(opencode): server-qualified MCP resource catalog and tool discovery — 重新建 key 的 catalog,capability negotiation
  6. docs(changelog): add MCP resource integration entry

4. RFC / OpenSpec 关联

已关联 RFC-0058,commit message 和 PR description 中均有引用。

5. 增量价值 vs #372

关于 #383:该 PR 已关闭未合入,其工作已通过 #384/#386 合入 main。本 PR 与 #383 的代码重叠属于历史遗留(同一分支的不同迭代),实际功能差异已在 rebase 后消除。目前仅 3 个文件与 #383 有代码交集(mcp_server_cap.py、agent_routes.py、test_mcp_server_cap.py),且已与 #372 的合入内容对齐。

其他修复

  • 修复了原 commit 中因 git stash pop 冲突未解决的 <<<<<<< Updated upstream / >>>>>>> Stashed changes 标记(位于 mcp_server_cap.py 和 agent_routes.py,共 49 个 syntax error)
  • 已通过 ruff lint、ruff format、mypy strict(686 source files)、143 个相关测试
  • 已在 main 基点上(ac1646184,已验证 fetch,无需 rebase)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants