Repository navigation
feat(backend): manage global MCP servers through the pi mcp implementation - #417
Conversation
…ation Settings needs MCP status and sign-in, but the built-in MCP extension keeps its state inside its closure. Reuse runMcpCommand and loadMcpConfig (bundled by path, contract-tested against the pinned Pi) instead of writing a Pace MCP client.
There was a problem hiding this comment.
Devin Review found 1 potential issue.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| const exitCode = await runMcpCommand(args, { | ||
| ...commandBase, | ||
| // Passing openUrl also makes `login` non-interactive (no stdin prompt); | ||
| // other subcommands ignore it. | ||
| openUrl: openExternal, | ||
| log: (line) => out.push(line), | ||
| error: (line) => err.push(line), | ||
| }); |
There was a problem hiding this comment.
🟡 OAuth credentials use the wrong directory
When agentDir differs from PI_CODING_AGENT_DIR, runMcpCommand reads and writes OAuth credentials in Pi's default directory. Sessions using agentDir cannot use those credentials, and logout targets the wrong store.
Learn more
The service accepts an explicit agent directory and uses it when loading and updating the global MCP configuration. Pi's CLI command resolves its credential store through getAgentDir(), which reads the process environment instead of the supplied agentDir; the contract test setup sets that environment variable to match the test directory. If the values differ, OAuth login and logout operate on a different mcp-auth.json from the sessions configured for this service.
Example: With agentDir set to /tmp/profile-b and PI_CODING_AGENT_DIR unset, adding a server writes /tmp/profile-b/mcp.json, but logging in saves credentials under ~/.pi/agent. A session using /tmp/profile-b remains unauthenticated.
Recommended fix: Make the Pi CLI credential store use the same agent directory for the duration of each command, without globally changing process.env across concurrent requests. If the CLI cannot accept a credential-store path, use Pi's lower-level credential API or restrict the service contract and explicitly enforce the process agent directory.
Was this helpful? React with 👍 or 👎 to provide feedback.
No linked issue: implements the MCP Settings direction recorded in
.scratch/mcp-settings/PRD.md(resolves.scratch/mcp-extension-ui/HANDOFF.md). Session-level MCP notices are deferred to #416.Summary
workspace/mcp-servers.ts:列表/探测、OAuth 登录登出、启用禁用、exposure、添加(stdio / HTTP)与删除。runMcpCommand、loadMcpConfig、updateMcpServerConfig,与会话里的内置 MCP 扩展共用配置解析、OAuth 判定和mcp-auth.json凭据位置。exports里,按文件路径别名引入并打进安装包(electron.vite.config.ts、vite.config.ts、tsconfig.json),绑定当前固定的 Pi 版本。packages/core/src/mcp-servers.ts,renderer 不依赖 Pi 内部类型。get_mcp_config、probe_mcp_servers、login_mcp_server、logout_mcp_server、set_mcp_server_enabled、set_mcp_server_exposure、add_mcp_server、remove_mcp_server。workspace/open-url.ts)。hasStoredCredentials:用 Pi 自己的McpOAuthCredentialStore查mcp-auth.json(按 URL 为键),UI 据此只在真有凭据时提供 Sign out。mcp.json;项目级.pi/mcp.json和项目信任后续再做。Test plan
mcp.json结构、CLI 参数、list --json输出一变即失败(PI_CODING_AGENT_DIR指向临时目录,不碰真实 home)workspace/fixtures/mcp-test-server.mjs:真实握手探测 stdio 已连接、HTTP 已连接、HTTP 401 → needs-auth(参数指向不存在文件时测试会失败,非空验证)mcp-auth.json时hasStoredCredentials为 true,logout后回到 falseservice.test.ts覆盖 Gateway 方法bun run typecheck/bun run lint/bun run test/bun run build全绿runMcpCommand已打进安装包)