@dyyz1993/pi-coding-agent 0.74.4 → 0.74.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,6 +33,7 @@ import { ExtensionRunner, wrapRegisteredTools, } from "./extensions/index.js";
33
33
  import { emitSessionShutdownEvent } from "./extensions/runner.js";
34
34
  import { FileSnapshotManager } from "./file-store/file-snapshot-manager.js";
35
35
  import { InternalGit } from "./file-store/internal-git.js";
36
+ import { McpManager } from "./mcp/mcp-manager.js";
36
37
  import { resolveModelAlias } from "./model-resolver.js";
37
38
  import { expandPromptTemplate } from "./prompt-templates.js";
38
39
  import { CURRENT_SESSION_VERSION, getLatestCompactionEntry } from "./session-manager.js";
@@ -117,6 +118,7 @@ export class AgentSession {
117
118
  // Model registry for API key resolution
118
119
  _modelRegistry;
119
120
  _fileSnapshotManager = null;
121
+ _mcpManager;
120
122
  _tierModels = {};
121
123
  // Tool registry for extension getTools/setTools
122
124
  _toolRegistry = new Map();
@@ -169,6 +171,32 @@ export class AgentSession {
169
171
  this._extensionRunner.setFileSnapshotManager(null);
170
172
  }
171
173
  }
174
+ _initMcpServers() {
175
+ if (this._mcpManager) {
176
+ this._mcpManager.dispose().catch(() => { });
177
+ this._mcpManager = undefined;
178
+ }
179
+ const settings = this.settingsManager.getMergedSettings();
180
+ const servers = settings?.mcp?.servers;
181
+ if (!servers || Object.keys(servers).length === 0)
182
+ return;
183
+ this._mcpManager = new McpManager({
184
+ onConnectionChange: (conn) => {
185
+ this._emit({
186
+ type: "mcp_connection_change",
187
+ name: conn.name,
188
+ status: conn.status,
189
+ error: conn.error,
190
+ tools: conn.tools.map((t) => ({
191
+ originalName: t.originalName,
192
+ fullName: t.fullName,
193
+ description: t.description,
194
+ })),
195
+ });
196
+ },
197
+ });
198
+ this._mcpManager.connectAll(servers).catch(() => { });
199
+ }
172
200
  async _getRequiredRequestAuth(model) {
173
201
  const result = await this._modelRegistry.getApiKeyAndHeaders(model);
174
202
  if (!result.ok) {
@@ -537,6 +565,7 @@ export class AgentSession {
537
565
  */
538
566
  dispose() {
539
567
  this._extensionRunner.invalidate("This extension ctx is stale after session replacement or reload. Do not use a captured pi or command ctx after ctx.newSession(), ctx.fork(), ctx.switchSession(), or ctx.reload(). For newSession, fork, and switchSession, move post-replacement work into withSession and use the ctx passed to withSession. For reload, do not use the old ctx after await ctx.reload().");
568
+ this._mcpManager?.dispose().catch(() => { });
540
569
  this._disconnectFromAgent();
541
570
  this._eventListeners = [];
542
571
  cleanupSessionResources(this.sessionId);
@@ -1961,6 +1990,7 @@ export class AgentSession {
1961
1990
  activeToolNames: baseActiveToolNames,
1962
1991
  includeAllExtensionTools: options.includeAllExtensionTools,
1963
1992
  });
1993
+ this._initMcpServers();
1964
1994
  }
1965
1995
  async reload() {
1966
1996
  const previousFlagValues = this._extensionRunner.getFlagValues();