Repository navigation
feat(core): observe tool calls and keep operation tags (ENG-6303) - #39
Conversation
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.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Duplicated code
1 new finding.
|
Yukko (yukkodesu)
left a comment
There was a problem hiding this comment.
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.
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.
|
Rewrote the description to stay host-agnostic: it now says core sends nothing by itself and the local |
Part of ENG-6303
Core already measures every tool call through
recordand thephoton.mcp.tool.eventlog. 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/mcpstdio server passes no observer and behaves exactly as before.completedevent with the unprojectedoutcome(beforeclientResult()stripsstructuredContentfrom errors) and the sameresultanddurationMsthatrecordgetsabortedevent, then the abort reason is rethrown as beforerecordare unchangedobservepassedtoolErrorCode(outcome)is the existingerror.typederivation moved into one exported function: the stringcodeof an error result, otherwiseundefined. The log line and hosts share it.toolOutcomeName()now returns the typedToolResultinstead ofstring.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, andnormalizeCapabilitykeeps 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-coremoves 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 reachrecordtoday either. Wrapping the SDK'stools/callhandler would need its protected_getRequestHandler. A new event kind can be added later without breaking observers that ignore unknown kinds.Validation
New tests: tags are trimmed, kept in order and empty ones dropped; the release schema rejects
tags: []andtags: [""]; an error result reaches the observer unprojected while the response andrecordstay 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-botwith what you need.