microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
External/Microsoft.Teams.Plugins.AspNetCore.Mcp/McpPlugin.cs
76lines · modecode
| 1 | using System.Diagnostics.CodeAnalysis; |
| 2 | |
| 3 | using Microsoft.AspNetCore.Builder; |
| 4 | using Microsoft.Extensions.DependencyInjection; |
| 5 | using Microsoft.Teams.Api; |
| 6 | using Microsoft.Teams.Api.Activities; |
| 7 | using Microsoft.Teams.Apps; |
| 8 | using Microsoft.Teams.Apps.Plugins; |
| 9 | using Microsoft.Teams.Common.Logging; |
| 10 | using Microsoft.Teams.Plugins.AspNetCore.DevTools; |
| 11 | |
| 12 | namespace Microsoft.Teams.Plugins.AspNetCore.Mcp; |
| 13 | |
| 14 | [Plugin( |
| 15 | "High-level MCP server that provides a simpler API for working with resources, tools, and prompts.", |
| 16 | "For advanced usage (like sending notifications or setting custom request handlers),", |
| 17 | "use the underlying Server instance available via the server property." |
| 18 | )] |
| 19 | public class McpPlugin : IAspNetCorePlugin |
| 20 | { |
| 21 | [AllowNull] |
| 22 | [Dependency] |
| 23 | public ILogger Logger { get; set; } |
| 24 | |
| 25 | public event IPlugin.ErrorEventHandler ErrorEvent = (_, _) => Task.Run(() => { }); |
| 26 | |
| 27 | private readonly IServiceProvider _services; |
| 28 | private readonly DevToolsPlugin? _devtools; |
| 29 | |
| 30 | public McpPlugin(IServiceProvider provider) |
| 31 | { |
| 32 | _services = provider; |
| 33 | _devtools = provider.GetService<DevToolsPlugin>(); |
| 34 | } |
| 35 | |
| 36 | public IApplicationBuilder Configure(IApplicationBuilder builder) |
| 37 | { |
| 38 | builder.UseRouting(); |
| 39 | return builder.UseEndpoints(endpoints => endpoints.MapMcp("mcp")); |
| 40 | } |
| 41 | |
| 42 | public Task OnInit(IApp app, CancellationToken cancellationToken = default) |
| 43 | { |
| 44 | return Task.Run(() => { }); |
| 45 | } |
| 46 | |
| 47 | public Task OnStart(IApp app, CancellationToken cancellationToken = default) |
| 48 | { |
| 49 | return Task.Run(() => Logger.Debug("OnStart")); |
| 50 | } |
| 51 | |
| 52 | public Task OnError(IApp app, IPlugin? plugin, Exception exception, IContext<IActivity>? context, CancellationToken cancellationToken = default) |
| 53 | { |
| 54 | return Task.Run(() => Logger.Debug("OnError")); |
| 55 | } |
| 56 | |
| 57 | public Task OnActivity(IApp app, IContext<IActivity> context) |
| 58 | { |
| 59 | return Task.Run(() => Logger.Debug("OnActivity")); |
| 60 | } |
| 61 | |
| 62 | public Task OnActivityResponse(IApp app, Response? response, IContext<IActivity> context) |
| 63 | { |
| 64 | return Task.Run(() => Logger.Debug("OnActivityResponse")); |
| 65 | } |
| 66 | |
| 67 | public Task OnActivitySent(IApp app, IActivity activity, IContext<IActivity> context) |
| 68 | { |
| 69 | return Task.Run(() => Logger.Debug("OnActivitySent")); |
| 70 | } |
| 71 | |
| 72 | public Task OnActivitySent(IApp app, ISenderPlugin sender, IActivity activity, ConversationReference reference, CancellationToken cancellationToken = default) |
| 73 | { |
| 74 | return Task.Run(() => Logger.Debug("OnActivitySent")); |
| 75 | } |
| 76 | } |