microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
31d1aa2aae7f45f1943ebae04ce8c66899e89e48

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

External/Microsoft.Teams.Plugins.AspNetCore.Mcp/McpPlugin.cs

76lines · modecode

1using System.Diagnostics.CodeAnalysis;
2
3using Microsoft.AspNetCore.Builder;
4using Microsoft.Extensions.DependencyInjection;
5using Microsoft.Teams.Api;
6using Microsoft.Teams.Api.Activities;
7using Microsoft.Teams.Apps;
8using Microsoft.Teams.Apps.Plugins;
9using Microsoft.Teams.Common.Logging;
10using Microsoft.Teams.Plugins.AspNetCore.DevTools;
11
12namespace 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)]
19public 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}