-
Notifications
You must be signed in to change notification settings - Fork 8
feat: deep linking implementation for ToolHive Studio #953
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
Open
therealnb
wants to merge
11
commits into
main
Choose a base branch
from
research-80
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
062989b
feat: implement deep linking functionality
therealnb 6adb85e
Merge remote-tracking branch 'origin/main' into research-80
therealnb 8135349
Accidental check-in
therealnb f1ff557
Ignore vscode
therealnb 7b5dd26
fix: resolve CI check failures
therealnb fa12e08
Further check fixes
therealnb 45b80f9
Further clean up
therealnb 675585c
fix: add @public JSDoc tags and deepLink mock for tests
therealnb 82021b2
fix: replace useSearch with URLSearchParams in registry page
therealnb 85134f6
One more check fix
therealnb e844e6d
Fix dialog,
therealnb 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| { | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "name": "Debug ToolHive Studio Main Process", | ||
| "type": "node", | ||
| "request": "launch", | ||
| "program": "${workspaceFolder}/node_modules/.bin/electron-forge", | ||
| "args": ["start", "--", "--inspect=9229"], | ||
| "env": { | ||
| "NODE_ENV": "development", | ||
| "PATH": "/Users/nigel/.nvm/versions/node/v22.20.0/bin:${env:PATH}" | ||
| }, | ||
| "runtimeExecutable": "/Users/nigel/.nvm/versions/node/v22.20.0/bin/node", | ||
| "console": "integratedTerminal", | ||
| "skipFiles": ["<node_internals>/**"] | ||
| }, | ||
| { | ||
| "name": "Attach to ToolHive Studio", | ||
| "type": "node", | ||
| "request": "attach", | ||
| "port": 9229, | ||
| "skipFiles": ["<node_internals>/**"] | ||
| }, | ||
| { | ||
| "name": "Launch ToolHive Studio (Terminal)", | ||
| "type": "node", | ||
| "request": "launch", | ||
| "program": "/Users/nigel/.nvm/versions/node/v22.20.0/bin/pnpm", | ||
| "args": ["run", "start:debug"], | ||
| "env": { | ||
| "NODE_ENV": "development" | ||
| }, | ||
| "cwd": "${workspaceFolder}", | ||
| "console": "integratedTerminal", | ||
| "skipFiles": ["<node_internals>/**"] | ||
| } | ||
| ] | ||
| } | ||
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,202 @@ | ||
| # Deep Linking in ToolHive Studio | ||
|
|
||
| ToolHive Studio supports deep linking to provide a seamless user experience when installing MCP servers. This feature allows external tools, documentation, and error messages to direct users directly to the server installation page in the UI. | ||
|
|
||
| ## Overview | ||
|
|
||
| The deep linking system consists of: | ||
|
|
||
| 1. **Custom URL Scheme**: `toolhive://` protocol for OS-level integration | ||
| 2. **HTTP Control Endpoint**: Fallback for when the UI is already running | ||
| 3. **CLI Command Generation**: Alternative for command-line users | ||
|
|
||
| ## URL Scheme Format | ||
|
|
||
| ``` | ||
| toolhive://action?parameter=value | ||
| ``` | ||
|
|
||
| ### Supported Actions | ||
|
|
||
| #### `install-server` | ||
| Navigate to the server installation page in the registry. | ||
|
|
||
| **Parameters:** | ||
| - `server` (required): Server name to install | ||
| - `registry` (optional): Registry name (defaults to 'official') | ||
|
|
||
| **Example:** | ||
| ``` | ||
| toolhive://install-server?server=github®istry=official | ||
| ``` | ||
|
|
||
|
|
||
| ## HTTP Control Endpoint | ||
|
|
||
| When ToolHive Studio is running, it starts an HTTP control server on `http://127.0.0.1:51234` for programmatic navigation. | ||
|
|
||
| ### Endpoints | ||
|
|
||
| #### `GET /health` | ||
| Check if the control server is running. | ||
|
|
||
| **Response:** | ||
| ```json | ||
| { | ||
| "status": "ok", | ||
| "service": "toolhive-studio-control", | ||
| "timestamp": "2024-01-01T00:00:00.000Z" | ||
| } | ||
| ``` | ||
|
|
||
| #### `POST /navigate` | ||
| Navigate to a deep link URL. | ||
|
|
||
| **Request Body:** | ||
| ```json | ||
| { | ||
| "url": "toolhive://install-server?server=github-mcp-server" | ||
| } | ||
| ``` | ||
|
|
||
| **Response:** | ||
| ```json | ||
| { | ||
| "success": true, | ||
| "message": "Navigation handled" | ||
| } | ||
| ``` | ||
|
|
||
| #### `GET /navigate?url=<encoded-url>` | ||
| Alternative GET endpoint for navigation. | ||
|
|
||
| **Example:** | ||
| ``` | ||
| GET /navigate?url=toolhive%3A//install-server%3Fserver%3Dgithub-mcp-server | ||
| ``` | ||
|
|
||
| ## Usage Examples | ||
|
|
||
| ### From Documentation | ||
| Include deep links in your MCP server documentation: | ||
|
|
||
| ```markdown | ||
| ## Quick Install | ||
|
|
||
| Click here to install in ToolHive Studio: | ||
| [Install GitHub MCP Server](toolhive://install-server?server=github-mcp-server®istry=official) | ||
|
|
||
| Or run this command: | ||
| ```bash | ||
| thv run --registry official github-mcp-server | ||
| ``` | ||
|
|
||
| ### From Error Messages | ||
| When a required secret is missing, generate a deep link: | ||
|
|
||
| ```typescript | ||
| const deepLink = `toolhive://install-server?server=${serverName}&secret_API_KEY=<your-api-key>` | ||
| console.error(`Missing API_KEY. Configure it here: ${deepLink}`) | ||
| ``` | ||
|
|
||
| ### From External Tools | ||
| Use the HTTP control endpoint to navigate programmatically: | ||
|
|
||
| ```bash | ||
| # Check if ToolHive Studio is running | ||
| curl -s http://127.0.0.1:51234/health | ||
|
|
||
| # Navigate to install page | ||
| curl -X POST http://127.0.0.1:51234/navigate \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{"url": "toolhive://install-server?server=my-server"}' | ||
| ``` | ||
|
|
||
| ### From JavaScript/Node.js | ||
| ```javascript | ||
| async function openInToolHive(serverName, environment = {}, secrets = {}) { | ||
| const url = new URL('toolhive://install-server') | ||
| url.searchParams.set('server', serverName) | ||
|
|
||
| // Add environment variables | ||
| for (const [key, value] of Object.entries(environment)) { | ||
| url.searchParams.set(`env_${key}`, value) | ||
| } | ||
|
|
||
| // Add secrets | ||
| for (const [key, value] of Object.entries(secrets)) { | ||
| url.searchParams.set(`secret_${key}`, value) | ||
| } | ||
|
|
||
| // Try HTTP control endpoint first (if UI is running) | ||
| try { | ||
| const response = await fetch('http://127.0.0.1:51234/navigate', { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify({ url: url.toString() }) | ||
| }) | ||
|
|
||
| if (response.ok) { | ||
| console.log('Navigated via control endpoint') | ||
| return | ||
| } | ||
| } catch (error) { | ||
| // Control endpoint not available, fall back to OS | ||
| } | ||
|
|
||
| // Fallback to OS deep link (will launch app if not running) | ||
| window.open(url.toString(), '_blank') | ||
| } | ||
| ``` | ||
|
|
||
| ## Implementation Details | ||
|
|
||
| ### OS Integration | ||
|
|
||
| The deep linking system registers the `toolhive://` protocol with the operating system: | ||
|
|
||
| - **macOS**: Uses `app.setAsDefaultProtocolClient()` and handles `open-url` events | ||
| - **Windows**: Registers protocol in registry, handles via `second-instance` event | ||
| - **Linux**: Uses desktop file registration, handles via command line arguments | ||
|
|
||
| ### Security Considerations | ||
|
|
||
| 1. **Local Only**: The HTTP control endpoint only binds to `127.0.0.1` (localhost) | ||
| 2. **URL Validation**: All URLs must start with `toolhive://` | ||
| 3. **Parameter Sanitization**: All parameters are validated and sanitized | ||
| 4. **No Sensitive Data**: Secrets in URLs are for convenience only; users should set them securely | ||
|
|
||
| ### Error Handling | ||
|
|
||
| - Invalid URLs are logged and ignored | ||
| - Navigation failures fall back to the default page | ||
| - Network errors in the control endpoint are handled gracefully | ||
| - Missing required parameters show appropriate error messages | ||
|
|
||
| ## Best Practices | ||
|
|
||
| 1. **Always provide CLI alternatives** for users who prefer command-line tools | ||
| 2. **Use environment variables** for non-sensitive configuration | ||
| 3. **Prompt for secrets** rather than including them in URLs when possible | ||
| 4. **Test deep links** on all supported platforms | ||
| 5. **Provide fallback instructions** if deep linking fails | ||
|
|
||
| ## Testing | ||
|
|
||
| You can test deep links using: | ||
|
|
||
| ```bash | ||
| # macOS | ||
| open "toolhive://install-server?server=test-server" | ||
|
|
||
| # Windows | ||
| start "toolhive://install-server?server=test-server" | ||
|
|
||
| # Linux | ||
| xdg-open "toolhive://install-server?server=test-server" | ||
|
|
||
| # HTTP Control Endpoint | ||
| curl -X POST http://127.0.0.1:51234/navigate \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{"url": "toolhive://install-server?server=test-server"}' | ||
| ``` |
Oops, something went wrong.
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.