MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / annotateMcpRequest

Function annotateMcpRequest

apps/cloud/src/mcp/telemetry.ts:234–269  ·  view source on GitHub ↗
(
  request: Request,
  opts: { token: VerifiedToken | null; parseBody: boolean },
)

Source from the content-addressed store, hash-verified

232 });
233
234export const annotateMcpRequest = (
235 request: Request,
236 opts: { token: VerifiedToken | null; parseBody: boolean },
237): Effect.Effect<void> =>
238 Effect.gen(function* () {
239 const cf = getCfMeta(request);
240 const baseAttrs: Record<string, unknown> = {
241 "mcp.request.method": request.method,
242 "mcp.request.session_id_present": !!request.headers.get("mcp-session-id"),
243 "mcp.request.session_id": request.headers.get("mcp-session-id") ?? "",
244 "mcp.auth.has_bearer": (request.headers.get("authorization") ?? "").startsWith(BEARER_PREFIX),
245 "mcp.auth.verified": !!opts.token,
246 "mcp.auth.organization_id": opts.token?.organizationId ?? "",
247 "mcp.auth.account_id": opts.token?.accountId ?? "",
248 "cf.country": cf.country ?? "",
249 "cf.city": cf.city ?? "",
250 "cf.region": cf.region ?? "",
251 "cf.timezone": cf.timezone ?? "",
252 "cf.asn": cf.asn ?? 0,
253 "cf.as_organization": cf.asOrganization ?? "",
254 "cf.tls_version": cf.tlsVersion ?? "",
255 "cf.tls_cipher": cf.tlsCipher ?? "",
256 "cf.http_protocol": cf.httpProtocol ?? "",
257 "cf.colo": cf.colo ?? "",
258 ...dumpHeaders(request),
259 };
260
261 const envelope = opts.parseBody ? yield* readJsonRpcEnvelope(request) : Option.none();
262 const attrs = {
263 ...baseAttrs,
264 ...rpcAttrs(envelope),
265 "mcp.request.parse_body": opts.parseBody,
266 };
267
268 yield* Effect.annotateCurrentSpan(attrs);
269 });

Callers 4

annotateFunction · 0.90
finishAuthorizedFunction · 0.90
toOutcomeFunction · 0.90
authenticateFunction · 0.90

Calls 5

getCfMetaFunction · 0.85
dumpHeadersFunction · 0.85
readJsonRpcEnvelopeFunction · 0.85
rpcAttrsFunction · 0.85
getMethod · 0.65

Tested by 1

annotateFunction · 0.72