关于 mpc-csharp-semantickernel
mpc-csharp-semantickernel 是一个已停止维护的示例,展示 Microsoft Semantic Kernel、OpenAI 与官方 C# MCP SDK 的用法。它提供可调用邮件工具的 Web 聊天端点,收件人通过代码配置。
主要功能
- 01Semantic Kernel 与 OpenAI 集成示例
- 02使用官方 C# MCP SDK
- 03配置收件人的邮件工具
- 04用于发送请求的 Web 聊天端点
适用场景
- 01了解 C# Semantic Kernel 与 MCP 示例
- 02测试调用邮件工具的聊天请求
MCP 相关
该示例包含一个使用官方 C# SDK 构建的 MCP 服务端。其 Web 应用使用 Semantic Kernel 和 OpenAI 处理可调用邮件工具的聊天请求。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
$${\color{red}此 \space 仓库 \space 将 \space 不再 \space 维护。 \space 它 \space 只是 \space 一个 \space 快速 \space 示例。}$$
mpc-csharp-semantickernel
Microsoft Semantic Kernel 与 OpenAI 以及官方 Model Context Protocol C# SDK 的使用示例。该 SDK 可在 https://github.com/modelcontextprotocol/csharp-sdk 找到。
前置条件
一个 SMTP 邮件服务器(用于 EmailTools) 一个 OpenAI API 密钥
如何运行示例
- 使用 OpenAI Developer Dashboard 获取 API 密钥。
- 填写各个独立项目的 appsettings。
- 可发送邮件的电子邮件地址以字典形式硬编码在 Tools/EmailTool.cs 中。请使用你的电子邮件列表更新该字典。也可以将其设为配置项。
- 运行项目。默认的 launchSettings 设置为 http://localhost:5109
Appsettings
WebAppMCPPoc 项目
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"OpenAI": {
"ApiKey": "<yourApiKey>",
"ChatModelId" : "gpt-4o-mini"
}
}
MCPServer 项目
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"EmailSettings": {
"SMTPServer": {
"MailPort": "465",
"MailServer": "<yourserver.com>",
"Sender": "<[email protected]>",
"SenderName": "<AIEmailSender>",
"Password": "<EmailPassword>",
"Username": "<EmailUsername>"
}
}
}
发送请求:
你可以使用 postman 之类的工具发送请求。
请求示例:
POST https://localhost:7113/chat
请求体:{ "text": "send and email toaFriend and tell him that you are an ai in 250 words. Tell him you're using C# to do this.."}
将 {someone} 替换为你已添加到 EmailTool 邮件字典中的姓名。
private static readonly Dictionary<string, string> emails = new Dictionary<string, string>
{
{ "example", "[email protected]" },
{ "aFriend", "[email protected]" }
};
许可证
本项目采用 MIT 许可证。
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。