Skip to main content
Glama
bpamiri

SQL Server MCP

by bpamiri

call_stored_proc

Execute stored procedures in SQL Server databases to retrieve data, perform operations, or automate database tasks using defined parameter inputs.

Instructions

Execute a stored procedure.

Args:
    procedure: Procedure name, optionally with schema (e.g., 'dbo.sp_GetUser' or 'sp_GetUser')
    params: Input parameter values as dictionary (parameter names without @)

Returns:
    Dictionary with:
    - procedure: Full procedure name
    - result_sets: List of result sets (each is a list of row dictionaries)
    - status: 'success' or error

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
procedureYes
paramsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The primary MCP tool handler for 'call_stored_proc'. Decorated with @mcp.tool(), it parses the procedure name, handles parameters, checks read-only mode, and calls the low-level ConnectionManager method.
    @mcp.tool()
    def call_stored_proc(
        procedure: str,
        params: dict[str, Any] | None = None,
    ) -> dict[str, Any]:
        """Execute a stored procedure.
    
        Args:
            procedure: Procedure name, optionally with schema (e.g., 'dbo.sp_GetUser' or 'sp_GetUser')
            params: Input parameter values as dictionary (parameter names without @)
    
        Returns:
            Dictionary with:
            - procedure: Full procedure name
            - result_sets: List of result sets (each is a list of row dictionaries)
            - status: 'success' or error
        """
        try:
            manager = get_connection_manager()
            config = manager.config
    
            # Check read-only mode
            if config.read_only:
                return {"error": "Stored procedure execution disabled in read-only mode"}
    
            # Parse schema.procedure format
            if "." in procedure:
                parts = procedure.split(".", 1)
                schema = parts[0]
                proc_name = parts[1]
            else:
                schema = "dbo"
                proc_name = procedure
    
            full_name = f"{schema}.{proc_name}"
    
            # Build parameter tuple
            param_values = tuple(params.values()) if params else None
    
            # Execute stored procedure
            results = manager.call_stored_proc(full_name, param_values)
    
            return {
                "status": "success",
                "procedure": full_name,
                "result_sets": [results] if results else [],
                "row_count": len(results) if results else 0,
            }
    
        except QueryError as e:
            logger.error(f"Error calling stored procedure {procedure}: {e}")
            return {"error": str(e)}
        except Exception as e:
            logger.error(f"Unexpected error calling stored procedure {procedure}: {e}")
            return {"error": str(e)}
  • Low-level helper method in ConnectionManager that performs the actual stored procedure execution using pymssql's cursor.callproc.
    def call_stored_proc(
        self,
        proc_name: str,
        params: tuple[Any, ...] | None = None,
    ) -> list[dict[str, Any]]:
        """Execute a stored procedure and return results.
    
        Args:
            proc_name: Name of the stored procedure
            params: Optional procedure parameters
    
        Returns:
            List of result rows as dicts
    
        Raises:
            QueryError: If execution fails
        """
        conn = self.get_connection()
        try:
            cursor = conn.cursor(as_dict=True)
            cursor.callproc(proc_name, params or ())
    
            # Fetch results if any
            results = []
            if cursor.description:
                results = list(cursor.fetchall())
    
            conn.commit()
            return results
    
        except pymssql.Error as e:
            logger.error(f"Stored procedure execution failed: {e}")
            raise QueryError(f"Stored procedure '{proc_name}' failed: {e}") from e
        finally:
            cursor.close()
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses that the tool executes a stored procedure and returns a dictionary with result sets and status, which adds some behavioral context. However, it lacks details on permissions, side effects, error handling, or performance implications, which are crucial for a database operation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and front-loaded with the purpose, followed by clear sections for Args and Returns. Every sentence adds value, such as examples and return structure, with no wasted words. It's appropriately sized for the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity, no annotations, and an output schema (implied by Returns section), the description is fairly complete. It covers purpose, parameters, and return values adequately. However, it could improve by addressing usage guidelines or behavioral risks like data modification, which would make it more comprehensive.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 0%, so the description must compensate. It adds meaningful semantics: 'procedure' includes examples with schema, and 'params' specifies input as a dictionary without '@' prefixes. This clarifies usage beyond the bare schema, though it could detail parameter types or constraints more.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Execute a stored procedure.' It specifies the verb ('Execute') and resource ('stored procedure'), which is straightforward. However, it doesn't explicitly differentiate from siblings like 'execute_query' or 'describe_stored_proc', which would require a 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention siblings like 'execute_query' for general SQL queries or 'describe_stored_proc' for metadata, leaving the agent without context for selection. This lack of comparative guidance is a significant gap.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bpamiri/mssql-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server