@salesforce/mcp 0.27.1 → 0.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +1 -1
- package/lib/sf-mcp-server.d.ts +11 -0
- package/lib/sf-mcp-server.js +39 -0
- package/npm-shrinkwrap.json +564 -586
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export default class McpServerCommand extends Command {
|
|
|
4
4
|
static description: string;
|
|
5
5
|
static flags: {
|
|
6
6
|
orgs: import("@oclif/core/interfaces").OptionFlag<string[], import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
-
toolsets: import("@oclif/core/interfaces").OptionFlag<(import("@salesforce/mcp-provider-api
|
|
7
|
+
toolsets: import("@oclif/core/interfaces").OptionFlag<(import("@salesforce/mcp-provider-api").Toolset | "all")[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
8
|
tools: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
9
|
version: import("@oclif/core/interfaces").BooleanFlag<void>;
|
|
10
10
|
'no-telemetry': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
package/lib/sf-mcp-server.d.ts
CHANGED
|
@@ -46,5 +46,16 @@ export declare class SfMcpServer extends McpServer implements ToolMethodSignatur
|
|
|
46
46
|
outputSchema?: OutputArgs;
|
|
47
47
|
annotations?: ToolAnnotations;
|
|
48
48
|
}, cb: ToolCallback<InputArgs>): RegisteredTool;
|
|
49
|
+
/**
|
|
50
|
+
* Calculates the total character count from tool result content and structured output.
|
|
51
|
+
* Used for token usage. Accounts for both:
|
|
52
|
+
* - content: text (and other) content items
|
|
53
|
+
* - structuredContent: structured tool output when the tool defines an outputSchema
|
|
54
|
+
*
|
|
55
|
+
* @see https://modelcontextprotocol.io/specification/2025-11-25/server/tools#output-schema
|
|
56
|
+
* @param result - The CallToolResult from tool execution
|
|
57
|
+
* @returns Total character count across text content and structured content
|
|
58
|
+
*/
|
|
59
|
+
private calculateResponseCharCount;
|
|
49
60
|
}
|
|
50
61
|
export {};
|
package/lib/sf-mcp-server.js
CHANGED
|
@@ -86,6 +86,14 @@ export class SfMcpServer extends McpServer {
|
|
|
86
86
|
this.logger.debug(`Tool ${name} completed in ${runtimeMs}ms`);
|
|
87
87
|
if (result.isError)
|
|
88
88
|
this.logger.debug(`Tool ${name} errored`);
|
|
89
|
+
// Calculate response character count for token usage (never let telemetry instrumentation fail a tool call)
|
|
90
|
+
let responseCharCount = 0;
|
|
91
|
+
try {
|
|
92
|
+
responseCharCount = this.calculateResponseCharCount(result);
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
// never let telemetry instrumentation fail a tool call
|
|
96
|
+
}
|
|
89
97
|
this.telemetry?.sendEvent('TOOL_CALLED', {
|
|
90
98
|
name,
|
|
91
99
|
runtimeMs,
|
|
@@ -96,6 +104,7 @@ export class SfMcpServer extends McpServer {
|
|
|
96
104
|
//
|
|
97
105
|
// https://modelcontextprotocol.io/specification/2025-06-18/schema#calltoolresult
|
|
98
106
|
isError: result.isError ?? false,
|
|
107
|
+
responseCharCount: responseCharCount.toString(),
|
|
99
108
|
});
|
|
100
109
|
this.telemetry?.sendPdpEvent({
|
|
101
110
|
eventName: 'salesforceMcp.executed',
|
|
@@ -107,5 +116,35 @@ export class SfMcpServer extends McpServer {
|
|
|
107
116
|
const tool = super.registerTool(name, config, wrappedCb);
|
|
108
117
|
return tool;
|
|
109
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Calculates the total character count from tool result content and structured output.
|
|
121
|
+
* Used for token usage. Accounts for both:
|
|
122
|
+
* - content: text (and other) content items
|
|
123
|
+
* - structuredContent: structured tool output when the tool defines an outputSchema
|
|
124
|
+
*
|
|
125
|
+
* @see https://modelcontextprotocol.io/specification/2025-11-25/server/tools#output-schema
|
|
126
|
+
* @param result - The CallToolResult from tool execution
|
|
127
|
+
* @returns Total character count across text content and structured content
|
|
128
|
+
*/
|
|
129
|
+
calculateResponseCharCount(result) {
|
|
130
|
+
let total = 0;
|
|
131
|
+
// Plain text (and other) content items
|
|
132
|
+
if (result.content && Array.isArray(result.content)) {
|
|
133
|
+
total += result.content
|
|
134
|
+
.filter((item) => item.type === 'text')
|
|
135
|
+
.reduce((sum, item) => sum + item.text.length, 0);
|
|
136
|
+
}
|
|
137
|
+
// Structured content (JSON object per outputSchema)
|
|
138
|
+
const structured = result.structuredContent;
|
|
139
|
+
if (structured !== undefined && structured !== null && typeof structured === 'object') {
|
|
140
|
+
try {
|
|
141
|
+
total += JSON.stringify(structured).length;
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
// ignore serialization errors
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return total;
|
|
148
|
+
}
|
|
110
149
|
}
|
|
111
150
|
//# sourceMappingURL=sf-mcp-server.js.map
|