Skip to content

Add stored procedure and function tools with comprehensive test coverage #59

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
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

shubham070
Copy link

@shubham070 shubham070 commented Jul 18, 2025

🚀 Overview

This PR implements comprehensive support for SQL Server stored procedures and functions in the MCP server, including execution capabilities, metadata retrieval, and robust test coverage.

✨ Features Added

New MCP Tools (6 tools)

  • ExecuteStoredProcedure - Execute stored procedures with optional parameters
  • ExecuteFunction - Execute table-valued functions with optional parameters
  • ListProceduresAndFunctions - List all stored procedures and functions in the database
  • DescribeProcedureOrFunction - Get detailed metadata about specific procedures/functions
  • CreateProcedure - Creates a new stored procedure in the SQL Database
  • CreateFunction - -"Creates a new function in the SQL Database

Comprehensive Test Coverage

  • 18 Unit Tests - Fast, isolated tests without database dependencies
  • Integration Tests - End-to-end testing with real SQL Server (existing tests preserved)
  • Test Documentation - Complete README with best practices and execution commands

🔧 Technical Implementation

Core Features

  • Parameter validation and sanitization for security
  • Support for both parameterized and parameterless execution
  • Comprehensive error handling and logging
  • Consistent return format following existing MCP patterns
  • Full metadata extraction including parameter definitions

Architecture Improvements

  • Clean separation between unit and integration tests
  • Follows Test Pyramid principle for optimal feedback cycles
  • Maintains existing code patterns and conventions
  • Zero breaking changes to existing functionality

🧪 Testing Strategy

Unit Tests (ToolsUnitTests.cs)

dotnet test --filter "FullyQualifiedName~ToolsUnitTests"
# ✅ 16 tests, ~1.2s execution time, no database required

…tools

- Add ListProceduresAndFunctions tool to list all stored procedures and functions
- Add DescribeProcedureOrFunction tool to get detailed information about procedures/functions
- Include parameter information, definitions, and metadata
- Both tools follow existing patterns with proper error handling and logging
…cuteFunction tools

- Add ToolsUnitTests.cs with 16 fast unit tests covering:
  * Parameter validation for stored procedures and functions
  * Constructor and interface validation for Tools class
  * SqlConnectionFactory interface verification
  * Various parameter types and null value handling

- Add comprehensive test documentation (README.md) explaining:
  * Separation between unit tests (fast, no dependencies) and integration tests
  * Test execution commands and prerequisites
  * Test coverage matrix for all tools
  * Best practices following Test Pyramid principle

- Maintain clean architecture:
  * Unit tests (16) - Fast validation without database dependencies
  * Integration tests (14) - End-to-end database testing (unchanged)
  * Total coverage: 30 tests across all MCP tools

This addresses missing test coverage for the ExecuteStoredProcedure and
ExecuteFunction tools added in previous commits while maintaining proper
separation of concerns between unit and integration testing.
Copy link

@aaron-cui-sh aaron-cui-sh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JetterMcTedder or other admins when are y'all gon review some of these open PRs?

@JetterMcTedder
Copy link
Contributor

@aaron-cui-sh let me go see if I can get someone to review the MCP updates/additions.

shubham070 and others added 6 commits August 7, 2025 23:21
- Add unit tests for CreateProcedure and CreateFunction tools
- Test parameter validation and SQL statement validation
- Test ExecuteStoredProcedure and ExecuteFunction parameter handling
- Test edge cases and error conditions
- Follow existing test patterns and conventions
…nd function tools

- Document all 13 MCP tools (7 existing + 6 new)
- Add detailed testing documentation
- Include example usage for procedures and functions
- Update tool count from 7 to 13 tools
- Add troubleshooting section for new features
git commit -m "Fix compilation errors: Remove invalid 'message' parameter from DbOperationResult constructor

- Fixed CreateProcedure.cs line 42
- Fixed CreateFunction.cs line 42
- DbOperationResult constructor only accepts success, error, rowsAffected, data parameters"

# Push to the PR branch
git push origin feature/implement-procedures-functions-tools
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants