Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/__tests__/__snapshots__/options.defaults.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,8 @@ exports[`options defaults should return specific properties: defaults 1`] = `
"toolModules": [],
"urlRegex": /\\^\\(https\\?:\\)\\\\/\\\\//i,
"version": "0.0.0",
"xhrFetch": {
"timeoutMs": 15000,
},
}
`;
36 changes: 32 additions & 4 deletions src/options.defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { type ToolModule } from './server.toolsUser';
* registered with the server.
* @property urlRegex - Regular expression pattern for URL matching.
* @property version - Version of the package.
* @property xhrFetch - XHR and Fetch options.
*/
interface DefaultOptions<TLogOptions = LoggingOptions> {
contextPath: string;
Expand Down Expand Up @@ -73,6 +74,7 @@ interface DefaultOptions<TLogOptions = LoggingOptions> {
toolModules: ToolModule | ToolModule[];
urlRegex: RegExp;
version: string;
xhrFetch: XhrFetchOptions;
}

/**
Expand Down Expand Up @@ -153,13 +155,19 @@ interface LoggingSession extends LoggingOptions {
readonly channelName: string;
}

/**
* Base stats options.
*/
type StatsOptions = {
reportIntervalMs: {
health: number;
transport: number;
}
};

/**
* Stats channel names.
*/
type StatsChannels = {
readonly health: string;
readonly session: string;
Expand All @@ -179,6 +187,17 @@ interface StatsSession extends StatsOptions {
channels: StatsChannels
}

/**
* XHR and Fetch options.
*
* @interface XhrFetchOptions
*
* @property timeoutMs Timeout for XHR and Fetch requests (ms).
*/
interface XhrFetchOptions {
timeoutMs: number;
}

/**
* Base logging options.
*/
Expand All @@ -205,7 +224,7 @@ const HTTP_OPTIONS: HttpOptions = {
*/
const PLUGIN_HOST_OPTIONS: PluginHostOptions = {
loadTimeoutMs: 5000,
invokeTimeoutMs: 10000,
invokeTimeoutMs: 10_000,
gracePeriodMs: 2000
};

Expand Down Expand Up @@ -250,7 +269,7 @@ const TOOL_MEMO_OPTIONS = {
};

/**
* Stats options.
* Default stats options.
*/
const STATS_OPTIONS: StatsOptions = {
reportIntervalMs: {
Expand All @@ -259,6 +278,13 @@ const STATS_OPTIONS: StatsOptions = {
}
};

/**
* Default XHR and Fetch options.
*/
const XHR_FETCH_OPTIONS: XhrFetchOptions = {
timeoutMs: 15_000
};

/**
* Base logging channel name. Fixed to avoid user override.
*/
Expand Down Expand Up @@ -387,7 +413,8 @@ const DEFAULT_OPTIONS: DefaultOptions = {
toolModules: [],
separator: DEFAULT_SEPARATOR,
urlRegex: URL_REGEX,
version: (process.env.NODE_ENV === 'local' && '0.0.0') || packageJson.version
version: (process.env.NODE_ENV === 'local' && '0.0.0') || packageJson.version,
xhrFetch: XHR_FETCH_OPTIONS
};

export {
Expand All @@ -412,5 +439,6 @@ export {
type LoggingOptions,
type LoggingSession,
type PluginHostOptions,
type StatsSession
type StatsSession,
type XhrFetchOptions
};
8 changes: 4 additions & 4 deletions src/server.getResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ readLocalFileFunction.memo = memo(readLocalFileFunction, DEFAULT_OPTIONS.resourc
*
* @note Review expanding fetch to handle more file types like JSON.
*
* @param url
* @param url - URL to fetch
* @param options - Options
*/
const fetchUrlFunction = async (url: string) => {
const fetchUrlFunction = async (url: string, options = getOptions()) => {
const controller = new AbortController();
const timeoutMs = Number(process.env.DOC_MCP_FETCH_TIMEOUT_MS || 15_000);
const timeout = setTimeout(() => controller.abort(), timeoutMs);
const timeout = setTimeout(() => controller.abort(), options.xhrFetch.timeoutMs);

// Allow the process to exit
timeout.unref();
Expand Down
Loading