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

Function annotateMcpRequest

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

Source from the content-addressed store, hash-verified

183 });
184
185export const annotateMcpRequest = (
186 request: Request,
187 opts: { token: VerifiedToken | null; parseBody: boolean },
188): Effect.Effect<void> =>
189 Effect.gen(function* () {
190 const cf = getCfMeta(request);
191 const baseAttrs: Record<string, unknown> = {
192 "mcp.request.method": request.method,
193 "mcp.request.session_id_present": !!request.headers.get("mcp-session-id"),
194 "mcp.request.session_id": request.headers.get("mcp-session-id") ?? "",
195 "mcp.auth.has_bearer": (request.headers.get("authorization") ?? "").startsWith(BEARER_PREFIX),
196 "mcp.auth.verified": !!opts.token,
197 "mcp.auth.organization_id": opts.token?.organizationId ?? "",
198 "mcp.auth.account_id": opts.token?.accountId ?? "",
199 "cf.country": cf.country ?? "",
200 "cf.city": cf.city ?? "",
201 "cf.region": cf.region ?? "",
202 "cf.timezone": cf.timezone ?? "",
203 "cf.asn": cf.asn ?? 0,
204 "cf.as_organization": cf.asOrganization ?? "",
205 "cf.tls_version": cf.tlsVersion ?? "",
206 "cf.tls_cipher": cf.tlsCipher ?? "",
207 "cf.http_protocol": cf.httpProtocol ?? "",
208 "cf.colo": cf.colo ?? "",
209 ...dumpHeaders(request),
210 };
211
212 const envelope = opts.parseBody ? yield* readJsonRpcEnvelope(request) : Option.none();
213 const attrs = {
214 ...baseAttrs,
215 ...rpcAttrs(envelope),
216 "mcp.request.parse_body": opts.parseBody,
217 };
218
219 yield* Effect.annotateCurrentSpan(attrs);
220 yield* Effect.annotateCurrentSpan(attrs).pipe(Effect.withSpan("mcp.request.annotate"));
221 });

Callers 3

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

no test coverage detected