MCP Tool

An MCP tool exposes a SQL Server stored procedure as a callable tool. Metadata, such as name, input schema, and procedure name, is registered in the system.

Input can be parameter-based (mapping directly to procedure parameters), raw JSON, or omitted entirely for tools that do not require input.

Output can be plain text, raw JSON, or a result set that is automatically serialized to JSON.

Claims

If the MCP server has security configured, claims contain JSON-serialized data that identifies the caller.

[{
  "name": "xxx",
  "value": "yyy"
}, ... ]

Example Tool: User Details

Demonstrates use of the ErrorMessage column, implicit JSON output, and the _RawJSON suffix for explicit JSON output.

// Schema for UserId
{"type": "integer"}
CREATE OR ALTER PROCEDURE Example.User_DetailsTool
	@UserId int = NULL,

	@Claims nvarchar(MAX) = NULL
AS
BEGIN
	IF NOT EXISTS (SELECT * FROM SoftadminApi.[User] WHERE UserId = @UserId)
	BEGIN
		SELECT CONCAT('User with id ', @UserId, ' not found') AS ErrorMessage;
		RETURN -1;
	END;

	SELECT
		U.UserId,
		U.Username,
		U.UsernameFirst,
		U.UsernameLast,
		U.UserEmail,
		U.RoleId,
		U.IsAdministrator,
		U.LanguageId,
		U.IsEnabled,
		CONVERT(bit, IIF(U.PasswordHash IS NOT NULL, 1, 0)) AS HasPassword,
		U.LastSuccessfulLogin,
		(
			SELECT
				F.FunctionId,
				F.FunctionName
			FROM
				SoftadminApi.User_Functions(@UserId) UF
				JOIN SoftadminApi.Functions(1) F ON F.FunctionID = UF.FunctionID
			FOR JSON PATH
		) AS Functions_RawJSON
	FROM
		SoftadminApi.[User] U
	WHERE
		U.UserId = @UserId;
END;

Example: Function List

Demonstrates using a JSON array as input.

// Schema for FunctionIds
{"type": "array", "items": { "type": "integer" }, "description": "Filters the list"}
CREATE OR ALTER PROCEDURE Example.Function_List
	@FunctionIds nvarchar(MAX) = NULL,

	@Claims nvarchar(MAX) = NULL
AS
BEGIN
	SELECT
		F.FunctionId,
		F.FunctionName,
		F.FunctionAlias,
		F.FunctionDescription
	FROM
		SoftadminApi.Functions(NULL) F
	WHERE
		(@FunctionIds IS NULL OR F.FunctionId IN (
			SELECT value
			FROM OPENJSON(@FunctionIds) WITH (value INT '$')
		))
	ORDER BY
		F.SortOrder,
		F.FunctionId;
END;

SQL

SQL Call: Call MCP Tool (mandatory)

Invoked each time the tool is called.

May modify database: Yes

Parameters

@<ParameterName> string
If the tool uses parameter-based input mode, arguments are mapped directly to procedure parameters.
@Claims string
JSON-serialized user claims for the caller. NULL is the server has no security configured.
@Parameters string
If the tool uses JSON input mode, it receives raw JSON in a single parameter.

Resultset: Structured Output (optional)

The result set is formatted as a JSON array of objects.

Table count: repeated zero or one time
Row count: zero or more rows
Columns
<ColumnName> optional any

The value is serialized as JSON and returned using the column name as the field name.

<ColumnName>_RawJSON optional string

The value is not serialized and is inserted as-is into a field named <ColumnName> (suffix removed). The value must be valid JSON.

Resultset: Tool Error (optional)

When the tool fails or input data is invalid, return a clear error message.

Table count: repeated zero or one time
Row count: exactly one row
Columns
ErrorMessage mandatory string

Error message returned to the caller.

Resultset: Raw Output (optional)

Tools that return plain text instead of JSON, or require advanced JSON formatting, can return raw text.

Table count: repeated zero or one time
Row count: exactly one row
Columns
TextContent mandatory string

Text to return