@@ -3,27 +3,35 @@ import type { ToolPlugin, TransformContext } from "../../plugin-types.ts";
33/**
44 * Built-in plugin that handles tool name mapping between dot and underscore notation
55 * Allows tools to be referenced with both formats (e.g., "server.tool" and "server_tool")
6+ * Also sanitizes tool names to comply with API restrictions
67 */
78export const createToolNameMappingPlugin = ( ) : ToolPlugin => ( {
89 name : "built-in-tool-name-mapping" ,
910 version : "1.0.0" ,
1011 enforce : "pre" , // Apply early to establish mappings
1112 transformTool : ( tool , context : TransformContext ) => {
1213 const server = context . server ;
13- const toolName = context . toolName ;
14+ const toolName = context . toolName ; // Sanitized name (e.g., "_c_desktop-commander_start_process")
15+
16+ // Get original name if available (e.g., "@c/desktop-commander.start_process")
17+ const originalName = ( tool as any ) . _originalName || toolName ;
1418
1519 // Create bidirectional mapping between dot and underscore notation
16- const dotNotation = toolName . replace ( / _ / g, "." ) ;
17- const underscoreNotation = toolName . replace ( / \. / g, "_" ) ;
20+ // Based on ORIGINAL name to support both @scope /server.tool and @scope /server_tool
21+ const dotNotation = originalName . replace ( / _ / g, "." ) ;
22+ const underscoreNotation = originalName . replace ( / \. / g, "_" ) ;
1823
19- if ( dotNotation !== toolName && server . toolNameMapping ) {
24+ if ( dotNotation !== originalName && server . toolNameMapping ) {
2025 server . toolNameMapping . set ( dotNotation , toolName ) ;
21- server . toolNameMapping . set ( toolName , dotNotation ) ;
2226 }
2327
24- if ( underscoreNotation !== toolName && server . toolNameMapping ) {
28+ if ( underscoreNotation !== originalName && server . toolNameMapping ) {
2529 server . toolNameMapping . set ( underscoreNotation , toolName ) ;
26- server . toolNameMapping . set ( toolName , underscoreNotation ) ;
30+ }
31+
32+ // Also map the original name to sanitized name
33+ if ( originalName !== toolName && server . toolNameMapping ) {
34+ server . toolNameMapping . set ( originalName , toolName ) ;
2735 }
2836
2937 return tool ;
0 commit comments