github / github/copilot-cli

Shared MCP Token Cache Across CLI Sessions

未关闭
#2,780 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
area:authentication area:mcp
主要语言
Shell
星标
11.2k
派生
1.9k
平均合并
14 小时 16 分钟
30 天内合并 PR
6

描述

### Describe the feature or problem you'd like to solve

_No response_

### Proposed solution

# Feature Request: Shared MCP Token Cache Across CLI Sessions

## Problem

Each Copilot CLI terminal/session maintains its own independent MCP connections and token cache. When a token expires:

1. Running `/mcp reload` in **Terminal A** does NOT fix **Terminal B**
2. Each terminal must be individually refreshed
3. Users working with multiple CLI sessions (common for parallel workflows) must reload each one

This is inconsistent with how other developer tools work — `az login`, `gh auth login`, and `docker login` all share credentials across terminal sessions on the same machine.

## Proposed Solution

**Shared token cache**: MCP server OAuth tokens should be stored in a machine-local cache (e.g., OS keychain or a file-based token cache) that all CLI sessions on the same machine can read from.

### Implementation suggestions

- Store MCP OAuth tokens in a shared location:
- **Windows**: Windows Credential Manager or `~/.copilot/mcp-token-cache/`
- **macOS**: Keychain Access
- **Linux**: `libsecret` / `gnome-keyring` or file-based fallback
- When a CLI session needs an MCP token, check the shared cache first
- When any session refreshes a token (via `/mcp reload` or auto-refresh), update the shared cache
- Include a file lock or atomic write mechanism to prevent race conditions
- Optional: a `--no-shared-cache` flag for users who want isolated sessions

### Interaction with auto-refresh (Feature Request #1)

If auto-refresh is implemented, the shared cache becomes even more valuable:

- One session refreshes the token → all sessions benefit immediately
- No "thundering herd" of multiple sessions trying to refresh simultaneously

## Environment

- Copilot CLI on Windows (PowerShell)
- Multiple terminal sessions on the same machine
- MCP servers using Entra ID (Azure AD) OAuth

## Current Workaround

When tokens expire, users must run `/mcp reload` in **every open CLI session** individually. There is no way to refresh once and have all sessions pick up the new token.

### Example prompts or workflows

_No response_

### Additional context

_No response_

贡献指南

打开贡献指南

调研方向

该 issue 未指定文件或测试。首先跟踪 MCP token 的处理流程和 `/mcp reload` 入口点;确定会话当前如何存储和刷新 token。完成标准是:会话能够在 Windows、macOS 和 Linux 之间安全地共享已刷新的 token,防止竞态条件,并考虑所请求的隔离选项。

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

评估

领域
authentication, cli, security
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
冷清
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

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