github / github/copilot-sdk

initializeAndValidate() is a no-op for extension sessions via joinSession()

未关闭
#1,496 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
enhancement
主要语言
Java
星标
10.5k
派生
1.5k
平均合并
1 天 14 小时
30 天内合并 PR
129

描述

## Summary

`session.rpc.tools.initializeAndValidate()` is callable from extensions that join sessions via `joinSession()`, but it behaves as a no-op — returning `{}` instantly without rebuilding the LLM's tool list. This prevents extensions from refreshing the tool list mid-turn after dynamically enabling/disabling MCP servers.

## Expected Behavior

After an extension calls `rpc.mcp.enable({ serverName })` and the MCP server connects (confirmed via `mcp_server_status_changed` event), calling `initializeAndValidate()` should rebuild the LLM's active tool list so that newly available tools are usable in the same turn.

## Actual Behavior

- `initializeAndValidate()` returns `{}` in ~29ms (consistent with the base-class no-op documented in `rpc.ts:9235`: *"Default base-class implementation is a no-op for sessions that don't support tool validation"*)
- Tools only become available via `tools_changed_notice`, which fires exclusively between turns
- Extensions have no mechanism to trigger a mid-turn tool list rebuild

## Diagnostic Evidence

Built a diagnostic tool (`mcp_api_probe`) inside an extension to test the full `rpc.tools` namespace:

```
session.rpc.tools exists: true
.initializeAndValidate: function ← callable but no-op
.getCurrentMetadata: undefined ← not available
.handlePendingToolCall: function
all keys: [handlePendingToolCall, initializeAndValidate]
```

Full enable+verify cycle (mail MCP):
```
[17:08:09.150Z] calling rpc.mcp.enable...
[17:08:11.261Z] rpc.mcp.enable resolved
status events received: 2 — both "connected"
tools_updated events received: 0
[17:08:16.274Z] calling tools.initializeAndValidate()...
[17:08:17.126Z] initializeAndValidate returned: {}
Result: tools NOT visible same-turn
```

Live test results across 3 MCP servers:

| MCP Server | Connected? | Tools Same-Turn? | Appeared Via |
|------------|-----------|-----------------|-------------|
| mail | ✅ | ❌ | tools_changed_notice (next turn) |
| workiq | ✅ | ❌ | tools_changed_notice (~90s) |
| s360-breeze | ✅ | ❌ | tools_changed_notice (~90s) |

## Request

Make `initializeAndValidate()` functional for extension sessions via `joinSession()`, or provide an alternative API (e.g., `session.rpc.tools.rebuild()`) that extensions can call to force a mid-turn tool list rebuild after MCP enable/disable operations.

## Use Case

[Constellation](https://github.com/lowdrag84/constellation) — a Copilot CLI extension that manages MCP server profiles for token optimization (saves 16K-33K tokens/turn by only loading needed MCPs). Everything works except tools require a wasted turn after each load.

Related: Feature request also filed on github/copilot-cli.

## Environment

- Copilot CLI v1.0.56-1
- `@github/copilot-sdk/extension` via `joinSession()`
- OS: Windows 11

贡献指南

打开贡献指南

调研方向

先从 rpc.ts:9235 处的基类实现和注释开始,然后跟踪通过 joinSession() 创建的会话中的 session.rpc.tools.initializeAndValidate。复现 MCP 启用流程,等待 mcp_server_status_changed,并验证活动工具列表是在同一轮中重建的,而不是仅在 tools_changed_notice 之后才重建。

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
api, developer-experience
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。