MCP Server
在 Delphi 中构建 Model Context Protocol (MCP) 服务器。向 AI 应用程序暴露工具、资源和提示词。
在 Delphi 中构建 Model Context Protocol (MCP) 服务器。向 AI 应用程序暴露工具、资源和提示词。
将自定义工具、提示词和资源暴露给任意支持 MCP 的 LLM 客户端。基于 sgcWebSockets HTTP 服务器托管带有 HTTP 和 HTTP Streamable 传输的 JSON-RPC 端点。
TsgcWSAPIServer_MCP
Model Context Protocol server
Windows, macOS, Linux, iOS, Android
Enterprise(AI 附加模块)
附加到 HTTP 服务器,填写 ServerInfo,挂接 OnMCPRequest* 处理程序,设置 Active := True。
uses
sgcAI_MCP_Server, sgcAI_MCP_Classes;
var
MCP: TsgcWSAPIServer_MCP;
begin
MCP := TsgcWSAPIServer_MCP.Create(nil);
MCP.MCPOptions.HttpOptions.Port := 8080;
MCP.MCPOptions.ServerInfo.Name := 'sgc-mcp-server';
MCP.MCPOptions.ServerInfo.Title := 'Weather MCP';
MCP.MCPOptions.ServerInfo.Version := '1.0.0';
// Lifecycle + incoming request handlers
MCP.OnMCPInitialize := SrvInitialize;
MCP.OnMCPSessionNew := SrvSessionNew;
MCP.OnMCPRequestTool := SrvCallTool;
MCP.OnMCPRequestPrompt := SrvGetPrompt;
MCP.OnMCPRequestResource := SrvReadResource;
MCP.Active := True;
// Push a notification to every connected session
MCP.SendNotificationToolsListChanged;
end;
5 个发布属性、9 个方法、12 个事件 — 来自组件参考。
Methods: KeepAlive.
Events: OnMCPHTTPRequest, OnMCPHTTPResponse.
Published properties: MCPOptions, EndpointOptions, TransportOptions.
Published properties: Version.
Properties: Server.
Methods: RequestRootsList, RequestSamplingCreateMessage, RequestElicitationCreate.
本组件所实现协议的权威参考来源。
TsgcWSAPIServer_MCP 组件,设置 MCPOptions.HttpOptions.Port 和 MCPOptions.ServerInfo,挂接 OnMCPRequest* 处理程序,然后设置 Active := True。它在 sgcWebSockets HTTP 服务器之上托管一个 JSON-RPC 端点。
TransportOptions 和 EndpointOptions 发布属性进行配置。
OnMCPRequestTool 处理工具调用,OnMCPRequestPrompt 处理提示,OnMCPRequestResource 处理资源。你还可以向每个已连接的会话推送更新,例如使用 SendNotificationToolsListChanged。
RequestRootsList、RequestSamplingCreateMessage 和 RequestElicitationCreate 发起服务器端请求,因此服务器可以向已连接的 MCP 客户端请求 roots、采样补全或用户输入。