@posthog/agent 2.3.53 → 2.3.67

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/dist/types.d.ts CHANGED
@@ -74,6 +74,7 @@ interface ProcessSpawnedCallback {
74
74
  sessionId?: string;
75
75
  }) => void;
76
76
  onProcessExited?: (pid: number) => void;
77
+ onMcpServersReady?: (serverNames: string[]) => void;
77
78
  }
78
79
  interface TaskExecutionOptions {
79
80
  repositoryPath?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/agent",
3
- "version": "2.3.53",
3
+ "version": "2.3.67",
4
4
  "repository": "https://github.com/PostHog/code",
5
5
  "description": "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
6
6
  "exports": {
@@ -107,11 +107,11 @@
107
107
  "access": "public"
108
108
  },
109
109
  "scripts": {
110
- "build": "rm -rf dist && tsup",
110
+ "build": "node ../../scripts/rimraf.mjs dist && tsup",
111
111
  "dev": "tsup --watch",
112
112
  "test": "vitest run",
113
113
  "test:watch": "vitest",
114
114
  "typecheck": "pnpm exec tsc --noEmit",
115
- "clean": "rm -rf dist .turbo"
115
+ "clean": "node ../../scripts/rimraf.mjs dist .turbo"
116
116
  }
117
117
  }
@@ -55,7 +55,10 @@ import {
55
55
  handleSystemMessage,
56
56
  handleUserAssistantMessage,
57
57
  } from "./conversion/sdk-to-acp";
58
- import { fetchMcpToolMetadata } from "./mcp/tool-metadata";
58
+ import {
59
+ fetchMcpToolMetadata,
60
+ getConnectedMcpServerNames,
61
+ } from "./mcp/tool-metadata";
59
62
  import { canUseTool } from "./permissions/permission-handlers";
60
63
  import { getAvailableSlashCommands } from "./session/commands";
61
64
  import { parseMcpServers } from "./session/mcp-config";
