pi-codemcp 1.1.1 → 1.1.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-codemcp",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Typed, sandboxed Code Mode access to configured MCP servers for Pi",
5
5
  "type": "module",
6
6
  "packageManager": "bun@1.3.10",
@@ -235,6 +235,7 @@ def normalize_mcp_config(
235
235
  mcp_url=url,
236
236
  client_name=oauth_client_name,
237
237
  token_storage=oauth_storage,
238
+ additional_client_metadata={"token_endpoint_auth_method": "none"},
238
239
  )
239
240
  auth_kind = "oauth"
240
241
  elif isinstance(raw_auth, str):
package/src/mcp-client.ts CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  unlinkSync,
9
9
  } from "node:fs";
10
10
  import { createRequire } from "node:module";
11
- import { dirname, join, resolve } from "node:path";
11
+ import { delimiter, dirname, join, resolve } from "node:path";
12
12
  import { fileURLToPath } from "node:url";
13
13
  import { getAgentDir } from "@earendil-works/pi-coding-agent";
14
14
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
@@ -38,12 +38,38 @@ const LONG_RUNNING_TOOLS = new Set<SidecarToolName>([
38
38
  "execute_chain",
39
39
  "revalidate_chain",
40
40
  ]);
41
+ const OAUTH_CAPABLE_TOOLS = new Set<SidecarToolName>([
42
+ "search",
43
+ "inspect",
44
+ "discover",
45
+ ...LONG_RUNNING_TOOLS,
46
+ ]);
47
+ const DEFAULT_TOOL_TIMEOUT_MS = 30_000;
48
+ const OAUTH_CALLBACK_TIMEOUT_SECONDS = 300;
49
+ const TOOL_TIMEOUT_GRACE_MS = 5_000;
50
+
51
+ export function sidecarToolTimeoutMs(
52
+ name: SidecarToolName,
53
+ executionTimeoutSeconds: number,
54
+ ): number {
55
+ if (OAUTH_CAPABLE_TOOLS.has(name)) {
56
+ return (
57
+ Math.max(executionTimeoutSeconds, OAUTH_CALLBACK_TIMEOUT_SECONDS) * 1_000 +
58
+ TOOL_TIMEOUT_GRACE_MS
59
+ );
60
+ }
61
+ if (LONG_RUNNING_TOOLS.has(name)) {
62
+ return executionTimeoutSeconds * 1_000 + TOOL_TIMEOUT_GRACE_MS;
63
+ }
64
+ return DEFAULT_TOOL_TIMEOUT_MS;
65
+ }
41
66
 
42
67
  export interface SidecarClientOptions {
43
68
  packageRoot?: string;
44
69
  agentDir?: string;
45
70
  environment?: Record<string, string>;
46
71
  projectChainsPath?: string;
72
+ workingDirectory?: string;
47
73
  }
48
74
 
49
75
  export class SidecarClient {
@@ -51,6 +77,7 @@ export class SidecarClient {
51
77
  private readonly packageVersion: string;
52
78
  private readonly agentDir: string;
53
79
  private readonly environment: Record<string, string>;
80
+ private readonly workingDirectory: string;
54
81
  private client: Client | undefined;
55
82
  private transport: StdioClientTransport | undefined;
56
83
  private startPromise: Promise<void> | undefined;
@@ -64,10 +91,11 @@ export class SidecarClient {
64
91
  );
65
92
  this.packageVersion = readPackageVersion(this.packageRoot);
66
93
  this.agentDir = resolve(options.agentDir ?? getAgentDir());
94
+ this.workingDirectory = resolve(options.workingDirectory ?? process.cwd());
67
95
  this.projectChainsDirectory = options.projectChainsPath
68
96
  ? resolve(options.projectChainsPath)
69
97
  : undefined;
70
- this.environment = {
98
+ const environment: Record<string, string> = {
71
99
  ...definedProcessEnvironment(),
72
100
  ...(options.environment ?? {}),
73
101
  PI_CODEMCP_AGENT_DIR: this.agentDir,
@@ -76,6 +104,12 @@ export class SidecarClient {
76
104
  : { PI_CODEMCP_PROJECT_CHAINS_DIR: this.projectChainsDirectory }),
77
105
  UV_PROJECT_ENVIRONMENT: join(this.agentDir, "pi-codemcp", "runtime", "venv"),
78
106
  };
107
+ this.environment = {
108
+ ...environment,
109
+ PYTHONPATH: environment.PYTHONPATH
110
+ ? `${this.packageRoot}${delimiter}${environment.PYTHONPATH}`
111
+ : this.packageRoot,
112
+ };
79
113
  if (this.projectChainsDirectory === undefined) {
80
114
  delete this.environment.PI_CODEMCP_PROJECT_CHAINS_DIR;
81
115
  }
@@ -120,9 +154,11 @@ export class SidecarClient {
120
154
  await this.ensureStarted(signal);
121
155
  const client = this.client;
122
156
  if (!client) throw new Error("Sidecar client failed to initialize");
123
- const timeout = LONG_RUNNING_TOOLS.has(name)
124
- ? loadCodeMcpSettings(this.settingsPath).executionTimeoutSeconds * 1_000 + 5_000
125
- : 30_000;
157
+ const needsExecutionTimeout = LONG_RUNNING_TOOLS.has(name) || OAUTH_CAPABLE_TOOLS.has(name);
158
+ const executionTimeoutSeconds = needsExecutionTimeout
159
+ ? loadCodeMcpSettings(this.settingsPath).executionTimeoutSeconds
160
+ : 0;
161
+ const timeout = sidecarToolTimeoutMs(name, executionTimeoutSeconds);
126
162
  const result = await client.callTool({ name, arguments: args }, undefined, {
127
163
  timeout,
128
164
  ...(signal === undefined ? {} : { signal }),
@@ -183,7 +219,7 @@ export class SidecarClient {
183
219
  "run",
184
220
  ...(isTruthy(process.env.PI_OFFLINE) ? ["--offline"] : []),
185
221
  "--project",
186
- "sidecar",
222
+ join(this.packageRoot, "sidecar"),
187
223
  "--frozen",
188
224
  "--no-dev",
189
225
  "-m",
@@ -191,7 +227,7 @@ export class SidecarClient {
191
227
  "serve",
192
228
  "--stdio",
193
229
  ],
194
- cwd: this.packageRoot,
230
+ cwd: this.workingDirectory,
195
231
  env: this.environment,
196
232
  stderr: "pipe",
197
233
  });