Definition
Assembly: Microsoft.OData.Mcp.Core.dll Namespace: Microsoft.OData.Mcp.Core.Tools Inheritance: System.ObjectSyntax
Summary
Represents the result of an MCP tool execution.Remarks
This class standardizes the format of tool execution results, providing consistent error handling, data formatting, and metadata across all tools.Constructors
.ctor
Initializes a new instance of the McpToolResult class.Syntax
.ctor
Initializes a new instance of the McpToolResult class with success status.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
data | System.Text.Json.JsonDocument? | The result data. |
correlationId | string? | The correlation ID. |
.ctor
Initializes a new instance of the McpToolResult class with error status.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
errorMessage | string | The error message. |
errorCode | string? | The error code. |
correlationId | string? | The correlation ID. |
.ctor Inherited
Inherited from
objectSyntax
Properties
CompletedAt
Gets or sets the timestamp when the execution completed.Syntax
Property Value
Type:System.DateTime?
The UTC timestamp when the tool finished executing.
Remarks
This timestamp can be used for auditing and troubleshooting purposes.CorrelationId
Gets or sets the correlation ID for this execution.Syntax
Property Value
Type:string?
The correlation ID that can be used to trace this execution across systems.
Remarks
This should match the correlation ID from the tool context for end-to-end tracing.Data
Gets or sets the result data as a JSON document.Syntax
Property Value
Type:System.Text.Json.JsonDocument?
The structured result data, or null if no data is available.
Remarks
The data format depends on the specific tool but should always be valid JSON that can be consumed by MCP clients.ErrorCode
Gets or sets the error code for failed executions.Syntax
Property Value
Type:string?
A machine-readable error code, or null if execution was successful.
Remarks
Error codes provide a standardized way for clients to handle specific error conditions programmatically.ErrorMessage
Gets or sets the error message for failed executions.Syntax
Property Value
Type:string?
A human-readable error message, or null if execution was successful.
Remarks
Error messages should be clear and actionable, helping users understand what went wrong and how to fix it.ExecutionDuration
Gets or sets the execution duration.Syntax
Property Value
Type:System.TimeSpan?
The time taken to execute the tool.
Remarks
This information is useful for performance monitoring and optimization.IsSuccess
Gets or sets a value indicating whether the tool execution was successful.Syntax
Property Value
Type:bool
true if the execution was successful; otherwise, false.
Remarks
Success indicates that the tool executed without errors and completed its intended operation, regardless of whether data was found or modified.Metadata
Gets or sets additional metadata about the execution.Syntax
Property Value
Type:System.Collections.Generic.Dictionary<string, object>
A dictionary of metadata key-value pairs.
Remarks
Metadata can include information such as execution time, record counts, caching status, or other operational details.StatusCode
Gets or sets the HTTP status code equivalent for this result.Syntax
Property Value
Type:int
The HTTP status code that best represents this result.
Remarks
This helps clients understand the result in terms of standard HTTP semantics, even when the tool isn’t directly related to HTTP operations.Warnings
Gets or sets warnings that occurred during execution.Syntax
Property Value
Type:System.Collections.Generic.List<string>
A collection of warning messages.
Remarks
Warnings indicate potential issues or notable conditions that didn’t prevent successful execution but may be of interest to users.Methods
AddMetadata
Adds metadata to the result.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
key | string | The metadata key. |
value | object | The metadata value. |
Exceptions
| Exception | Description |
|---|---|
ArgumentException | Thrown when key is null or whitespace. |
AddWarning
Adds a warning to the result.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
warning | string | The warning message. |
Exceptions
| Exception | Description |
|---|---|
ArgumentException | Thrown when warning is null or whitespace. |
Equals Inherited Virtual
Inherited from
objectSyntax
Parameters
| Name | Type | Description |
|---|---|---|
obj | object? | - |
Returns
Type:bool
Equals Inherited
Inherited from
objectSyntax
Parameters
| Name | Type | Description |
|---|---|---|
objA | object? | - |
objB | object? | - |
Returns
Type:bool
Error
Creates an error result with the specified message and code.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
errorMessage | string | The error message. |
errorCode | string? | The error code. |
correlationId | string? | The correlation ID. |
Returns
Type:Microsoft.OData.Mcp.Core.Tools.McpToolResult
An error MCP tool result.
Exceptions
| Exception | Description |
|---|---|
ArgumentException | Thrown when errorMessage is null or whitespace. |
Error
Creates an error result from an exception.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
exception | System.Exception | The exception that occurred. |
correlationId | string? | The correlation ID. |
Returns
Type:Microsoft.OData.Mcp.Core.Tools.McpToolResult
An error MCP tool result.
Exceptions
| Exception | Description |
|---|---|
ArgumentNullException | Thrown when exception is null. |
GetHashCode Inherited Virtual
Inherited from
objectSyntax
Returns
Type:int
GetMetadata
Gets metadata value by key.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
key | string | The metadata key. |
Returns
Type:T?
The metadata value if found and of the correct type; otherwise, the default value.
Type Parameters
T- The type of the metadata value.
GetType Inherited
Inherited from
objectSyntax
Returns
Type:System.Type
MemberwiseClone Inherited
Inherited from
objectSyntax
Returns
Type:object
NotFound
Creates a not found result.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
message | string? | The not found message. |
correlationId | string? | The correlation ID. |
Returns
Type:Microsoft.OData.Mcp.Core.Tools.McpToolResult
A not found MCP tool result.
ReferenceEquals Inherited
Inherited from
objectSyntax
Parameters
| Name | Type | Description |
|---|---|---|
objA | object? | - |
objB | object? | - |
Returns
Type:bool
SetExecutionDuration
Sets the execution duration based on a start time.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
startTime | System.DateTime? | The execution start time. |
Success
Creates a successful result with the specified data.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
data | System.Text.Json.JsonDocument? | The result data. |
correlationId | string? | The correlation ID. |
Returns
Type:Microsoft.OData.Mcp.Core.Tools.McpToolResult
A successful MCP tool result.
Success
Creates a successful result with the specified object data.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
data | object | The data object to serialize to JSON. |
correlationId | string? | The correlation ID. |
Returns
Type:Microsoft.OData.Mcp.Core.Tools.McpToolResult
A successful MCP tool result.
Exceptions
| Exception | Description |
|---|---|
ArgumentNullException | Thrown when data is null. |
ToDictionary
Converts the result to a dictionary for JSON serialization.Syntax
Returns
Type:System.Collections.Generic.Dictionary<string, object?>
A dictionary representation of the result.
ToString Override
Returns a JSON string representation of the result.Syntax
Returns
Type:string
A JSON string representation of the result.
ToString Inherited Virtual
Inherited from
objectSyntax
Returns
Type:string?
Unauthorized
Creates an unauthorized result.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
message | string? | The unauthorized message. |
correlationId | string? | The correlation ID. |
Returns
Type:Microsoft.OData.Mcp.Core.Tools.McpToolResult
An unauthorized MCP tool result.
ValidationError
Creates a validation error result.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
message | string | The validation error message. |
correlationId | string? | The correlation ID. |
Returns
Type:Microsoft.OData.Mcp.Core.Tools.McpToolResult
A validation error MCP tool result.