Skip to content

Commit d1e9fdc

Browse files
committed
avoid inline conditionals
1 parent 2c6e5a0 commit d1e9fdc

File tree

4 files changed

+40
-13
lines changed

4 files changed

+40
-13
lines changed

packages/core/src/integrations/mcp-server/correlation.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ export function completeSpanWithResults(transport: MCPTransport, requestId: Requ
9090
*/
9191
export function cleanupPendingSpansForTransport(transport: MCPTransport): number {
9292
const spanMap = transportToSpanMap.get(transport);
93-
if (!spanMap) return 0;
93+
if (!spanMap) {
94+
return 0;
95+
}
9496

9597
const pendingCount = spanMap.size;
9698

packages/core/src/integrations/mcp-server/resultExtraction.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@ function buildAllContentItemAttributes(content: unknown[]): Record<string, strin
2222
};
2323

2424
for (const [i, item] of content.entries()) {
25-
if (typeof item !== 'object' || item === null) continue;
25+
if (typeof item !== 'object' || item === null) {
26+
continue;
27+
}
2628

2729
const contentItem = item as Record<string, unknown>;
2830
const prefix = content.length === 1 ? 'mcp.tool.result' : `mcp.tool.result.${i}`;
2931

3032
const safeSet = (key: string, value: unknown): void => {
31-
if (typeof value === 'string') attributes[`${prefix}.${key}`] = value;
33+
if (typeof value === 'string') {
34+
attributes[`${prefix}.${key}`] = value;
35+
}
3236
};
3337

3438
safeSet('content_type', contentItem.type);
@@ -39,7 +43,11 @@ function buildAllContentItemAttributes(content: unknown[]): Record<string, strin
3943
if (typeof contentItem.text === 'string') {
4044
const text = contentItem.text;
4145
const maxLength = 500;
42-
attributes[`${prefix}.content`] = text.length > maxLength ? `${text.slice(0, maxLength - 3)}...` : text;
46+
if (text.length > maxLength) {
47+
attributes[`${prefix}.content`] = `${text.slice(0, maxLength - 3)}...`;
48+
} else {
49+
attributes[`${prefix}.content`] = text;
50+
}
4351
}
4452

4553
if (typeof contentItem.data === 'string') {
@@ -64,7 +72,9 @@ function buildAllContentItemAttributes(content: unknown[]): Record<string, strin
6472
*/
6573
export function extractToolResultAttributes(result: unknown): Record<string, string | number | boolean> {
6674
let attributes: Record<string, string | number | boolean> = {};
67-
if (typeof result !== 'object' || result === null) return attributes;
75+
if (typeof result !== 'object' || result === null) {
76+
return attributes;
77+
}
6878

6979
const resultObj = result as Record<string, unknown>;
7080
if (typeof resultObj.isError === 'boolean') {
@@ -83,19 +93,24 @@ export function extractToolResultAttributes(result: unknown): Record<string, str
8393
*/
8494
export function extractPromptResultAttributes(result: unknown): Record<string, string | number | boolean> {
8595
const attributes: Record<string, string | number | boolean> = {};
86-
if (typeof result !== 'object' || result === null) return attributes;
96+
if (typeof result !== 'object' || result === null) {
97+
return attributes;
98+
}
8799

88100
const resultObj = result as Record<string, unknown>;
89101

90-
if (typeof resultObj.description === 'string')
102+
if (typeof resultObj.description === 'string') {
91103
attributes[MCP_PROMPT_RESULT_DESCRIPTION_ATTRIBUTE] = resultObj.description;
104+
}
92105

93106
if (Array.isArray(resultObj.messages)) {
94107
attributes[MCP_PROMPT_RESULT_MESSAGE_COUNT_ATTRIBUTE] = resultObj.messages.length;
95108

96109
const messages = resultObj.messages;
97110
for (const [i, message] of messages.entries()) {
98-
if (typeof message !== 'object' || message === null) continue;
111+
if (typeof message !== 'object' || message === null) {
112+
continue;
113+
}
99114

100115
const messageObj = message as Record<string, unknown>;
101116
const prefix = messages.length === 1 ? 'mcp.prompt.result' : `mcp.prompt.result.${i}`;

packages/core/src/integrations/mcp-server/sessionExtraction.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,15 @@ function extractPartyInfo(obj: unknown): PartyInfo {
3333

3434
if (obj && typeof obj === 'object' && obj !== null) {
3535
const source = obj as Record<string, unknown>;
36-
if (typeof source.name === 'string') partyInfo.name = source.name;
37-
if (typeof source.title === 'string') partyInfo.title = source.title;
38-
if (typeof source.version === 'string') partyInfo.version = source.version;
36+
if (typeof source.name === 'string') {
37+
partyInfo.name = source.name;
38+
}
39+
if (typeof source.title === 'string') {
40+
partyInfo.title = source.title;
41+
}
42+
if (typeof source.version === 'string') {
43+
partyInfo.version = source.version;
44+
}
3945
}
4046

4147
return partyInfo;
@@ -69,7 +75,9 @@ export function extractSessionDataFromInitializeResponse(result: unknown): Parti
6975
const sessionData: Partial<SessionData> = {};
7076
if (result && typeof result === 'object') {
7177
const resultObj = result as Record<string, unknown>;
72-
if (typeof resultObj.protocolVersion === 'string') sessionData.protocolVersion = resultObj.protocolVersion;
78+
if (typeof resultObj.protocolVersion === 'string') {
79+
sessionData.protocolVersion = resultObj.protocolVersion;
80+
}
7381
if (resultObj.serverInfo) {
7482
sessionData.serverInfo = extractPartyInfo(resultObj.serverInfo);
7583
}

packages/core/src/integrations/mcp-server/sessionManagement.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ const transportToSessionData = new WeakMap<MCPTransport, SessionData>();
1616
* @param sessionData - Session data to store
1717
*/
1818
export function storeSessionDataForTransport(transport: MCPTransport, sessionData: SessionData): void {
19-
if (transport.sessionId) transportToSessionData.set(transport, sessionData);
19+
if (transport.sessionId) {
20+
transportToSessionData.set(transport, sessionData);
21+
}
2022
}
2123

2224
/**

0 commit comments

Comments
 (0)