Skip to content

Commit 6eaa071

Browse files
committed
Add [McpServerPrompt] support
1 parent 81a54ec commit 6eaa071

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1116
-527
lines changed

Diff for: samples/AspNetCoreSseServer/Program.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
using ModelContextProtocol;
21
using AspNetCoreSseServer;
32

43
var builder = WebApplication.CreateBuilder(args);
5-
builder.Services.AddMcpServer().WithToolsFromAssembly();
4+
builder.Services.AddMcpServer().WithItemsFromAssembly();
65
var app = builder.Build();
76

87
app.MapGet("/", () => "Hello World!");

Diff for: samples/AspNetCoreSseServer/Tools/EchoTool.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace TestServerWithHosting.Tools;
55

6-
[McpServerToolType]
6+
[McpServerType]
77
public static class EchoTool
88
{
99
[McpServerTool, Description("Echoes the input back to the client.")]

Diff for: samples/AspNetCoreSseServer/Tools/SampleLlmTool.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace TestServerWithHosting.Tools;
77
/// <summary>
88
/// This tool uses dependency injection and async method
99
/// </summary>
10-
[McpServerToolType]
10+
[McpServerType]
1111
public static class SampleLlmTool
1212
{
1313
[McpServerTool(Name = "sampleLLM"), Description("Samples from an LLM using MCP's sampling feature")]

Diff for: samples/QuickstartWeatherServer/Program.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
using Microsoft.Extensions.DependencyInjection;
22
using Microsoft.Extensions.Hosting;
3-
using ModelContextProtocol;
43
using System.Net.Http.Headers;
54

65
var builder = Host.CreateEmptyApplicationBuilder(settings: null);
76

87
builder.Services.AddMcpServer()
98
.WithStdioServerTransport()
10-
.WithToolsFromAssembly();
9+
.WithItemsFromAssembly();
1110

1211
builder.Services.AddSingleton(_ =>
1312
{

Diff for: samples/QuickstartWeatherServer/Tools/WeatherTools.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace QuickstartWeatherServer.Tools;
77

8-
[McpServerToolType]
8+
[McpServerType]
99
public static class WeatherTools
1010
{
1111
[McpServerTool, Description("Get weather alerts for a US state.")]

Diff for: samples/TestServerWithHosting/Program.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ModelContextProtocol;
1+
using Microsoft.Extensions.DependencyInjection;
22
using Microsoft.Extensions.Hosting;
33
using Serilog;
44

@@ -19,7 +19,7 @@
1919
builder.Services.AddSerilog();
2020
builder.Services.AddMcpServer()
2121
.WithStdioServerTransport()
22-
.WithToolsFromAssembly();
22+
.WithItemsFromAssembly();
2323

2424
var app = builder.Build();
2525

Diff for: samples/TestServerWithHosting/Tools/EchoTool.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace TestServerWithHosting.Tools;
55

6-
[McpServerToolType]
6+
[McpServerType]
77
public static class EchoTool
88
{
99
[McpServerTool, Description("Echoes the input back to the client.")]

Diff for: samples/TestServerWithHosting/Tools/SampleLlmTool.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace TestServerWithHosting.Tools;
77
/// <summary>
88
/// This tool uses depenency injection and async method
99
/// </summary>
10-
[McpServerToolType]
10+
[McpServerType]
1111
public static class SampleLlmTool
1212
{
1313
[McpServerTool(Name = "sampleLLM"), Description("Samples from an LLM using MCP's sampling feature")]

Diff for: src/ModelContextProtocol/AIContentExtensions.cs

+18
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ public static ChatMessage ToChatMessage(this PromptMessage promptMessage)
2525
};
2626
}
2727

28+
/// <summary>Gets <see cref="PromptMessage"/> instances for the specified <see cref="ChatMessage"/>.</summary>
29+
/// <param name="chatMessage">The message for which to extract its contents as <see cref="PromptMessage"/> instances.</param>
30+
/// <returns>The converted content.</returns>
31+
public static IEnumerable<PromptMessage> ToPromptMessages(this ChatMessage chatMessage)
32+
{
33+
Throw.IfNull(chatMessage);
34+
35+
Role r = chatMessage.Role == ChatRole.User ? Role.User : Role.Assistant;
36+
37+
foreach (var content in chatMessage.Contents)
38+
{
39+
if (content is TextContent or DataContent)
40+
{
41+
yield return new PromptMessage { Role = r, Content = content.ToContent() };
42+
}
43+
}
44+
}
45+
2846
/// <summary>Creates a new <see cref="AIContent"/> from the content of a <see cref="Content"/>.</summary>
2947
/// <param name="content">The <see cref="Content"/> to convert.</param>
3048
/// <returns>The created <see cref="AIContent"/>.</returns>

Diff for: src/ModelContextProtocol/Client/McpClient.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using ModelContextProtocol.Configuration;
2-
using ModelContextProtocol.Logging;
1+
using ModelContextProtocol.Logging;
32
using ModelContextProtocol.Protocol.Messages;
43
using ModelContextProtocol.Protocol.Transport;
54
using ModelContextProtocol.Protocol.Types;

Diff for: src/ModelContextProtocol/Client/McpClientFactory.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Globalization;
22
using System.Runtime.InteropServices;
3-
using ModelContextProtocol.Configuration;
43
using ModelContextProtocol.Logging;
54
using ModelContextProtocol.Protocol.Transport;
65
using ModelContextProtocol.Utils;

Diff for: src/ModelContextProtocol/Configuration/DefaultMcpServerBuilder.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using ModelContextProtocol.Utils;
2-
using Microsoft.Extensions.DependencyInjection;
32

4-
namespace ModelContextProtocol.Configuration;
3+
namespace Microsoft.Extensions.DependencyInjection;
54

65
/// <summary>
76
/// Default implementation of <see cref="IMcpServerBuilder"/>.
87
/// </summary>
9-
internal class DefaultMcpServerBuilder : IMcpServerBuilder
8+
internal sealed class DefaultMcpServerBuilder : IMcpServerBuilder
109
{
1110
/// <inheritdoc/>
1211
public IServiceCollection Services { get; }

Diff for: src/ModelContextProtocol/Configuration/IMcpServerBuilder.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using ModelContextProtocol.Server;
2-
using Microsoft.Extensions.DependencyInjection;
32

4-
namespace ModelContextProtocol.Configuration;
3+
namespace Microsoft.Extensions.DependencyInjection;
54

65
/// <summary>
76
/// Builder for configuring <see cref="IMcpServer"/> instances.

Diff for: src/ModelContextProtocol/Configuration/McpServerBuilderExtensions.Handler.cs

-143
This file was deleted.

Diff for: src/ModelContextProtocol/Configuration/McpServerBuilderExtensions.Tools.cs

-100
This file was deleted.

0 commit comments

Comments
 (0)