基于文件的内存MCP服务器
这是在中实现的MCP服务器示例。NET使用 模型上下文协议 C#SDK。它提供了使用基于文件的存储来存储和检索按类型分类的内存的工具。
在当地发展
要从源代码(本地)测试此MCP服务器,而不使用内置的MCP服务器包,您可以将IDE配置为直接使用以下命令运行项目 dotnet run.
{
"servers": {
"MemoryMcpNet": {
"type": "stdio",
"command": "dotnet",
"args": [
"run",
"--project",
"
"
]
}
}
}测试MCP服务器
配置后,您可以使用以下提供的MCP服务器工具 FileMemoryTools:
- 存储内存:将内存存储在指定类别中。
- 参数: - category:内存类型(参见 MemoryCategory 枚举) - memory:要存储的内存内容 - 返回:包含存储内容的确认消息
- 检索内存:从指定类别检索所有内存。
- 参数: - category:内存类型 - 返回:内存项的JSON数组(Id, Content, LastUpdated)
- 删除内存:按类别和ID删除内存。
- 参数: - category:内存类型 - id:要删除的内存的唯一ID - 返回:确认消息(如果已删除)或未找到消息
Copilot聊天中的示例用法:
mcp_memorymcpnet_store_memory: Store a note in the 'Notes' category
mcp_memorymcpnet_retrieve_memory: Retrieve all reminders
mcp_memorymcpnet_remove_memory: Remove memory with ID 5 from 'History'发布到NuGet.org
- 跑
dotnet pack -c Release创建NuGet包 - 发布到NuGet.org
dotnet nuget push bin/Release/*.nupkg --api-key --source https://api.nuget.org/v3/index.json
使用NuGet.org的MCP服务器
一旦MCP服务器包发布到NuGet.org,您就可以在首选IDE中对其进行配置。VS Code和Visual Studio都使用 dnx 命令从NuGet.org下载并安装MCP服务器包。
- VS Code:创建一个
/.vscode/mcp.json文件 - Visual Studio:创建一个
\.mcp.json文件
对于VS Code和Visual Studio,配置文件都使用以下服务器定义:
{
"servers": {
"MemoryMcpNet": {
"type": "stdio",
"command": "dnx",
"args": [
]
}
}
}更多信息
.NET MCP服务器使用 模型上下文协议 C#SDK。有关MCP的更多信息:
有关配置和使用MCP服务器的更多信息,请参阅VS Code或Visual Studio文档:
