Skip to content

Commit 157849f

Browse files
committed
refactor: avoid mutating config arg in registerAppTool
1 parent 6a22f0d commit 157849f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/server/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export interface McpUiAppToolConfig extends ToolConfig {
4848
/**
4949
* URI of the UI resource to display for this tool.
5050
* This is converted to `_meta["ui/resourceUri"]`.
51-
*
51+
*
5252
* @example "ui://weather/widget.html"
5353
*
5454
* @deprecated Use `_meta.ui.resourceUri` instead.
@@ -109,15 +109,16 @@ export function registerAppTool(
109109
const uiMeta = meta.ui as McpUiToolMeta | undefined;
110110
const legacyUri = meta[RESOURCE_URI_META_KEY] as string | undefined;
111111

112+
let normalizedMeta = meta;
112113
if (uiMeta?.resourceUri && !legacyUri) {
113114
// New format -> also set legacy key
114-
meta[RESOURCE_URI_META_KEY] = uiMeta.resourceUri;
115+
normalizedMeta = { ...meta, [RESOURCE_URI_META_KEY]: uiMeta.resourceUri };
115116
} else if (legacyUri && !uiMeta?.resourceUri) {
116117
// Legacy format -> also set new format
117-
meta.ui = { ...uiMeta, resourceUri: legacyUri };
118+
normalizedMeta = { ...meta, ui: { ...uiMeta, resourceUri: legacyUri } };
118119
}
119120

120-
server.registerTool(name, config, handler);
121+
server.registerTool(name, { ...config, _meta: normalizedMeta }, handler);
121122
}
122123

123124
/**

0 commit comments

Comments
 (0)