Skip to content

Commit e9caa71

Browse files
committed
Add Title to a bunch of types
1 parent a29ddc7 commit e9caa71

38 files changed

+407
-139
lines changed

samples/EverythingServer/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ await ctx.Server.SampleAsync([
8686
var @ref = @params.Ref;
8787
var argument = @params.Argument;
8888

89-
if (@ref.Type == "ref/resource")
89+
if (@ref is ResourceTemplateReference rtr)
9090
{
91-
var resourceId = @ref.Uri?.Split("/").Last();
91+
var resourceId = rtr.Uri?.Split("/").Last();
9292

9393
if (resourceId is null)
9494
{
@@ -103,7 +103,7 @@ await ctx.Server.SampleAsync([
103103
};
104104
}
105105

106-
if (@ref.Type == "ref/prompt")
106+
if (@ref is PromptReference pr)
107107
{
108108
if (!exampleCompletions.TryGetValue(argument.Name, out IEnumerable<string>? value))
109109
{
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace System.Diagnostics.CodeAnalysis;
5+
6+
/// <summary>Specifies the syntax used in a string.</summary>
7+
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
8+
internal sealed class StringSyntaxAttribute : Attribute
9+
{
10+
/// <summary>Initializes the <see cref="StringSyntaxAttribute"/> with the identifier of the syntax used.</summary>
11+
/// <param name="syntax">The syntax identifier.</param>
12+
public StringSyntaxAttribute(string syntax)
13+
{
14+
Syntax = syntax;
15+
Arguments = Array.Empty<object?>();
16+
}
17+
18+
/// <summary>Initializes the <see cref="StringSyntaxAttribute"/> with the identifier of the syntax used.</summary>
19+
/// <param name="syntax">The syntax identifier.</param>
20+
/// <param name="arguments">Optional arguments associated with the specific syntax employed.</param>
21+
public StringSyntaxAttribute(string syntax, params object?[] arguments)
22+
{
23+
Syntax = syntax;
24+
Arguments = arguments;
25+
}
26+
27+
/// <summary>Gets the identifier of the syntax used.</summary>
28+
public string Syntax { get; }
29+
30+
/// <summary>Optional arguments associated with the specific syntax employed.</summary>
31+
public object?[] Arguments { get; }
32+
33+
/// <summary>The syntax identifier for strings containing composite formats for string formatting.</summary>
34+
public const string CompositeFormat = nameof(CompositeFormat);
35+
36+
/// <summary>The syntax identifier for strings containing date format specifiers.</summary>
37+
public const string DateOnlyFormat = nameof(DateOnlyFormat);
38+
39+
/// <summary>The syntax identifier for strings containing date and time format specifiers.</summary>
40+
public const string DateTimeFormat = nameof(DateTimeFormat);
41+
42+
/// <summary>The syntax identifier for strings containing <see cref="Enum"/> format specifiers.</summary>
43+
public const string EnumFormat = nameof(EnumFormat);
44+
45+
/// <summary>The syntax identifier for strings containing <see cref="Guid"/> format specifiers.</summary>
46+
public const string GuidFormat = nameof(GuidFormat);
47+
48+
/// <summary>The syntax identifier for strings containing JavaScript Object Notation (JSON).</summary>
49+
public const string Json = nameof(Json);
50+
51+
/// <summary>The syntax identifier for strings containing numeric format specifiers.</summary>
52+
public const string NumericFormat = nameof(NumericFormat);
53+
54+
/// <summary>The syntax identifier for strings containing regular expressions.</summary>
55+
public const string Regex = nameof(Regex);
56+
57+
/// <summary>The syntax identifier for strings containing time format specifiers.</summary>
58+
public const string TimeOnlyFormat = nameof(TimeOnlyFormat);
59+
60+
/// <summary>The syntax identifier for strings containing <see cref="TimeSpan"/> format specifiers.</summary>
61+
public const string TimeSpanFormat = nameof(TimeSpanFormat);
62+
63+
/// <summary>The syntax identifier for strings containing URIs.</summary>
64+
public const string Uri = nameof(Uri);
65+
66+
/// <summary>The syntax identifier for strings containing XML.</summary>
67+
public const string Xml = nameof(Xml);
68+
}

src/ModelContextProtocol.Core/Client/McpClient.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Microsoft.Extensions.Logging;
22
using ModelContextProtocol.Protocol;
3-
using System.Diagnostics;
43
using System.Text.Json;
54

65
namespace ModelContextProtocol.Client;

src/ModelContextProtocol.Core/Client/McpClientExtensions.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -639,11 +639,6 @@ public static ValueTask<CompleteResult> CompleteAsync(this IMcpClient client, Re
639639
Throw.IfNull(reference);
640640
Throw.IfNullOrWhiteSpace(argumentName);
641641

642-
if (!reference.Validate(out string? validationMessage))
643-
{
644-
throw new ArgumentException($"Invalid reference: {validationMessage}", nameof(reference));
645-
}
646-
647642
return client.SendRequestAsync(
648643
RequestMethods.CompletionComplete,
649644
new()

src/ModelContextProtocol.Core/Client/McpClientPrompt.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ internal McpClientPrompt(IMcpClient client, Prompt prompt)
4444
/// <summary>Gets the name of the prompt.</summary>
4545
public string Name => ProtocolPrompt.Name;
4646

47+
/// <summary>Gets the title of the prompt.</summary>
48+
public string? Title => ProtocolPrompt.Title;
49+
4750
/// <summary>Gets a description of the prompt.</summary>
4851
public string? Description => ProtocolPrompt.Description;
4952

src/ModelContextProtocol.Core/Client/McpClientResource.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ internal McpClientResource(IMcpClient client, Resource resource)
4242
/// <summary>Gets the name of the resource.</summary>
4343
public string Name => ProtocolResource.Name;
4444

45+
/// <summary>Gets the title of the resource.</summary>
46+
public string? Title => ProtocolResource.Title;
47+
4548
/// <summary>Gets a description of the resource.</summary>
4649
public string? Description => ProtocolResource.Description;
4750

src/ModelContextProtocol.Core/Client/McpClientResourceTemplate.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ internal McpClientResourceTemplate(IMcpClient client, ResourceTemplate resourceT
4242
/// <summary>Gets the name of the resource template.</summary>
4343
public string Name => ProtocolResourceTemplate.Name;
4444

45+
/// <summary>Gets the title of the resource template.</summary>
46+
public string? Title => ProtocolResourceTemplate.Title;
47+
4548
/// <summary>Gets a description of the resource template.</summary>
4649
public string? Description => ProtocolResourceTemplate.Description;
4750

src/ModelContextProtocol.Core/Client/McpClientTool.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ internal McpClientTool(
6868
/// <inheritdoc/>
6969
public override string Name => _name;
7070

71+
/// <summary>Gets the tool's title.</summary>
72+
public string? Title => ProtocolTool.Title ?? ProtocolTool.Annotations?.Title;
73+
7174
/// <inheritdoc/>
7275
public override string Description => _description;
7376

src/ModelContextProtocol.Core/McpJsonUtilities.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using Microsoft.Extensions.AI;
22
using ModelContextProtocol.Protocol;
3-
using ModelContextProtocol.Server;
43
using System.Diagnostics.CodeAnalysis;
5-
using System.Reflection;
64
using System.Text.Json;
75
using System.Text.Json.Serialization;
86
using System.Text.Json.Serialization.Metadata;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace ModelContextProtocol.Protocol;
4+
5+
/// <summary>Provides a base interface for metadata with name (identifier) and title (display name) properties.</summary>
6+
public interface IBaseMetadata
7+
{
8+
/// <summary>
9+
/// Gets or sets the unique identifier for this item.
10+
/// </summary>
11+
[JsonPropertyName("name")]
12+
string Name { get; set; }
13+
14+
/// <summary>
15+
/// Gets or sets a title.
16+
/// </summary>
17+
/// <remarks>
18+
/// This is intended for UI and end-user contexts. It is optimized to be human-readable and easily understood,
19+
/// even by those unfamiliar with domain-specific terminology.
20+
/// If not provided, <see cref="Name"/> may be used for display (except for tools, where <see cref="ToolAnnotations.Title"/>, if present,
21+
/// should be given precedence over using <see cref="Name"/>).
22+
/// </remarks>
23+
[JsonPropertyName("title")]
24+
string? Title { get; set; }
25+
}

src/ModelContextProtocol.Core/Protocol/Implementation.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@ namespace ModelContextProtocol.Protocol;
1717
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for details.
1818
/// </para>
1919
/// </remarks>
20-
public class Implementation
20+
public class Implementation : IBaseMetadata
2121
{
22-
/// <summary>
23-
/// Gets or sets the name of the implementation.
24-
/// </summary>
25-
/// <remarks>
26-
/// This is typically the name of the client or server library/application.
27-
/// </remarks>
22+
/// <inheritdoc />
2823
[JsonPropertyName("name")]
2924
public required string Name { get; set; }
3025

26+
/// <inheritdoc />
27+
[JsonPropertyName("title")]
28+
public string? Title { get; set; }
29+
3130
/// <summary>
3231
/// Gets or sets the version of the implementation.
3332
/// </summary>

src/ModelContextProtocol.Core/Protocol/Prompt.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,16 @@ namespace ModelContextProtocol.Protocol;
88
/// <remarks>
99
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for details.
1010
/// </remarks>
11-
public class Prompt
11+
public class Prompt : IBaseMetadata
1212
{
13+
/// <inheritdoc />
14+
[JsonPropertyName("name")]
15+
public required string Name { get; set; }
16+
17+
/// <inheritdoc />
18+
[JsonPropertyName("title")]
19+
public string? Title { get; set; }
20+
1321
/// <summary>
1422
/// Gets or sets a list of arguments that this prompt accepts for templating and customization.
1523
/// </summary>
@@ -41,10 +49,4 @@ public class Prompt
4149
/// </remarks>
4250
[JsonPropertyName("description")]
4351
public string? Description { get; set; }
44-
45-
/// <summary>
46-
/// Gets or sets the name of the prompt.
47-
/// </summary>
48-
[JsonPropertyName("name")]
49-
public string Name { get; set; } = string.Empty;
5052
}

src/ModelContextProtocol.Core/Protocol/PromptArgument.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ namespace ModelContextProtocol.Protocol;
1515
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for details.
1616
/// </para>
1717
/// </remarks>
18-
public class PromptArgument
18+
public class PromptArgument : IBaseMetadata
1919
{
20-
/// <summary>
21-
/// Gets or sets the name of the argument used for referencing in prompt templates.
22-
/// </summary>
20+
/// <inheritdoc />
2321
[JsonPropertyName("name")]
24-
public string Name { get; set; } = string.Empty;
22+
public required string Name { get; set; }
23+
24+
/// <inheritdoc />
25+
[JsonPropertyName("title")]
26+
public string? Title { get; set; }
2527

2628
/// <summary>
2729
/// Gets or sets a human-readable description of the argument's purpose and expected values.

0 commit comments

Comments
 (0)