@dyyz1993/pi-coding-agent 0.74.9 → 0.74.10

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.
@@ -34,6 +34,7 @@ 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
36
  import { McpManager } from "./mcp/mcp-manager.js";
37
+ import { createMcpToolDefinition } from "./mcp/tool-converter.js";
37
38
  import { resolveModelAlias } from "./model-resolver.js";
38
39
  import { expandPromptTemplate } from "./prompt-templates.js";
39
40
  import { CURRENT_SESSION_VERSION, getLatestCompactionEntry } from "./session-manager.js";
@@ -119,6 +120,8 @@ export class AgentSession {
119
120
  _modelRegistry;
120
121
  _fileSnapshotManager = null;
121
122
  _mcpManager;
123
+ _mcpToolDefinitions = new Map();
124
+ _noMcp;
122
125
  _tierModels = {};
123
126
  // Tool registry for extension getTools/setTools
124
127
  _toolRegistry = new Map();
@@ -142,6 +145,7 @@ export class AgentSession {
142
145
  this._allowedToolNames = config.allowedToolNames ? new Set(config.allowedToolNames) : undefined;
143
146
  this._baseToolsOverride = config.baseToolsOverride;
144
147
  this._sessionStartEvent = config.sessionStartEvent ?? { type: "session_start", reason: "startup" };
148
+ this._noMcp = config.noMcp ?? false;
145
149
  // Always subscribe to agent events for internal handling
146
150
  // (session persistence, extensions, auto-compaction, retry logic)
147
151
  this._unsubscribeAgent = this.agent.subscribe(this._handleAgentEvent);
@@ -172,6 +176,8 @@ export class AgentSession {
172
176
  }
173
177
  }
174
178
  _initMcpServers() {
179
+ if (this._noMcp)
180
+ return;
175
181
  if (this._mcpManager) {
176
182
  this._mcpManager.dispose().catch(() => { });
177
183
  this._mcpManager = undefined;
@@ -193,6 +199,21 @@ export class AgentSession {
193
199
  description: t.description,
194
200
  })),
195
201
  });
202
+ if (conn.status === "connected" && this._mcpManager) {
203
+ this._mcpToolDefinitions.clear();
204
+ const allTools = this._mcpManager.getAllTools();
205
+ for (const tool of allTools) {
206
+ this._mcpToolDefinitions.set(tool.fullName, createMcpToolDefinition(tool, this._mcpManager));
207
+ }
208
+ this._refreshToolRegistry();
209
+ }
210
+ else if (conn.status === "error" || conn.status === "disconnected") {
211
+ const staleKeys = [...this._mcpToolDefinitions.keys()].filter((key) => key.startsWith(`mcp__${conn.name}__`));
212
+ for (const key of staleKeys) {
213
+ this._mcpToolDefinitions.delete(key);
214
+ }
215
+ this._refreshToolRegistry();
216
+ }
196
217
  },
197
218
  });
198
219
  this._mcpManager.connectAll(servers).catch(() => { });
@@ -1901,12 +1922,19 @@ export class AgentSession {
1901
1922
  const allowedToolNames = this._allowedToolNames;
1902
1923
  const isAllowedTool = (name) => !allowedToolNames || allowedToolNames.has(name);
1903
1924
  const registeredTools = this._extensionRunner.getAllRegisteredTools();
1925
+ const mcpTools = [...this._mcpToolDefinitions.values()]
1926
+ .filter((def) => isAllowedTool(def.name))
1927
+ .map((definition) => ({
1928
+ definition,
1929
+ sourceInfo: createSyntheticSourceInfo(`<mcp:${definition.name}>`, { source: "mcp" }),
1930
+ }));
1904
1931
  const allCustomTools = [
1905
1932
  ...registeredTools,
1906
1933
  ...this._customTools.map((definition) => ({
1907
1934
  definition,
1908
1935
  sourceInfo: createSyntheticSourceInfo(`<sdk:${definition.name}>`, { source: "sdk" }),
1909
1936
  })),
1937
+ ...mcpTools,
1910
1938
  ].filter((tool) => isAllowedTool(tool.definition.name));
1911
1939
  const definitionRegistry = new Map(Array.from(this._baseToolDefinitions.entries())
1912
1940
  .filter(([name]) => isAllowedTool(name))