|
| 1 | +// WebMCP: expose raid docs tools to AI agents via the browser |
| 2 | +// https://webmachinelearning.github.io/webmcp/ |
| 3 | +export function onRouteDidUpdate(): void { |
| 4 | + if (typeof navigator === 'undefined' || !('modelContext' in navigator)) { |
| 5 | + return; |
| 6 | + } |
| 7 | + |
| 8 | + (navigator as any).modelContext.provideContext({ |
| 9 | + tools: [ |
| 10 | + { |
| 11 | + name: 'navigate_to_docs', |
| 12 | + description: 'Navigate to a section of the raid documentation.', |
| 13 | + inputSchema: { |
| 14 | + type: 'object', |
| 15 | + properties: { |
| 16 | + section: { |
| 17 | + type: 'string', |
| 18 | + enum: ['overview', 'usage', 'features', 'examples', 'references', 'whats-new'], |
| 19 | + description: 'The documentation section to navigate to.', |
| 20 | + }, |
| 21 | + }, |
| 22 | + required: ['section'], |
| 23 | + }, |
| 24 | + execute: async ({ section }: { section: string }) => { |
| 25 | + const paths: Record<string, string> = { |
| 26 | + 'overview': '/docs/overview', |
| 27 | + 'usage': '/docs/category/usage', |
| 28 | + 'features': '/docs/category/features', |
| 29 | + 'examples': '/docs/category/examples', |
| 30 | + 'references': '/docs/category/references', |
| 31 | + 'whats-new': '/docs/whats-new', |
| 32 | + }; |
| 33 | + window.location.href = paths[section] ?? '/docs/overview'; |
| 34 | + }, |
| 35 | + }, |
| 36 | + { |
| 37 | + name: 'get_install_command', |
| 38 | + description: 'Returns the command to install raid on the current platform.', |
| 39 | + inputSchema: { |
| 40 | + type: 'object', |
| 41 | + properties: { |
| 42 | + platform: { |
| 43 | + type: 'string', |
| 44 | + enum: ['macos', 'linux', 'windows'], |
| 45 | + description: 'Target platform.', |
| 46 | + }, |
| 47 | + }, |
| 48 | + required: ['platform'], |
| 49 | + }, |
| 50 | + execute: async ({ platform }: { platform: string }) => { |
| 51 | + const commands: Record<string, string> = { |
| 52 | + macos: 'brew install 8bitalex/tap/raid', |
| 53 | + linux: 'curl -sSL https://github.com/8bitalex/raid/releases/latest/download/raid_linux_amd64.tar.gz | tar -xz && sudo mv raid /usr/local/bin/', |
| 54 | + windows: 'scoop bucket add 8bitalex https://github.com/8bitalex/scoop-bucket && scoop install raid', |
| 55 | + }; |
| 56 | + return commands[platform] ?? commands.macos; |
| 57 | + }, |
| 58 | + }, |
| 59 | + ], |
| 60 | + }); |
| 61 | +} |
0 commit comments