DMCPServer 是一个用 Delphi 开发的主控协议服务器。
安装使用的是 boss install 命令:
boss install github.com/Daniel09Fernandes/DMCPServer
| 协议 | 支持 |
|---|---|
| HTTP | ✅ |
| STDIO | ✅ |
var
lCallbackGetWeather : TMCPAction;
begin
lCallbackGetWeather :=
procedure(var Params: TJSONObject; out Result: TDMCPCallToolsResult; out Error: TDMCPCallToolsContent)
var
Location: string;
EnableLog: Boolean;
WeatherService: IWeatherService;
WeatherData: string;
begin
try
try
// 提取参数
Location := Params.GetParam('location');
EnableLog := Params.GetParam('EnableLog', trBool);
// 验证必需参数
if Location.Trim = '' then
raise Exception.Create('需要位置参数');
WeatherService := TMockWeatherService.Create;
WeatherData := WeatherService.GetWeatherData(Location);
if EnableLog then
TDMCPServer.WriteToLog(Format('请求了 %s 的天气数据', [Location]));
// 组装结果 - 不需要手动释放内存,会自动处理。
Result := TDMCPCallToolsResult.Create;
Result.Content.AddRange(TDMCPCallToolsContent.Create(ptText, WeatherData));
Error := nil;
finally
Params.Free;
end;
except
on E: Exception do
begin
// 处理异常。默认行为是返回错误信息。
Error := TDMCPCallToolsContent.Create(ptText,
'天气服务错误: ' + E.Message);
TDMCPServer.WriteToLog('获取天气时出错: ' + E.Message);
Result := nil;
end;
end;
end;
end;
var
lDMCP: IDMCPServerRegister;
begin
lDMCP := TDMCPServerRegister.New
.SetLogs(True); // 设置日志请求
lDMCP
.RegisterAction('get_weather', '获取当前天气信息', lCallbackGetWeather)
.ServerInfo
.SetServerName('DinosMCPServer')
.SetVersion('0.1.0')
.Tools(TMCPServerTools.New
.SetName('get_weather')
.InputSchema
.SetType(ptObject)
.SetProperties('location', ptString)
.SetProperties('Conditions', ptString)
.SetProperties('EnableLog', ptBoolean)
.SetRequired(['location'])
.SetAdditionalProperties(False)
.&End);
lDMCP.Run;
end;
<img width="40" height="40" alt="image" src="https://gips3.baidu.com/it/u=820598116,180599806&fm=3081&app=3081&f=PNG?w=256&h=256" /> 为了向 LLM 内存添加更多资源以供 MCP 使用
.ServerInfo
.SetServerName('DinosMCPServer')
.SetVersion('0.1.0')
.Resources(TMCPServerResources.New
.SetUri('file:///C:/Users/danie/Downloads/teste/fatura-exemplo.csv')
.SetName('创建销售订单的模型')
.SetDescription('用于创建销售订单的标准预算模板。'))
访问开发者配置并编辑配置
<img width="364" height="167" alt="image" src="https://gips0.baidu.com/it/u=781846586,3562311589&fm=3081&app=3081&f=PNG?w=364&h=167" /><br>
<img width="945" height="685" alt="image" src="https://gips2.baidu.com/it/u=1985872463,2825959057&fm=3081&app=3081&f=PNG?w=945&h=685" /><br>
在 mcpServers 节点上附加您的 MCPServer(STDIO)
<img width="713" height="283" alt="image" src="https://gips2.baidu.com/it/u=155828883,3522282359&fm=3081&app=3081&f=PNG?w=713&h=283" /><br>
对于 HTTP:
<img width="398" height="604" alt="image" src="https://gips1.baidu.com/it/u=138939261,3998640506&fm=3081&app=3081&f=PNG?w=398&h=604" />📖 查看完整的文档:DMCPServer-docs
PIX:
<img src="https://gips2.baidu.com/it/u=2496460534,1617650200&fm=3081&app=3081&f=PNG?w=802&h=643" width="300" height="300">