| 1 | package tool |
| 2 | |
| 3 | import "context" |
| 4 | |
| 5 | type remoteDispatchObserverKey struct{} |
| 6 | |
| 7 | // WithRemoteDispatchObserver binds content-free per-call telemetry to the |
| 8 | // concrete transport boundary. The callback is invoked immediately before an |
| 9 | // MCP tools/call request is sent, including calls whose remote result is an |
| 10 | // error. |
| 11 | func WithRemoteDispatchObserver(ctx context.Context, observer func()) context.Context { |
| 12 | if observer == nil { |
| 13 | return ctx |
| 14 | } |
| 15 | return context.WithValue(ctx, remoteDispatchObserverKey{}, observer) |
| 16 | } |
| 17 | |
| 18 | // ObserveRemoteDispatch records one actual remote tools/call attempt. |
| 19 | func ObserveRemoteDispatch(ctx context.Context) { |
| 20 | observer, _ := ctx.Value(remoteDispatchObserverKey{}).(func()) |
| 21 | if observer != nil { |
| 22 | observer() |
| 23 | } |
| 24 | } |
| 25 |