Skip to content

feat(core): observe tool calls and keep operation tags (ENG-6303) - #39

Merged
Unic (YuniqueUnic) merged 2 commits into
mainfrom
unic/eng-6303-observe-tool-calls
Nov 27, 2026
Merged

Unic (YuniqueUnic) merged 2 commits into
mainfrom
unic/eng-6303-observe-tool-calls

Conversation

@YuniqueUnic

@YuniqueUnic Unic (YuniqueUnic) commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Part of ENG-6303

Core already measures every tool call through record and the photon.mcp.tool.event log. This adds an optional observer, so a host that embeds core can also receive each call as a typed event and decide what to do with it. Core itself sends nothing anywhere: the local @photon-ai/mcp stdio server passes no observer and behaves exactly as before.

// packages/core/src/runtime/telemetry.ts
export type ToolResult = "complete" | "error" | "pending" | LifecycleDisposition;
export type RuntimeToolEvent =
  | Readonly<{ kind: "completed"; capability: Capability; input: unknown; outcome: Result; result: ToolResult; durationMs: number }>
  | Readonly<{ kind: "aborted"; capability: Capability; input: unknown; durationMs: number }>;
export type ToolObserver = (event: RuntimeToolEvent) => void;

// packages/core/src/runtime/execution/index.ts
export interface RuntimeDependencies extends InvocationDependencies { readonly observe?: ToolObserver; /* … */ }
export function toolErrorCode(outcome: Result): string | undefined;
Call Observer receives
Tool returns a result, success or error One completed event with the unprojected outcome (before clientResult() strips structuredContent from errors) and the same result and durationMs that record gets
Request aborted while the tool runs One aborted event, then the abort reason is rethrown as before
Observer throws, or returns a promise that rejects Ignored; the response and record are unchanged
No observe passed Nothing changes
  • toolErrorCode(outcome) is the existing error.type derivation moved into one exported function: the string code of an error result, otherwise undefined. The log line and hosts share it.
  • toolOutcomeName() now returns the typed ToolResult instead of string.
  • Capability.tags: the compiler keeps an operation's string OpenAPI tags in order, trimmed, and drops empty ones; the strict release schema accepts only a non-empty list of non-empty tags, and normalizeCapability keeps them. A host can use the first tag as the tool category, the same tag the docs site files the operation under. Releases without tags load unchanged.
  • @photon-ai/mcp-core moves to 0.2.1. All changes are additive.

Not observed. The MCP SDK 2.0.0 rejects an unknown tool name and arguments that fail the input schema before our handler runs, so those calls never reach executeCapability(); they never reach record today either. Wrapping the SDK's tools/call handler would need its protected _getRequestHandler. A new event kind can be added later without breaking observers that ignore unknown kinds.

Validation

pnpm verify    passed: 601 core, 27 mcp tests, Biome, type checks, builds

New tests: tags are trimmed, kept in order and empty ones dropped; the release schema rejects tags: [] and tags: [""]; an error result reaches the observer unprojected while the response and record stay the same, whether the observer throws or returns a rejected promise; an in-flight abort is observed once and still rethrows.

Release: after merge, publish core with a GitHub release tagged mcp-core-v0.2.1. Hosts can pin 0.2.1 once it is on npm.


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Hosts can pass an optional observer through the execution dependencies.
executeCapability notifies it once per call with a completed or aborted
event, and core drops observer exceptions so they never change a result.
toolErrorCode() is the one derivation of a tool error code, shared by the
existing log line and hosts. Capabilities keep their OpenAPI tags.
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9285ec32-0ed4-446b-b52d-16d7497df29c
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Duplicated code

Exact duplication Before 3fe4706 After 0ef944c
Duplicated lines 136 (1.62%) 136 (1.60%)
Clone pairs 10 10
Scanned files 35 35

1 new finding.

@yukkodesu Yukko (yukkodesu) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean separation of mechanism and policy overall — left 3 inline notes (1 schema invariant worth tightening + 2 minor edge cases).

Also a quick note on the PR description: since photon-hq/mcp-server is a public repo that also ships the local @photon-ai/mcp stdio server (which sends no telemetry), consider editing the PR description to stay host-agnostic and drop references to internal services/tooling — external readers skimming the opening sentence could easily misread it as the local package sending tool calls to third-party analytics.

Comment thread packages/core/src/release.ts Resolved
Comment thread packages/core/src/compiler/schema.ts Resolved
The release schema now rejects an empty tag list and empty tags, the
same guarantee the compiler gives hosts that read tags[0]. The compiler
trims tags and drops whitespace-only ones, as it already does for
summaries and API reference slugs. notify() also swallows a rejection
from an observer that returns a promise, since an async function is
assignable to ToolObserver and its rejection escaped the try/catch.
@YuniqueUnic

Copy link
Copy Markdown
Collaborator Author

Rewrote the description to stay host-agnostic: it now says core sends nothing by itself and the local @photon-ai/mcp stdio server passes no observer, and it no longer names internal services. The three inline notes are fixed in 0ef944c; replies are in each thread.

@YuniqueUnic
Unic (YuniqueUnic) merged commit 4877eef into main Nov 27, 2026
8 checks passed
@YuniqueUnic
Unic (YuniqueUnic) deleted the unic/eng-6303-observe-tool-calls branch November 27, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants