Skip to content

Commit 15bc364

Browse files
committed
fix(getResources): move dotenv to default options
1 parent 5d60f08 commit 15bc364

3 files changed

Lines changed: 36 additions & 7 deletions

File tree

src/__tests__/__snapshots__/options.defaults.test.ts.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,8 @@ exports[`options defaults should return specific properties: defaults 1`] = `
8282
"toolModules": [],
8383
"urlRegex": /\\^\\(https\\?:\\)\\\\/\\\\//i,
8484
"version": "0.0.0",
85+
"xhrFetch": {
86+
"timeoutMs": 15000,
87+
},
8588
}
8689
`;

src/options.defaults.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ interface DefaultOptions<TLogOptions = LoggingOptions> {
4545
contextPath: string;
4646
contextUrl: string;
4747
docsPath: string;
48+
xhrFetch: XhrFetchOptions;
4849
http: HttpOptions;
4950
isHttp: boolean;
5051
logging: TLogOptions;
@@ -153,13 +154,19 @@ interface LoggingSession extends LoggingOptions {
153154
readonly channelName: string;
154155
}
155156

157+
/**
158+
* Base stats options.
159+
*/
156160
type StatsOptions = {
157161
reportIntervalMs: {
158162
health: number;
159163
transport: number;
160164
}
161165
};
162166

167+
/**
168+
* Stats channel names.
169+
*/
163170
type StatsChannels = {
164171
readonly health: string;
165172
readonly session: string;
@@ -179,6 +186,17 @@ interface StatsSession extends StatsOptions {
179186
channels: StatsChannels
180187
}
181188

189+
/**
190+
* XHR and Fetch options.
191+
*
192+
* @interface XhrFetchOptions
193+
*
194+
* @property timeoutMs Timeout for XHR and Fetch requests (ms).
195+
*/
196+
interface XhrFetchOptions {
197+
timeoutMs: number;
198+
}
199+
182200
/**
183201
* Base logging options.
184202
*/
@@ -205,7 +223,7 @@ const HTTP_OPTIONS: HttpOptions = {
205223
*/
206224
const PLUGIN_HOST_OPTIONS: PluginHostOptions = {
207225
loadTimeoutMs: 5000,
208-
invokeTimeoutMs: 10000,
226+
invokeTimeoutMs: 10_000,
209227
gracePeriodMs: 2000
210228
};
211229

@@ -250,7 +268,7 @@ const TOOL_MEMO_OPTIONS = {
250268
};
251269

252270
/**
253-
* Stats options.
271+
* Default stats options.
254272
*/
255273
const STATS_OPTIONS: StatsOptions = {
256274
reportIntervalMs: {
@@ -259,6 +277,13 @@ const STATS_OPTIONS: StatsOptions = {
259277
}
260278
};
261279

280+
/**
281+
* Default XHR and Fetch options.
282+
*/
283+
const XHR_FETCH_OPTIONS: XhrFetchOptions = {
284+
timeoutMs: 15_000
285+
};
286+
262287
/**
263288
* Base logging channel name. Fixed to avoid user override.
264289
*/
@@ -387,7 +412,8 @@ const DEFAULT_OPTIONS: DefaultOptions = {
387412
toolModules: [],
388413
separator: DEFAULT_SEPARATOR,
389414
urlRegex: URL_REGEX,
390-
version: (process.env.NODE_ENV === 'local' && '0.0.0') || packageJson.version
415+
version: (process.env.NODE_ENV === 'local' && '0.0.0') || packageJson.version,
416+
xhrFetch: XHR_FETCH_OPTIONS
391417
};
392418

393419
export {

src/server.getResources.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ readLocalFileFunction.memo = memo(readLocalFileFunction, DEFAULT_OPTIONS.resourc
2323
*
2424
* @note Review expanding fetch to handle more file types like JSON.
2525
*
26-
* @param url
26+
* @param url - URL to fetch
27+
* @param options - Options
2728
*/
28-
const fetchUrlFunction = async (url: string) => {
29+
const fetchUrlFunction = async (url: string, options = getOptions()) => {
2930
const controller = new AbortController();
30-
const timeoutMs = Number(process.env.DOC_MCP_FETCH_TIMEOUT_MS || 15_000);
31-
const timeout = setTimeout(() => controller.abort(), timeoutMs);
31+
const timeout = setTimeout(() => controller.abort(), options.xhrFetch.timeoutMs);
3232

3333
// Allow the process to exit
3434
timeout.unref();

0 commit comments

Comments
 (0)