MCP Client
You are able to leverage other MCP servers that expose tools via the SSE protocol as part of your application. This allows your AI agent to use remote tools to accomplish tasks.
Install it to your application:
dotnet add package Microsoft.Teams.Plugins.External.McpClient --prerelease
Take a look at Function calling to understand how the ChatPrompt
leverages tools to enhance the LLM's capabilities. MCP extends this functionality by allowing remote tools, that may or may not be developed or maintained by you, to be used by your application.
Remote MCP Server​
The first thing that's needed is access to a remote MCP server. MCP Servers (at present) come using two main types protocols:
- StandardIO - This is a local MCP server, which runs on your machine. An MCP client may connect to this server, and use standard input and outputs to communicate with it. Since our application is running remotely, this is not something that we want to use
- SSE - This is a remote MCP server. An MCP client may send it requests and the server responds in the expected MCP protocol.
For hooking up to your a valid SSE server, you will need to know the URL of the server, and if applicable, and keys that must be included as part of the header.
MCP Client Plugin​
The MCPClientPlugin
(from Microsoft.Teams.Plugins.External.McpClient
package) integrates directly with the ChatPrompt
object as a plugin. When the ChatPrompt
's send
function is called, it calls the external MCP server and loads up all the tools that are available to it.
Once loaded, it treats these tools like any functions that are available to the ChatPrompt
object. If the LLM then decides to call one of these remote MCP tools, the MCP Client plugin will call the remote MCP server and return the result back to the LLM. The LLM can then use this result in its response.
- Controller
- Minimal
// DocsPrompt.cs
using Microsoft.Teams.AI;
using Microsoft.Teams.AI.Annotations;
using Microsoft.Teams.Plugins.External.McpClient;
[Prompt]
[Prompt.Description("helpful assistant")]
[Prompt.Instructions(
"You are a helpful assistant that can help answer questions using Microsoft docs.",
"You MUST use tool calls to do all your work."
)]
public class DocsPrompt(McpClientPlugin mcpClientPlugin)
{
[ChatPlugin]
public readonly IChatPlugin Plugin = mcpClientPlugin;
}
// Controller.cs
using Microsoft.Teams.AI.Models.OpenAI;
using Microsoft.Teams.Api.Activities;
using Microsoft.Teams.Apps;
using Microsoft.Teams.Apps.Activities;
using Microsoft.Teams.Apps.Annotations;
[TeamsController]
public class TeamsController(Func<OpenAIChatPrompt> _promptFactory)
{
[Message]
public async Task OnMessage(IContext<MessageActivity> context)
{
await context.Send(new TypingActivity());
var prompt = _promptFactory();
var result = await prompt.Send(context.Activity.Text);
await context.Send(result.Content);
}
}
// Program.cs
using Microsoft.Teams.AI.Models.OpenAI.Extensions;
using Microsoft.Teams.Plugins.AspNetCore.Extensions;
using Microsoft.Teams.Plugins.External.McpClient;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddTransient<TeamsController>().AddHttpContextAccessor();
builder.Services.AddSingleton((sp) => new McpClientPlugin().UseMcpServer("https://learn.microsoft.com/api/mcp"));
builder.AddTeams().AddOpenAI<DocsPrompt>();
var app = builder.Build();
app.UseTeams();
app.Run();
using Microsoft.Teams.AI.Models.OpenAI;
using Microsoft.Teams.AI.Prompts;
using Microsoft.Teams.Api.Activities;
using Microsoft.Teams.Apps;
using Microsoft.Teams.Apps.Activities;
using Microsoft.Teams.Plugins.AspNetCore.Extensions;
using Microsoft.Teams.Plugins.External.McpClient;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.AddTeams();
WebApplication webApp = builder.Build();
OpenAIChatPrompt prompt = new(
new OpenAIChatModel(
model: "gpt-4o",
apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY")!),
new ChatPromptOptions()
.WithDescription("helpful assistant")
.WithInstructions(
"You are a helpful assistant that can help answer questions using Microsoft docs.",
"You MUST use tool calls to do all your work.")
);
prompt.Plugin(new McpClientPlugin().UseMcpServer("https://learn.microsoft.com/api/mcp"));
App app = webApp.UseTeams();
app.OnMessage(async context =>
{
await context.Send(new TypingActivity());
var result = await prompt.Send(context.Activity.Text);
await context.Send(result.Content);
});
webApp.Run();
Custom Headers​
Some MCP servers may require custom headers to be sent as part of the request. You can customize the headers when calling the UseMcpServer
function:
new McpClientPlugin()
.UseMcpServer("https://learn.microsoft.com/api/mcp",
new McpClientPluginParams()
{
HeadersFactory = () => new Dictionary<string, string>()
{ { "HEADER_KEY", "HEADER_VALUE" } }
}
);
In this example, we augment the ChatPrompt
with a a remote MCP Server.
Feel free to build an MCP Server in a different agent using the MCP Server Guide. Or you can quickly set up an MCP server using Azure Functions.