@@ -101,6 +104,7 @@ function sanitizeTitle(text: string): string {
101
104
  export interface ClaudeAcpAgentOptions {
102
105
  onProcessSpawned?: (info: ProcessSpawnedInfo) => void;
103
106
  onProcessExited?: (pid: number) => void;
107
+ onMcpServersReady?: (serverNames: string[]) => void;
104
108
  }
105
109
 
106
110
  export class ClaudeAcpAgent extends BaseAcpAgent {
@@ -1020,11 +1024,17 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
1020
1024
  * Both populate caches used later — neither is needed to return configOptions.
1021
1025
  */
1022
1026
  private deferBackgroundFetches(q: Query): void {
1027
+ this.logger.info("Starting background fetches (commands + MCP metadata)");
1023
1028
  Promise.all([
1024
1029
  new Promise<void>((resolve) => setTimeout(resolve, 10)).then(() =>
1025
1030
  this.sendAvailableCommandsUpdate(),
1026
1031
  ),
1027
- fetchMcpToolMetadata(q, this.logger),
1032
+ fetchMcpToolMetadata(q, this.logger).then(() => {
1033
+ const serverNames = getConnectedMcpServerNames();
1034
+ if (serverNames.length > 0) {
1035
+ this.options?.onMcpServersReady?.(serverNames);
1036
+ }
1037
+ }),
1028
1038
  ]).catch((err) =>
1029
1039
  this.logger.error("Background fetch failed", { error: err }),
1030
1040
  );
@@ -1,3 +1,4 @@
1
+ import * as path from "node:path";
1
2
  import type { PromptRequest } from "@agentclientprotocol/sdk";
2
3
  import type { SDKUserMessage } from "@anthropic-ai/claude-agent-sdk";
3
4
  import type { ContentBlockParam } from "@anthropic-ai/sdk/resources";
@@ -12,12 +13,11 @@ function formatUriAsLink(uri: string): string {
12
13
  try {
13
14
  if (uri.startsWith("file://")) {
14
15
  const filePath = uri.slice(7);
15
- const name = filePath.split("/").pop() || filePath;
16
+ const name = path.basename(filePath) || filePath;
16
17
  return `[@${name}](${uri})`;
17
18
  }
18
19
  if (uri.startsWith("zed://")) {
19
- const parts = uri.split("/");
20
- const name = parts[parts.length - 1] || uri;
20
+ const name = path.basename(uri) || uri;
21
21
  return `[@${name}](${uri})`;
22
22
  }
23
23
  return uri;
@@ -56,6 +56,8 @@ type ChunkHandlerContext = {
56
56
  registerHooks?: boolean;
57
57
  supportsTerminalOutput?: boolean;
58
58
  cwd?: string;
59
+ /** Raw MCP tool result from SDKUserMessage.tool_use_result (contains content, structuredContent, _meta) */
60
+ mcpToolUseResult?: Record<string, unknown>;
59
61
  };
60
62
 
61
63
  export interface MessageHandlerContext {
@@ -348,7 +350,16 @@ function handleToolResultChunk(
348
350
  toolCallId: chunk.tool_use_id,
349
351
  sessionUpdate: "tool_call_update",
350
352
  status: chunk.is_error ? "failed" : "completed",
351
- rawOutput: chunk.content,
353
+ rawOutput: ctx.mcpToolUseResult
354
+ ? { ...ctx.mcpToolUseResult, isError: chunk.is_error ?? false }
355
+ : {
356
+ content: Array.isArray(chunk.content)
357
+ ? chunk.content
358
+ : typeof chunk.content === "string"
359
+ ? [{ type: "text" as const, text: chunk.content }]
360
+ : [],
361
+ isError: chunk.is_error ?? false,
362
+ },
352
363
  ...toolUpdate,
353
364
  });
354
365
 
@@ -435,6 +446,7 @@ function toAcpNotifications(
435
446
  registerHooks?: boolean,
436
447
  supportsTerminalOutput?: boolean,
437
448
  cwd?: string,
449
+ mcpToolUseResult?: Record<string, unknown>,
438
450
  ): SessionNotification[] {
439
451
  if (typeof content === "string") {
440
452
  const update: SessionUpdate = {
@@ -461,6 +473,7 @@ function toAcpNotifications(
461
473
  registerHooks,
462
474
  supportsTerminalOutput,
463
475
  cwd,
476
+ mcpToolUseResult,
464
477
  };
465
478
  const output: SessionNotification[] = [];
466
479
 
@@ -829,6 +842,13 @@ export async function handleUserAssistantMessage(
829
842
  ? (message.parent_tool_use_id ?? undefined)
830
843
  : undefined;
831
844
 
845
+ // Pass the raw MCP tool result (contains content, structuredContent, _meta)
846
+ // so it can be forwarded as-is to the renderer for MCP Apps
847
+ const mcpToolUseResult =
848
+ message.type === "user" && message.tool_use_result != null
849
+ ? (message.tool_use_result as Record<string, unknown>)
850
+ : undefined;
851
+
832
852
  for (const notification of toAcpNotifications(
833
853
  contentToProcess as typeof content,
834
854
  message.message.role,
@@ -841,6 +861,7 @@ export async function handleUserAssistantMessage(
841
861
  context.registerHooks,
842
862
  context.supportsTerminalOutput,
843
863
  session.cwd,
864
+ mcpToolUseResult,
844
865
  )) {
845
866
  await client.sessionUpdate(notification);
846
867
  session.notificationHistory.push(notification);
@@ -48,6 +48,7 @@ export async function fetchMcpToolMetadata(
48
48
  for (const tool of server.tools) {
49
49
  const toolKey = buildToolKey(server.name, tool.name);
50
50
  const readOnly = tool.annotations?.readOnly === true;
51
+
51
52
  mcpToolMetadataCache.set(toolKey, {
52
53
  readOnly,
53
54
  name: tool.name,
@@ -94,6 +95,15 @@ export function isMcpToolReadOnly(toolName: string): boolean {
94
95
  return metadata?.readOnly === true;
95
96
  }
96
97
 
98
+ export function getConnectedMcpServerNames(): string[] {
99
+ const names = new Set<string>();
100
+ for (const key of mcpToolMetadataCache.keys()) {
101
+ const parts = key.split("__");
102
+ if (parts.length >= 3) names.add(parts[1]);
103
+ }
104
+ return [...names];
105
+ }
106
+
97
107
  export function clearMcpToolMetadataCache(): void {
98
108
  mcpToolMetadataCache.clear();
99
109
  }
package/src/index.ts CHANGED
@@ -1 +1,5 @@
1
- export { isMcpToolReadOnly } from "./adapters/claude/mcp/tool-metadata";
1
+ export {
2
+ getMcpToolMetadata,
3
+ isMcpToolReadOnly,
4
+ type McpToolMetadata,
5
+ } from "./adapters/claude/mcp/tool-metadata";
package/src/types.ts CHANGED
@@ -103,6 +103,7 @@ export interface ProcessSpawnedCallback {
103
103
  sessionId?: string;
104
104
  }) => void;
105
105
  onProcessExited?: (pid: number) => void;
106
+ onMcpServersReady?: (serverNames: string[]) => void;
106
107
  }
107
108
 
108
109
  export interface TaskExecutionOptions {