Skip to content

Commit ad97803

Browse files
authored
refactor(typings): pf-4119 rename, deprecate cli options (#199)
* index, deprecate, rename CliOptions towards PfMcpCliOptions, alias updates * options, move DefaultOptionsOverrides to ProgrammaticOptions * server, agent, replace alias JSDoc with copy, guidance on when to use * e2e, align annotation with PfMcpCliOptions
1 parent 50ebb04 commit ad97803

10 files changed

Lines changed: 90 additions & 46 deletions

File tree

guidelines/agent_coding.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,24 @@ While the codebase emphasizes pragmatism, **public APIs require comprehensive JS
194194

195195
- **`@param`**, **`@returns`**, **`@throws`**: Standard documentation for function signature.
196196
- **`@property`**: Document properties for interfaces or classes.
197-
- **`@alias`**: Used for stable aliased typings exposed to consumers.
197+
- **Type aliases (do not use `@alias`)**:
198+
- **Don't** use the `@alias` JSDoc tag on type aliases. Documentation generators may apply unwanted side effects (e.g. remaining symbols in the generated output).
199+
- **Do** document aliases with prose: `Alias of {@link InternalType} (Internal type).` for stable aliased typings exposed to consumers in `src/index.ts`.
200+
- **Do** use the simplified `Alias of {@link InternalType}.` for internal-only aliases to reduce redundancy.
198201
- **`@template`**: Document generic type parameters.
199202
- **`@example`**: Provide usage examples for complex functions.
200203
- **`@note`**: Important implementation details or gotchas.
201204

202205
### 4.2 JSDoc Format Examples
203206

204207
```typescript
208+
/**
209+
* Exposed options for CLI use. A focused options interface.
210+
*
211+
* Alias of {@link CliOptions} (Internal type).
212+
*/
213+
type PfMcpCliOptions = CliOptions;
214+
205215
/**
206216
* Fetches documentation for a PatternFly component.
207217
*

src/__tests__/index.test.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { main, start, type PfMcpOptions, type CliOptions } from '../index';
1+
import { main, start, type PfMcpOptions, type PfMcpCliOptions } from '../index';
22
import { parseCliOptions, type GlobalOptions } from '../options';
33
import { DEFAULT_OPTIONS } from '../options.defaults';
44
import { getSessionOptions, runWithSession, setOptions } from '../options.context';
@@ -36,7 +36,7 @@ describe('main', () => {
3636
mockParseCliOptions.mockImplementation(() => {
3737
callOrder.push('parse');
3838

39-
return { logging: defaultLogging } as CliOptions;
39+
return { logging: defaultLogging } as PfMcpCliOptions;
4040
});
4141

4242
mockSetOptions.mockImplementation(options => {
@@ -150,9 +150,23 @@ describe('main', () => {
150150
});
151151

152152
describe('type exports', () => {
153-
it('should export PfMcpOptions type', () => {
153+
it.each([
154+
{
155+
description: 'PfMcpOptions',
156+
checkType: (): PfMcpOptions => ({})
157+
},
158+
{
159+
description: 'PfMcpCliOptions',
160+
checkType: (): PfMcpCliOptions => ({
161+
isHttp: false,
162+
logging: {},
163+
toolModules: [],
164+
pluginIsolation: undefined
165+
})
166+
}
167+
])('should export type, $description', ({ checkType }) => {
154168
// TypeScript compilation will fail if the type is unavailable
155-
const options: PfMcpOptions = {};
169+
const options = checkType();
156170

157171
expect(options).toBeDefined();
158172
});

src/index.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { parseCliOptions, type CliOptions, type DefaultOptionsOverrides } from './options';
1+
import { parseCliOptions, type CliOptions, type ProgrammaticOptions } from './options';
22
import { getSessionOptions, setOptions, runWithSession } from './options.context';
33
import {
44
runServer,
@@ -23,9 +23,25 @@ import {
2323
} from './server.toolsUser';
2424

2525
/**
26-
* Options for "programmatic" use. Extends the `DefaultOptions` interface.
26+
* Exposed options for CLI use. A focused options interface.
27+
*
28+
* Alias of {@link CliOptions} (Internal type).
29+
*/
30+
type PfMcpCliOptions = CliOptions;
31+
32+
/**
33+
* `CliOptions` renamed to `PfMcpCliOptions` to avoid conflicts with internal naming.
34+
*
35+
* @deprecated Use {@link PfMcpCliOptions} instead.
36+
*/
37+
type DeprecatedCliOptions = PfMcpCliOptions;
38+
39+
/**
40+
* Exposed options for programmatic use. A limited `DefaultOptions` interface.
41+
*
42+
* Alias of {@link ProgrammaticOptions} (Internal type).
2743
*/
28-
type PfMcpOptions = DefaultOptionsOverrides;
44+
type PfMcpOptions = ProgrammaticOptions;
2945

3046
/**
3147
* Additional settings for programmatic control.
@@ -41,49 +57,49 @@ type PfMcpSettings = Pick<ServerSettings, 'allowProcessExit'>;
4157
/**
4258
* Server instance with shutdown capability
4359
*
44-
* @alias ServerInstance
60+
* Alias of {@link ServerInstance} (Internal type).
4561
*/
4662
type PfMcpInstance = ServerInstance;
4763

4864
/**
4965
* Subscribes a handler function, `PfMcpOnLogHandler`, to server logs. Automatically unsubscribed on server shutdown.
5066
*
51-
* @alias ServerOnLog
67+
* Alias of {@link ServerOnLog} (Internal type).
5268
*/
5369
type PfMcpOnLog = ServerOnLog;
5470

5571
/**
5672
* The handler function passed by `onLog`, `PfMcpOnLog`, to subscribe to server logs. Automatically unsubscribed on server shutdown.
5773
*
58-
* @alias ServerOnLogHandler
74+
* Alias of {@link ServerOnLogHandler} (Internal type).
5975
*/
6076
type PfMcpOnLogHandler = ServerOnLogHandler;
6177

6278
/**
6379
* The log event passed to the `onLog` handler, `PfMcpOnLogHandler`.
6480
*
65-
* @alias ServerLogEvent
81+
* Alias of {@link ServerLogEvent} (Internal type).
6682
*/
6783
type PfMcpLogEvent = ServerLogEvent;
6884

6985
/**
7086
* Get statistics about the server.
7187
*
72-
* @alias ServerGetStats
88+
* Alias of {@link ServerGetStats} (Internal type).
7389
*/
7490
type PfMcpGetStats = ServerGetStats;
7591

7692
/**
7793
* Statistics about the server.
7894
*
79-
* @alias ServerStats
95+
* Alias of {@link ServerStats} (Internal type).
8096
*/
8197
type PfMcpStats = ServerStats;
8298

8399
/**
84100
* Statistics report about the server.
85101
*
86-
* @alias ServerStatReport
102+
* Alias of {@link ServerStatReport} (Internal type).
87103
*/
88104
type PfMcpStatReport = ServerStatReport;
89105

@@ -199,7 +215,8 @@ export {
199215
createMcpTool,
200216
main,
201217
main as start,
202-
type CliOptions,
218+
type DeprecatedCliOptions as CliOptions,
219+
type PfMcpCliOptions,
203220
type PfMcpOptions,
204221
type PfMcpSettings,
205222
type PfMcpInstance,

src/options.context.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AsyncLocalStorage } from 'node:async_hooks';
22
import { randomUUID } from 'node:crypto';
3-
import { type AppSession, type GlobalOptions, type DefaultOptionsOverrides } from './options';
3+
import { type AppSession, type GlobalOptions, type ProgrammaticOptions } from './options';
44
import {
55
DEFAULT_OPTIONS,
66
LOG_BASENAME,
@@ -98,10 +98,10 @@ const optionsContext = new AsyncLocalStorage<GlobalOptions>();
9898
* @note In the future, look at adding a re-validation helper here, and potentially in `runWithOptions`,
9999
* that aligns with CLI options parsing. We need to account for both CLI and programmatic use.
100100
*
101-
* @param {DefaultOptionsOverrides} [options] - Optional overrides merged with DEFAULT_OPTIONS.
101+
* @param {ProgrammaticOptions} [options] - Optional overrides merged with DEFAULT_OPTIONS.
102102
* @returns {GlobalOptions} Cloned frozen default options object with session.
103103
*/
104-
const setOptions = (options?: DefaultOptionsOverrides): GlobalOptions => {
104+
const setOptions = (options?: ProgrammaticOptions): GlobalOptions => {
105105
const base = mergeObjects(DEFAULT_OPTIONS, options, { allowNullValues: false, allowUndefinedValues: false });
106106

107107
assertProtocol(base.patternflyOptions.urlWhitelist, base.patternflyOptions.urlWhitelistProtocols);

src/options.defaults.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,6 @@ interface DefaultOptions<TLogOptions = LoggingOptions> {
8181
xhrFetch: XhrFetchOptions;
8282
}
8383

84-
/**
85-
* Overrides for default options. Exposed to the consumer/user.
86-
*/
87-
type DefaultOptionsOverrides = Partial<
88-
Omit<DefaultOptions, 'mode' | 'modeOptions' | 'http' | 'logging' | 'pluginIsolation' | 'toolModules'>
89-
> & {
90-
mode?: DefaultOptions['mode'] | undefined;
91-
modeOptions?: Partial<ModeOptions> | undefined;
92-
http?: Partial<HttpOptions>;
93-
logging?: Partial<LoggingOptions>;
94-
pluginIsolation?: 'none' | 'strict' | undefined;
95-
toolModules?: ToolModule | ToolModule[] | undefined;
96-
};
97-
9884
/**
9985
* HTTP server options.
10086
*
@@ -549,7 +535,6 @@ export {
549535
MODE_LEVELS,
550536
PLUGIN_ISOLATION,
551537
type DefaultOptions,
552-
type DefaultOptionsOverrides,
553538
type HttpOptions,
554539
type LoggingOptions,
555540
type LoggingSession,
@@ -560,6 +545,7 @@ export {
560545
type RepoResources,
561546
type ServerInstanceOptions,
562547
type StatsSession,
548+
type ToolModule,
563549
type WhitelistUrl,
564550
type XhrFetchOptions
565551
};

src/options.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import {
33
MODE_LEVELS,
44
PLUGIN_ISOLATION,
55
type DefaultOptions,
6-
type DefaultOptionsOverrides,
76
type LoggingOptions,
87
type HttpOptions,
9-
type ModeOptions
8+
type ModeOptions,
9+
type ToolModule
1010
} from './options.defaults';
1111
import { type LogLevel, logSeverity } from './logger';
1212
import { isUrl, portValid } from './server.helpers';
@@ -26,7 +26,21 @@ type AppSession = {
2626
type GlobalOptions = DefaultOptions;
2727

2828
/**
29-
* Options parsed from CLI arguments
29+
* Option overrides parsed from programmatic use. Exposed to the consumer/user.
30+
*/
31+
type ProgrammaticOptions = Partial<
32+
Omit<DefaultOptions, 'mode' | 'modeOptions' | 'http' | 'logging' | 'pluginIsolation' | 'toolModules'>
33+
> & {
34+
mode?: DefaultOptions['mode'] | undefined;
35+
modeOptions?: Partial<ModeOptions> | undefined;
36+
http?: Partial<HttpOptions>;
37+
logging?: Partial<LoggingOptions>;
38+
pluginIsolation?: DefaultOptions['pluginIsolation'] | undefined;
39+
toolModules?: ToolModule | ToolModule[] | undefined;
40+
};
41+
42+
/**
43+
* Options parsed from CLI arguments. Exposed to the consumer/user.
3044
*
3145
* @note `pluginIsolation` preset for external plugins (CLI-provided). If omitted, defaults
3246
* to 'strict' when external tools are requested, otherwise 'none'.
@@ -241,8 +255,8 @@ export {
241255
type AppSession,
242256
type CliOptions,
243257
type DefaultOptions,
244-
type DefaultOptionsOverrides,
245258
type GlobalOptions,
246259
type HttpOptions,
247-
type LoggingOptions
260+
type LoggingOptions,
261+
type ProgrammaticOptions
248262
};

src/server.assertions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const mcpAssert = (condition: unknown, message: string | (() => string), code: E
2626
/**
2727
* General purpose input assert/validation function.
2828
*
29-
* @alias mcpAssert
29+
* Alias of {@link mcpAssert}.
3030
*
3131
* @param condition - Function or condition to be validated.
3232
* @param message - Thrown error message, or function, that returns the error message.

src/server.toolsUser.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ import { normalizeInputSchema } from './server.schema';
1212
/**
1313
* Inline tool options.
1414
*
15-
* @alias GlobalOptions
15+
* Alias of {@link GlobalOptions}.
16+
*
1617
* @note Author-facing configuration.
1718
*/
1819
type ToolInternalOptions = GlobalOptions;
1920

2021
/**
2122
* External tool options.
2223
*
23-
* @alias ToolOptions
24+
* Alias of {@link ToolOptions}.
25+
*
2426
* @note Author-facing configuration.
2527
*/
2628
type ToolExternalOptions = ToolOptions;
@@ -67,7 +69,8 @@ type CreatorEntry = Pick<NormalizedToolEntry, 'type' | 'original' | 'value' | 't
6769
/**
6870
* An MCP tool. A tool config tuple. The handler may be async or sync.
6971
*
70-
* @alias McpTool
72+
* Alias of {@link McpTool}.
73+
*
7174
* @note Author-facing configuration.
7275
* @example A tool config tuple. The handler may be async or sync.
7376
* [

src/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ interface ServerSettings {
5353
/**
5454
* Server stats.
5555
*
56-
* @alias Stats
56+
* Alias of {@link Stats}.
5757
*/
5858
type ServerStats = Stats;
5959

6060
/**
6161
* Server stats report.
6262
*
63-
* @alias StatReport
63+
* Alias of {@link StatReport}.
6464
*/
6565
type ServerStatReport = StatReport;
6666

tests/e2e/utils/stdioTransportClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface StdioTransportClient {
4444
* @param options - Server configuration options
4545
* @param options.command - Node command to run (default: 'node')
4646
* @param options.serverPath - Path to built server (default: 'dist/cli.js')
47-
* @param options.args - Additional args to pass to server, see app `CliOptions` for the full list
47+
* @param options.args - Additional args to pass to server, see `PfMcpCliOptions` for the full list
4848
* @param options.env - Environment variables for the child process
4949
*/
5050
export const startServer = async ({

0 commit comments

Comments
 (0)