Skip to content

Commit 9ef5751

Browse files
committed
Add [McpServerPrompt] support
1 parent 81a54ec commit 9ef5751

File tree

49 files changed

+1115
-526
lines changed

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

+1115
-526
lines changed

samples/AspNetCoreSseServer/Program.cs

Lines changed: 1 addition & 2 deletions
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!");

samples/AspNetCoreSseServer/Tools/EchoTool.cs

Lines changed: 1 addition & 1 deletion
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.")]

samples/AspNetCoreSseServer/Tools/SampleLlmTool.cs

Lines changed: 1 addition & 1 deletion
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")]

samples/QuickstartWeatherServer/Program.cs

Lines changed: 1 addition & 2 deletions
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
{

samples/QuickstartWeatherServer/Tools/WeatherTools.cs

Lines changed: 1 addition & 1 deletion
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.")]

samples/TestServerWithHosting/Program.cs

Lines changed: 2 additions & 2 deletions
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

samples/TestServerWithHosting/Tools/EchoTool.cs

Lines changed: 1 addition & 1 deletion
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.")]

samples/TestServerWithHosting/Tools/SampleLlmTool.cs

Lines changed: 1 addition & 1 deletion
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")]

src/ModelContextProtocol/AIContentExtensions.cs

Lines changed: 18 additions & 0 deletions
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>

src/ModelContextProtocol/Client/McpClient.cs

Lines changed: 1 addition & 2 deletions
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;

0 commit comments

Comments
 (0)