MCP Server

在 Delphi 中构建 Model Context Protocol (MCP) 服务器。向 AI 应用程序暴露工具、资源和提示词。

TsgcWSAPIServer_MCP

将自定义工具、提示词和资源暴露给任意支持 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.

HTTP

Events: OnMCPHTTPRequest, OnMCPHTTPResponse.

配置

Published properties: MCPOptions, EndpointOptions, TransportOptions.

诊断

Published properties: Version.

服务器

Properties: Server.

服务器发起的请求

Methods: RequestRootsList, RequestSamplingCreateMessage, RequestElicitationCreate.

规范与参考

本组件所实现协议的权威参考来源。

文档与演示

直接访问组件参考文档,获取即用型演示项目,并下载试用版。

演示项目 — Demos\AI\MCP\Server 即用型示例项目,随 sgcWebSockets 包一起提供 — 请在下方下载试用版。
技术文档(PDF) 功能概述、快速入门、Delphi 和 C++ Builder 代码示例及主要参考资源 — 仅适用于本组件。
用户手册(PDF) 涵盖库中每个组件的综合手册。

准备好构建 MCP 服务器了吗?

下载免费试用版,几分钟内即可开始构建。