-
-
Notifications
You must be signed in to change notification settings - Fork 87
feat(docs): make documentation plugin optional with opt-in config #413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+137
−10
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /** | ||
| * Optional Appium documentation plugin (RAG docs query + skills tools). | ||
| * | ||
| * The documentation feature lives in a separate package, `@appium/mcp-documentation`, | ||
| * which carries a multi-megabyte embeddings cache and pulls in a heavy ML stack | ||
| * (`@xenova/transformers`, `@langchain/*`). To keep the default install lean, that | ||
| * package is declared as an OPTIONAL peer dependency: it is not installed by | ||
| * default, and nothing related to it is downloaded unless the user opts in. | ||
| * | ||
| * Contract: | ||
| * - `APPIUM_MCP_DOCS_ENABLED` unset / not truthy → docs tools are NOT registered. | ||
| * This is the default; nothing extra is loaded. | ||
| * - `APPIUM_MCP_DOCS_ENABLED` truthy → the plugin is loaded if | ||
| * `@appium/mcp-documentation` is installed. If it is not installed, the server | ||
| * logs an actionable install hint and starts normally without the docs tools. | ||
| * | ||
| * Installation is intentionally left to the user's package manager (run at install | ||
| * time, where it belongs) rather than shelled out from the running server: that | ||
| * dedupes against appium-mcp's existing dependencies, works across npm/pnpm/yarn, | ||
| * and never blocks server startup. | ||
| */ | ||
|
|
||
| import type { AppiumMcpPlugin } from './core.js'; | ||
| import log from './logger.js'; | ||
| import { isTruthyEnvValue } from './utils/env.js'; | ||
|
|
||
| const ENABLED_FLAG = 'APPIUM_MCP_DOCS_ENABLED'; | ||
| const PACKAGE_NAME = '@appium/mcp-documentation'; | ||
|
|
||
| /** True when the user has opted into the documentation tools. */ | ||
| export function isDocumentationEnabled(): boolean { | ||
| return isTruthyEnvValue(process.env[ENABLED_FLAG]); | ||
| } | ||
|
navin772 marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Load the documentation plugin when the user has opted in. | ||
| * | ||
| * @returns the plugin instance, or `null` if the optional package is not | ||
| * installed or fails to load (in which case the server runs without the | ||
| * documentation tools). | ||
| */ | ||
| export async function loadDocumentationPlugin(): Promise<AppiumMcpPlugin | null> { | ||
| try { | ||
| // Widen to `string` so TypeScript treats this as a fully dynamic import and | ||
| // does not require @appium/mcp-documentation to be resolvable at build time | ||
| // (it is an optional, opt-in dependency, not installed by default). | ||
| const specifier: string = PACKAGE_NAME; | ||
| const mod = (await import(specifier)) as { | ||
| AppiumDocumentation: new () => AppiumMcpPlugin; | ||
| }; | ||
| const plugin = new mod.AppiumDocumentation(); | ||
| log.info(`Documentation tools enabled (${PACKAGE_NAME} loaded).`); | ||
| return plugin; | ||
| } catch (err) { | ||
| if (isModuleNotFound(err)) { | ||
| log.warn( | ||
| `${ENABLED_FLAG} is set but ${PACKAGE_NAME} is not installed. ` + | ||
| 'The documentation tools (appium_documentation_query, appium_skills) ' + | ||
| 'will be unavailable. Install the package to enable them:\n' + | ||
| ` npm install ${PACKAGE_NAME}` | ||
| ); | ||
| } else { | ||
| log.error(`${PACKAGE_NAME} is installed but failed to load:`, err); | ||
| } | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| function isModuleNotFound(err: unknown): boolean { | ||
| if (typeof err !== 'object' || err === null || !('code' in err)) { | ||
| return false; | ||
| } | ||
| const code = (err as { code?: unknown }).code; | ||
| return code === 'ERR_MODULE_NOT_FOUND' || code === 'MODULE_NOT_FOUND'; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,21 @@ | ||
| import type { AppiumMcpPlugin } from './core.js'; | ||
| import { createAppiumMcpServer } from './create-server.js'; | ||
| import { | ||
| isDocumentationEnabled, | ||
| loadDocumentationPlugin, | ||
| } from './documentation.js'; | ||
|
|
||
| const plugins: AppiumMcpPlugin[] = []; | ||
|
|
||
| try { | ||
| const { AppiumDocumentation } = await import('@appium/mcp-documentation'); | ||
| plugins.push(new AppiumDocumentation()); | ||
| } catch (_err) {} | ||
| // Documentation tools (RAG docs query + skills) are opt-in. They live in a | ||
| // separate package only installed when the user sets | ||
| // APPIUM_MCP_DOCS_ENABLED. See ./documentation.ts for the full contract. | ||
| if (isDocumentationEnabled()) { | ||
| const documentationPlugin = await loadDocumentationPlugin(); | ||
| if (documentationPlugin) { | ||
| plugins.push(documentationPlugin); | ||
| } | ||
| } | ||
|
|
||
| const server = await createAppiumMcpServer({ plugins }); | ||
| export default server; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.