Table of Contents

Class Reference

Namespace
ModelContextProtocol.Protocol
Assembly
ModelContextProtocol.Core.dll

Represents a reference to a resource or prompt in the Model Context Protocol.

public class Reference
Inheritance
Reference
Inherited Members

Remarks

A Reference object identifies either a resource or a prompt:

  • For resource references, set Type to "ref/resource" and provide the Uri property.
  • For prompt references, set Type to "ref/prompt" and provide the Name property.

References are commonly used with CompleteAsync(IMcpClient, Reference, string, string, CancellationToken) to request completion suggestions for arguments, and with other methods that need to reference resources or prompts.

See the schema for details.

Properties

Name

Gets or sets the name of the prompt or prompt template.

[JsonPropertyName("name")]
public string? Name { get; set; }

Property Value

string

Type

Gets or sets the type of content.

[JsonPropertyName("type")]
public string Type { get; set; }

Property Value

string

Remarks

This can be "ref/resource" or "ref/prompt".

Uri

Gets or sets the URI or URI template of the resource.

[JsonPropertyName("uri")]
public string? Uri { get; set; }

Property Value

string

Methods

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

Validate(out string?)

Validates the reference object to ensure it contains the required properties for its type.

public bool Validate(out string? validationMessage)

Parameters

validationMessage string

When this method returns false, contains a message explaining why validation failed; otherwise, null.

Returns

bool

True if the reference is valid; otherwise, false.

Remarks

For "ref/resource" type, the Uri property must not be null or empty. For "ref/prompt" type, the Name property must not be null or empty.