@dyyz1993/pi-coding-agent 0.74.4 → 0.74.5

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,28 @@ export class AgentSession {
169
171
  this._extensionRunner.setFileSnapshotManager(null);
170
172
  }
171
173
  }
174
+ _initMcpServers() {
175
+ const settings = this.settingsManager.getMergedSettings();
176
+ const servers = settings?.mcp?.servers;
177
+ if (!servers || Object.keys(servers).length === 0)
178
+ return;
179
+ this._mcpManager = new McpManager({
180
+ onConnectionChange: (conn) => {
181
+ this._emit({
182
+ type: "mcp_connection_change",
183
+ name: conn.name,
184
+ status: conn.status,
185
+ error: conn.error,
186
+ tools: conn.tools.map((t) => ({
187
+ originalName: t.originalName,
188
+ fullName: t.fullName,
189
+ description: t.description,
190
+ })),
191
+ });
192
+ },
193
+ });
194
+ this._mcpManager.connectAll(servers).catch(() => { });
195
+ }
172
196
  async _getRequiredRequestAuth(model) {
173
197
  const result = await this._modelRegistry.getApiKeyAndHeaders(model);
174
198
  if (!result.ok) {
@@ -537,6 +561,7 @@ export class AgentSession {
537
561
  */
538
562
  dispose() {
539
563
  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().");
564
+ this._mcpManager?.dispose().catch(() => { });
540
565
  this._disconnectFromAgent();
541
566
  this._eventListeners = [];
542
567
  cleanupSessionResources(this.sessionId);
@@ -1961,6 +1986,7 @@ export class AgentSession {
1961
1986
  activeToolNames: baseActiveToolNames,
1962
1987
  includeAllExtensionTools: options.includeAllExtensionTools,
1963
1988
  });
1989
+ this._initMcpServers();
1964
1990
  }
1965
1991
  async reload() {
1966
1992
  const previousFlagValues = this._extensionRunner.getFlagValues();