PROJECT_STRUCTURE.mdā¢7.21 kB
# Project Structure
This document outlines the organization and structure of the MSSQL MCP Server project.
## š Repository Layout
```
mssql-mcp-server/
āāā š README.md # Main project documentation
āāā š LICENSE # MIT License with proper attribution
āāā š CONTRIBUTING.md # Contribution guidelines
āāā š CHANGELOG.md # Version history and release notes
āāā š package.json # Node.js package configuration
āāā š package-lock.json # Dependency lock file
āāā š tsconfig.json # TypeScript configuration
āāā š .gitignore # Git ignore patterns
āāā š .env.example # Environment configuration template
āāā š src/ # Source code
ā āāā š index.ts # Main MCP server implementation
ā āāā š tools/ # Database operation tools
ā āāā š ReadDataTool.ts # SELECT queries with security validation
ā āāā š InsertDataTool.ts # INSERT operations
ā āāā š UpdateDataTool.ts # UPDATE operations with WHERE validation
ā āāā š CreateTableTool.ts # Table creation
ā āāā š CreateIndexTool.ts # Index management
ā āāā š DropTableTool.ts # Table deletion
ā āāā š ListTableTool.ts # Schema discovery
ā āāā š DescribeTableTool.ts # Table structure inspection
āāā š dist/ # Compiled JavaScript output (generated)
āāā š docs/ # Additional documentation
ā āāā š PROJECT_STRUCTURE.md # This file
āāā š node_modules/ # Dependencies (generated)
```
## šļø Architecture Overview
### Core Components
#### `src/index.ts`
- **Main MCP Server**: Entry point and server implementation
- **Dual Authentication**: Logic for SQL Server vs Azure AD authentication
- **Connection Management**: Database connection pooling and token handling
- **Tool Registration**: Registration of all 8 database operation tools
- **Error Handling**: Centralized error management and logging
#### `src/tools/`
Database operation tools implementing the MCP Tool interface:
| Tool | Purpose | Security Level | Operations |
|------|---------|----------------|------------|
| **ReadDataTool** | Execute SELECT queries | ššš High | Read data with injection prevention |
| **InsertDataTool** | Add new records | šš Medium | Single/bulk inserts with validation |
| **UpdateDataTool** | Modify existing data | ššš High | Updates with mandatory WHERE clauses |
| **CreateTableTool** | Create new tables | šš Medium | Table creation with column definitions |
| **CreateIndexTool** | Optimize performance | šš Medium | Index creation and management |
| **DropTableTool** | Remove tables | ššš High | Safe table deletion with validation |
| **ListTableTool** | Browse schema | š Low | List tables and metadata |
| **DescribeTableTool** | Inspect structure | š Low | Table schema and column details |
## š§ Configuration Files
### `package.json`
- **Metadata**: Project name, description, keywords for npm
- **Scripts**: Build, development, and utility commands
- **Dependencies**: Runtime and development dependencies
- **Publishing**: Configuration for npm distribution
### `tsconfig.json`
- **Target**: ES2020 for modern JavaScript features
- **Module**: ES2020 modules for compatibility
- **Strict Mode**: Enabled for type safety
- **Output**: Compiled to `dist/` directory with source maps
### `.env.example`
- **Template**: Example environment configuration
- **Documentation**: Inline comments explaining each variable
- **Examples**: Multiple configuration scenarios
- **Security**: Guidelines for credential management
## š Documentation Structure
### Primary Documentation
- **README.md**: Complete user guide and reference
- **CONTRIBUTING.md**: Developer contribution guidelines
- **LICENSE**: MIT License with proper attribution
- **CHANGELOG.md**: Version history and release notes
### Additional Documentation
- **docs/PROJECT_STRUCTURE.md**: This architectural overview
- **Inline Comments**: Comprehensive code documentation
- **JSDoc**: TypeScript documentation for APIs
## š Build Process
### Development Workflow
```bash
npm install # Install dependencies
npm run build # Compile TypeScript to JavaScript
npm run watch # Watch mode for development
npm run dev # Build and start server
npm run clean # Clean build artifacts
```
### Output Structure
```
dist/
āāā index.js # Compiled main server
āāā index.d.ts # TypeScript declarations
āāā index.js.map # Source map for debugging
āāā tools/ # Compiled tool implementations
āāā ReadDataTool.js
āāā InsertDataTool.js
āāā ... (other tools)
```
## š”ļø Security Architecture
### Input Validation
- **SQL Injection Prevention**: Multi-layer protection in ReadDataTool
- **Query Validation**: Syntax and semantic analysis
- **Parameter Binding**: Automatic parameterization for all queries
- **Keyword Filtering**: Dangerous SQL keyword detection
### Authentication Flow
```
Environment Check
āāā SQL_USER + SQL_PASSWORD present?
ā āāā Yes ā SQL Server Authentication
ā āāā No ā Azure AD Authentication
āāā Connection established with appropriate method
```
### Access Control
- **Read-Only Mode**: Environment variable to restrict operations
- **Tool-Level Security**: Each tool implements appropriate validation
- **Connection Pooling**: Secure token management and expiration
## š¤ Contribution Guidelines
### Code Organization
- **Single Responsibility**: Each tool has one clear purpose
- **Consistent Patterns**: All tools follow the same interface
- **Error Handling**: Comprehensive error management
- **Type Safety**: Full TypeScript coverage
### File Naming Conventions
- **PascalCase**: Class files (e.g., `ReadDataTool.ts`)
- **camelCase**: Function and variable names
- **UPPER_CASE**: Constants and environment variables
- **kebab-case**: Configuration files (e.g., `package.json`)
### Development Standards
- **TypeScript**: Strict mode with comprehensive types
- **ES2020**: Modern JavaScript features
- **Modular Design**: Clear separation of concerns
- **Documentation**: Inline comments and JSDoc
## š Deployment Considerations
### Package Distribution
- **npm Registry**: Configured for npm publication
- **Binary**: Executable via `mssql-mcp-server` command
- **Files**: Only essential files included in package
- **Dependencies**: Minimal runtime dependencies
### Environment Support
- **Node.js**: 16+ compatibility
- **Platforms**: Windows, macOS, Linux
- **Databases**: SQL Server 2016+, Azure SQL Database
- **AI Assistants**: Claude Desktop, VS Code Agent, MCP-compatible clients
This structure ensures maintainability, security, and ease of contribution while providing a professional foundation for the open-source project.