- 
                Notifications
    You must be signed in to change notification settings 
- Fork 248
feat: Add MCP elicitation for create project and branch tools #169
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
base: main
Are you sure you want to change the base?
Changes from all commits
80b3287
              a5eaac9
              9d0ff02
              ebc5843
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { source } from 'common-tags'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { Server } from '@modelcontextprotocol/sdk/server/index.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { z } from 'zod'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { listExtensionsSql, listTablesSql } from '../pg-meta/index.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|  | @@ -14,12 +15,14 @@ export type DatabaseOperationToolsOptions = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| database: DatabaseOperations; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| projectId?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| readOnly?: boolean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| server?: Server; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|  | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export function getDatabaseTools({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| database, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| projectId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| readOnly, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| server, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }: DatabaseOperationToolsOptions) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const project_id = projectId; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|  | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|  | @@ -215,6 +218,48 @@ export function getDatabaseTools({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Error('Cannot apply migration in read-only mode.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|  | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Try to request user confirmation via elicitation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (server) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const result = (await server.request( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| method: 'elicitation/create', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| params: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| message: `You are about to apply migration "${name}" to project ${project_id}. This will modify your database schema.\n\nPlease review the SQL:\n\n${query}\n\nDo you want to proceed?`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requestedSchema: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'object', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| properties: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| confirm: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'boolean', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title: 'Confirm Migration', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'I have reviewed the SQL and approve this migration', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required: ['confirm'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // @ts-ignore - elicitation types might not be available | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 
     | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // @ts-ignore - elicitation types might not be available | |
| // @ts-expect-error - elicitation types might not be available | 
    
      
    
      Copilot
AI
    
    
    
      Oct 27, 2025 
    
  
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The catch block silently proceeds with the migration after any elicitation error, which could include network failures or other issues unrelated to client support. Consider checking the specific error type to distinguish between 'unsupported' vs other failures, and potentially fail fast for unexpected errors rather than always proceeding.
| // If elicitation fails (client doesn't support it), proceed without confirmation | |
| // This maintains backwards compatibility | |
| console.warn( | |
| 'Elicitation not supported by client, proceeding with migration without confirmation' | |
| ); | |
| // Only proceed if the error is due to unsupported elicitation; otherwise, fail fast | |
| const errorMessage = | |
| typeof error === 'string' | |
| ? error | |
| : error instanceof Error | |
| ? error.message | |
| : ''; | |
| if ( | |
| errorMessage && | |
| ( | |
| errorMessage.includes('elicitation not supported') || | |
| errorMessage.includes('Elicitation not supported') || | |
| errorMessage.includes('not implemented') || | |
| errorMessage.includes('unsupported') | |
| ) | |
| ) { | |
| console.warn( | |
| 'Elicitation not supported by client, proceeding with migration without confirmation' | |
| ); | |
| } else { | |
| // Unexpected error, fail fast | |
| throw error; | |
| } | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if we can use the elicitInput helper here