diff --git a/ModelContextProtocol.slnx b/ModelContextProtocol.slnx index e4fd42fe..d34453bb 100644 --- a/ModelContextProtocol.slnx +++ b/ModelContextProtocol.slnx @@ -9,6 +9,7 @@ + diff --git a/samples/GetSessionId/GetSessionId.csproj b/samples/GetSessionId/GetSessionId.csproj new file mode 100644 index 00000000..a7eae26e --- /dev/null +++ b/samples/GetSessionId/GetSessionId.csproj @@ -0,0 +1,13 @@ + + + + net9.0 + enable + enable + + + + + + + diff --git a/samples/GetSessionId/GetSessionId.http b/samples/GetSessionId/GetSessionId.http new file mode 100644 index 00000000..0fdfb514 --- /dev/null +++ b/samples/GetSessionId/GetSessionId.http @@ -0,0 +1,6 @@ +@GetSessionId_HostAddress = http://localhost:5002 + +GET {{GetSessionId_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/samples/GetSessionId/GetSessionIdTool.cs b/samples/GetSessionId/GetSessionIdTool.cs new file mode 100644 index 00000000..02401651 --- /dev/null +++ b/samples/GetSessionId/GetSessionIdTool.cs @@ -0,0 +1,16 @@ +using ModelContextProtocol.Server; +using System.ComponentModel; + +[McpServerToolType] +public class GetSessionIdTool +{ + public GetSessionIdTool() + { + } + + [McpServerTool(Name = "get_session"), Description("Returns current session id")] + public async Task GetSession(IMcpServer mcpServer) + { + return mcpServer.SessionId; + } +} diff --git a/samples/GetSessionId/Program.cs b/samples/GetSessionId/Program.cs new file mode 100644 index 00000000..0bcca2b3 --- /dev/null +++ b/samples/GetSessionId/Program.cs @@ -0,0 +1,15 @@ +using Microsoft.Extensions.DependencyInjection; +using ModelContextProtocol.Server; + +var builder = WebApplication.CreateBuilder(args); + +builder.Services + .AddMcpServer() + .WithHttpTransport() + .WithToolsFromAssembly(); + +var app = builder.Build(); + +app.MapMcp("/mcp"); + +app.Run(); diff --git a/samples/GetSessionId/Properties/launchSettings.json b/samples/GetSessionId/Properties/launchSettings.json new file mode 100644 index 00000000..056a519e --- /dev/null +++ b/samples/GetSessionId/Properties/launchSettings.json @@ -0,0 +1,14 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "http://localhost:5002", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/samples/GetSessionId/appsettings.Development.json b/samples/GetSessionId/appsettings.Development.json new file mode 100644 index 00000000..0c208ae9 --- /dev/null +++ b/samples/GetSessionId/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/samples/GetSessionId/appsettings.json b/samples/GetSessionId/appsettings.json new file mode 100644 index 00000000..10f68b8c --- /dev/null +++ b/samples/GetSessionId/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}