Overview
Thetest-connection command verifies that the provided credentials can successfully connect to the data source. This is a fire-and-forget operation - no state should be persisted.
Command Invocation
TestConnectionRequest object
Stdout: JSON-encoded TestConnectionResponse object
Timeout: 15 seconds
Required: No - optional command for improved UX during connection setup
Request Parameters
Response Structure
true if connection succeeded, false if it failedHuman-readable success or failure message displayed to the user
Example Implementation
Fromplugins/mysql/main.go:
Request Format (stdin)
Response Format (stdout)
Success Response
Failure Response
Implementation Guidelines
What to Test
- Parse credentials: Validate that required connection parameters are present
- Open connection: Attempt to establish a connection to the data source
- Ping/verify: Send a simple query or ping to confirm the connection is live
- Close immediately: Do not keep the connection open or persist state
What NOT to Test
- Do not run complex queries or modify data
- Do not create or alter database objects
- Do not persist connection state or cache credentials
- Do not perform expensive operations (keep it fast)
Error Handling
The host expects errors to be returned in the response object, not via Go’s error return:Common Error Messages
Connection Refused
Authentication Failed
Timeout
Invalid Credentials
User Experience Flow
- User fills in authentication form in the UI
- User clicks “Test Connection” button
- Host invokes
test-connectioncommand with form values - Plugin attempts connection and returns result within 15 seconds
- Host displays success/failure message to user
- If successful, user can save the connection
- If failed, user corrects the credentials and retries
Best Practices
- Keep it fast: Aim for < 2 second response time for local connections
- Clear messages: Include specific error details (wrong password vs. server down)
- Timeout handling: Respect context timeouts to avoid hanging the UI
- Security: Never log or expose passwords in error messages
- Fallback: If a plugin can’t test meaningfully, return
ok: truewith a message like “Test not available for this plugin”
Plugins Without Test Support
If a plugin doesn’t implementtest-connection, the host:
- Allows users to save connections without testing
- Connection errors are only discovered when executing the first query
- The “Test Connection” button is hidden or disabled in the UI
Notes
- The command is optional but highly recommended for better UX
- Plugins that support
test-connectionshould also handle the same credential format inexecandconnection-tree - The host does not cache test results - each click triggers a new test