mssql_list_databases
Retrieve a list of all accessible databases on a Microsoft SQL Server to identify available data sources and manage connections.
Instructions
List all databases the user has access to
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| server | Yes | MSSQL Server hostname or IP address | |
| port | No | Port number (default: 1433) | |
| user | Yes | Username for authentication | |
| password | Yes | Password for authentication | |
| encrypt | No | Use encrypted connection (default: true) | |
| trustServerCertificate | No | Trust server certificate (default: true) |
Implementation Reference
- src/index.ts:472-495 (handler)The main handler function that connects to the MSSQL server using the provided connection config, executes a query against sys.databases to list accessible databases, and returns the results as JSON.private async handleListDatabases(args: any) { const config = ConnectionSchema.parse(args); const pool = await this.getConnection(config); const request = pool.request(); const result = await request.query(` SELECT name as database_name FROM sys.databases WHERE state = 0 -- Only online databases ORDER BY name `); return { content: [ { type: 'text', text: JSON.stringify({ server: config.server, databases: result.recordset, }, null, 2), }, ], }; }
- src/index.ts:272-287 (registration)Registration of the mssql_list_databases tool in the ListTools response, including name, description, and input schema definition.{ name: 'mssql_list_databases', description: 'List all databases the user has access to', inputSchema: { type: 'object', properties: { server: { type: 'string', description: 'MSSQL Server hostname or IP address' }, port: { type: 'number', description: 'Port number (default: 1433)', default: 1433 }, user: { type: 'string', description: 'Username for authentication' }, password: { type: 'string', description: 'Password for authentication' }, encrypt: { type: 'boolean', description: 'Use encrypted connection (default: true)', default: true }, trustServerCertificate: { type: 'boolean', description: 'Trust server certificate (default: true)', default: true }, }, required: ['server', 'user', 'password'], }, },
- src/index.ts:76-84 (schema)Zod schema for parsing connection configuration, used in the handler to validate tool inputs.const ConnectionSchema = z.object({ server: z.string().describe('MSSQL Server hostname or IP address'), port: z.number().default(1433).describe('Port number (default: 1433)'), user: z.string().describe('Username for authentication'), password: z.string().describe('Password for authentication'), database: z.string().optional().describe('Database name (optional)'), encrypt: z.boolean().default(true).describe('Use encrypted connection'), trustServerCertificate: z.boolean().default(true).describe('Trust server certificate'), });
- src/index.ts:437-438 (registration)Dispatch case in the CallToolRequestSchema handler that routes calls to the mssql_list_databases handler function.case 'mssql_list_databases': return await this.handleListDatabases(args);