github / github/copilot-cli

feat: Support MCP resources/subscribe and notifications/resources/updated

Đang mở
#3,073 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
area:mcp triaged
Ngôn ngữ chính
Shell
Star
11.2k
Fork
1.9k
Merge trung bình
14 giờ 16 phút
Pull request đã merge (30 ngày)
6

Mô tả

### Context

This builds directly on #1803 (`resources/read`) and #1518 (resources & prompts).

Among the remaining MCP primitives, **resource subscriptions** are a particularly
high-impact missing piece for autonomous agent workflows because they allow MCP
servers to notify clients about resource changes without polling.

#1378 suggests that Copilot CLI already has infrastructure for MCP server-push
notifications via `notifications/tools/list_changed`. The same notification
dispatch path seems like the natural place to add resource update handling.

### What's missing

| Protocol message | Direction | Status |
|------------------|-----------|--------|
| `resources/subscribe` | client → server | ❌ not sent |
| `notifications/resources/updated` | server → client | ❌ not handled |
| `resources/unsubscribe` | client → server | ❌ not sent |

### Proposed minimal addition

Once `resources/read` is supported (#1803), Copilot CLI could add support for
resource subscriptions with a small extension to the MCP client layer:

```typescript
// When the agent receives or selects a watchable resource URI,
// subscribe if the server supports resource subscriptions.
if (serverCapabilities?.resources?.subscribe && resourceUri) {
await mcpClient.subscribeResource({ uri: resourceUri });
}

// Handle resource update notifications alongside the existing
// tools/list_changed notification handler.
mcpClient.setNotificationHandler('notifications/resources/updated', async (n) => {
const { uri } = n.params;
const { contents } = await mcpClient.readResource({ uri });

// Surface the updated contents to the agent/session context.
agentContext.injectResourceUpdate(uri, contents);
});
```

This is a straightforward extension: `resources/read` (#1803) is the only
prerequisite for re-reading the updated resource contents.

### Why this matters

Without resource subscriptions, long-running MCP workflows must either poll
resources/tools repeatedly or expose extra status-check tools.

With subscriptions, an MCP server can expose a watch resource, notify the client
when the resource changes, and let the client re-read the resource only when
needed.

Example flow:

1. Server exposes a watch resource such as `copilot-review://watch/{id}`
2. Client reads the resource and sees a pending state
3. Client subscribes with `resources/subscribe`
4. Server sends `notifications/resources/updated` when the state changes
5. Client re-reads the resource and continues without polling
6. Client calls `resources/unsubscribe` when done

### Related issues

* #1803 — Support MCP `resources/read` primitive (prerequisite)
* #1518 — Support MCP resources and prompts (broader tracking issue)
* #1378 — `notifications/tools/list_changed` handling (existing notification infrastructure)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.