You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
1.4 KiB
Markdown

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

客户端调用MCP服务
==============
# 调用Stdio类型的MCP服务
## 调用本质:客户端在内部使用命令行(Windows下为cmd.exe),调用MCP服务控制台程序的可执行文件。
windows下类似于
```cmd
cmd.exe /c "D://目录/McpServer.exe"
```
## 注意事项
1. .NET 开发的Stio程序客户端调用时一种是执行命令换成cmd,参数为 Studio类型的mcp服务程序可执行文件(带路径),另一种是,执行命令为 Dotnet参数为 Dotnet的命令及参数(dotnet 路径/mcpServer.dll或者dotnet run --project xxx.csproj)
2. 调用服务后很可能MCP服务进程没有自动退出还驻留在系统进程中造成后续调用失败特别是在开发与调试阶段这种情况更常见。调用失败时一定要先检查MCP服务进程是否还在运行如果还在运行先结束进程。
3. 可以使用`MCP C# SDK`中,提供的 `IMcpClient` 直接调用MCP服务相关功能(连接、列举工具、调用工具等); 方便开发与调试,但不建议在生产环境中使用;
4. 生产环境,使用 `Microsoft.Extensions.AI`、`Microsoft.SemanticKernel`等AI库进行调用
# 调用SSE类型的MCP服务
## 调用本质客户端发送http请求MCP服务程序响应内容只不过服务端使用SSE数据交换使用Json Patch格式。这一切源于MCP协议。
## 注意事项: