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

Function annotateMcpRequest

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

Source from the content-addressed store, hash-verified

203 });
204
205export const annotateMcpRequest = (
206 request: Request,
207 opts: { token: VerifiedToken | null; parseBody: boolean },
208): Effect.Effect<void> =>
209 Effect.gen(function* () {
210 const cf = getCfMeta(request);
211 const baseAttrs: Record<string, unknown> = {
212 "mcp.request.method": request.method,
213 "mcp.request.session_id_present": !!request.headers.get("mcp-session-id"),
214 "mcp.request.session_id": request.headers.get("mcp-session-id") ?? "",
215 "mcp.auth.has_bearer": (request.headers.get("authorization") ?? "").startsWith(BEARER_PREFIX),
216 "mcp.auth.verified": !!opts.token,
217 "mcp.auth.organization_id": opts.token?.organizationId ?? "",
218 "mcp.auth.account_id": opts.token?.accountId ?? "",
219 "cf.country": cf.country ?? "",
220 "cf.city": cf.city ?? "",
221 "cf.region": cf.region ?? "",
222 "cf.timezone": cf.timezone ?? "",
223 "cf.asn": cf.asn ?? 0,
224 "cf.as_organization": cf.asOrganization ?? "",
225 "cf.tls_version": cf.tlsVersion ?? "",
226 "cf.tls_cipher": cf.tlsCipher ?? "",
227 "cf.http_protocol": cf.httpProtocol ?? "",
228 "cf.colo": cf.colo ?? "",
229 ...dumpHeaders(request),
230 };
231
232 const envelope = opts.parseBody ? yield* readJsonRpcEnvelope(request) : Option.none();
233 const attrs = {
234 ...baseAttrs,
235 ...rpcAttrs(envelope),
236 "mcp.request.parse_body": opts.parseBody,
237 };
238
239 yield* Effect.annotateCurrentSpan(attrs);
240 yield* Effect.annotateCurrentSpan(attrs).pipe(Effect.withSpan("mcp.request.annotate"));
241 });

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