@sentry/core
Version:
Base implementation for all Sentry JavaScript SDKs
85 lines (81 loc) • 3.42 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const attributes = require('@sentry/conventions/attributes');
const url = require('../../utils/url.js');
const methodConfig = require('./methodConfig.js');
function formatLoggingData(data) {
return typeof data === "string" ? data : JSON.stringify(data);
}
function getNotificationAttributes(method, params, recordInputs) {
const attributes$1 = {};
switch (method) {
case "notifications/cancelled":
if (params?.requestId) {
attributes$1[attributes.MCP_CANCELLED_REQUEST_ID] = String(params.requestId);
}
if (params?.reason) {
attributes$1[attributes.MCP_CANCELLED_REASON] = String(params.reason);
}
break;
case "notifications/message":
if (params?.level) {
attributes$1[attributes.MCP_LOGGING_LEVEL] = String(params.level);
}
if (params?.logger) {
attributes$1[attributes.MCP_LOGGING_LOGGER] = String(params.logger);
}
if (params?.data !== void 0) {
attributes$1[attributes.MCP_LOGGING_DATA_TYPE] = typeof params.data;
if (recordInputs) {
attributes$1[attributes.MCP_LOGGING_MESSAGE] = formatLoggingData(params.data);
}
}
break;
case "notifications/progress":
if (params?.progressToken) {
attributes$1[attributes.MCP_PROGRESS_TOKEN] = String(params.progressToken);
}
if (typeof params?.progress === "number") {
attributes$1[attributes.MCP_PROGRESS_CURRENT] = params.progress;
}
if (typeof params?.total === "number") {
attributes$1[attributes.MCP_PROGRESS_TOTAL] = params.total;
if (typeof params?.progress === "number") {
attributes$1[attributes.MCP_PROGRESS_PERCENTAGE] = params.progress / params.total * 100;
}
}
if (params?.message) {
attributes$1[attributes.MCP_PROGRESS_MESSAGE] = String(params.message);
}
break;
case "notifications/resources/updated":
if (params?.uri) {
attributes$1[attributes.MCP_RESOURCE_URI] = String(params.uri);
const urlObject = url.parseStringToURLObject(String(params.uri));
if (urlObject && !url.isURLObjectRelative(urlObject)) {
attributes$1[attributes.MCP_RESOURCE_PROTOCOL] = urlObject.protocol.replace(":", "");
}
}
break;
case "notifications/initialized":
attributes$1[attributes.MCP_LIFECYCLE_PHASE] = "initialization_complete";
attributes$1[attributes.MCP_PROTOCOL_READY] = 1;
break;
}
return attributes$1;
}
function buildTypeSpecificAttributes(type, message, params, recordInputs) {
if (type === "request") {
const request = message;
const targetInfo = methodConfig.extractTargetInfo(request.method, params || {});
return {
// oxlint-disable-next-line typescript/no-deprecated -- Preserve the legacy request ID attribute for existing consumers.
...request.id !== void 0 && { [attributes.MCP_REQUEST_ID]: String(request.id) },
...targetInfo.attributes,
...recordInputs ? methodConfig.getRequestArguments(request.method, params || {}) : {}
};
}
return getNotificationAttributes(message.method, params || {}, recordInputs);
}
exports.buildTypeSpecificAttributes = buildTypeSpecificAttributes;
exports.getNotificationAttributes = getNotificationAttributes;
//# sourceMappingURL=attributeExtraction.js.map