Skip to content

Commit 8154bf0

Browse files
committed
refactor: rename uiOverrides to customUIs in ServerOptions and UIRegistry for clarity
1 parent ab7be9a commit 8154bf0

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

src/server.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,20 @@ export interface ServerOptions {
6363
*/
6464
tools?: ToolClass[];
6565
/**
66-
* Custom UI overrides for tools. Maps tool names to their HTML strings.
67-
* These will override the default bundled UIs.
66+
* Custom UIs for tools. Maps tool names to their HTML strings.
67+
* Use this to add UIs to tools or replace the default bundled UIs.
6868
*
6969
* ```ts
7070
* import { readFileSync } from 'fs';
7171
* const server = new Server({
7272
* // ... other options
73-
* uiOverrides: {
73+
* customUIs: {
7474
* 'list-databases': readFileSync('./my-custom-ui.html', 'utf-8'),
7575
* }
7676
* });
7777
* ```
7878
*/
79-
uiOverrides?: Record<string, string>;
79+
customUIs?: Record<string, string>;
8080
}
8181

8282
export class Server {
@@ -107,7 +107,7 @@ export class Server {
107107
connectionErrorHandler,
108108
elicitation,
109109
tools,
110-
uiOverrides,
110+
customUIs,
111111
}: ServerOptions) {
112112
this.startTime = Date.now();
113113
this.session = session;
@@ -117,7 +117,7 @@ export class Server {
117117
this.elicitation = elicitation;
118118
this.connectionErrorHandler = connectionErrorHandler;
119119
this.toolConstructors = tools ?? AllTools;
120-
this.uiRegistry = new UIRegistry({ overrides: uiOverrides });
120+
this.uiRegistry = new UIRegistry({ customUIs });
121121
}
122122

123123
async connect(transport: Transport): Promise<void> {

src/ui/registry/registry.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,61 +25,61 @@ function getDefaultUIDistPath(): string {
2525
*
2626
* The registry:
2727
* - Loads default bundled HTML from dist/ui/ at runtime
28-
* - Allows overriding UIs via register()
28+
* - Allows adding or replacing UIs via register()
2929
* - Provides get() to retrieve UI HTML for a tool
3030
*/
3131
export class UIRegistry {
32-
private overrides: Map<string, string> = new Map();
32+
private customUIs: Map<string, string> = new Map();
3333
private cache: Map<string, string> = new Map();
3434
private uiDistPath: string;
3535

36-
constructor(options?: { uiDistPath?: string; overrides?: Record<string, string> }) {
36+
constructor(options?: { uiDistPath?: string; customUIs?: Record<string, string> }) {
3737
// Use provided path or auto-detect the dist/ui location
3838
this.uiDistPath = options?.uiDistPath ?? getDefaultUIDistPath();
3939

40-
// Apply initial overrides if provided
41-
if (options?.overrides) {
42-
for (const [toolName, html] of Object.entries(options.overrides)) {
40+
// Apply initial custom UIs if provided
41+
if (options?.customUIs) {
42+
for (const [toolName, html] of Object.entries(options.customUIs)) {
4343
this.register(toolName, html);
4444
}
4545
}
4646
}
4747

4848
/**
49-
* Register a custom UI HTML string for a tool, overriding the default
49+
* Register a custom UI HTML string for a tool
5050
* @param toolName The name of the tool (e.g., 'list-databases')
5151
* @param html The HTML string to use for this tool's UI
5252
*/
5353
register(toolName: string, html: string): void {
54-
this.overrides.set(toolName, html);
54+
this.customUIs.set(toolName, html);
5555
}
5656

5757
/**
58-
* Unregister a custom UI for a tool, reverting to the default
58+
* Unregister a custom UI for a tool, reverting to the default (if one exists)
5959
* @param toolName The name of the tool
6060
*/
6161
unregister(toolName: string): void {
62-
this.overrides.delete(toolName);
62+
this.customUIs.delete(toolName);
6363
}
6464

6565
/**
66-
* Check if a tool has a UI registered (either override or default)
66+
* Check if a tool has a UI registered (either custom or default)
6767
* @param toolName The name of the tool
6868
*/
6969
has(toolName: string): boolean {
70-
return this.overrides.has(toolName) || toolName in uiMap;
70+
return this.customUIs.has(toolName) || toolName in uiMap;
7171
}
7272

7373
/**
7474
* Get the UI HTML string for a tool
75-
* Returns the override if registered, otherwise loads the default from disk
75+
* Returns the custom UI if registered, otherwise loads the default from disk
7676
* @param toolName The name of the tool
7777
* @returns The HTML string, or undefined if no UI exists for this tool
7878
*/
7979
get(toolName: string): string | undefined {
80-
// Check for override first
81-
if (this.overrides.has(toolName)) {
82-
return this.overrides.get(toolName);
80+
// Check for custom UI first
81+
if (this.customUIs.has(toolName)) {
82+
return this.customUIs.get(toolName);
8383
}
8484

8585
// Check if we have a mapping for this tool
@@ -117,10 +117,10 @@ export class UIRegistry {
117117
}
118118

119119
/**
120-
* Get all registered tool names (both overrides and defaults)
120+
* Get all registered tool names (both custom and default)
121121
*/
122122
getRegisteredTools(): string[] {
123-
const tools = new Set<string>([...this.overrides.keys(), ...Object.keys(uiMap)]);
123+
const tools = new Set<string>([...this.customUIs.keys(), ...Object.keys(uiMap)]);
124124
return Array.from(tools);
125125
}
126126
}

0 commit comments

Comments
 (0)