McpUtils

object McpUtils : CloseableUtils

Model Context Protocol(MCP) 工具类,提供工具和服务器的注册、注销及资源管理功能。

该类基于 RegisterUtils 实现了资源的引用计数管理,确保同一资源可被多个来源注册/注销, 并在所有来源都注销后才真正释放资源。支持两种资源类型:

所有注册/注销操作都需要指定 origin 参数,用于标识发起操作的对象,以便进行引用计数。 当一个资源的所有引用(origin)都注销后,该资源会被自动释放。

Author

M8Test, [email protected], https://m8test.com

See also

RegisterUtils

资源注册管理的基础工具类

Functions

Link copied to clipboard
fun registerServer(origin: Any, serverBuilder: SseMcpServer.() -> Unit): Result

注册一个 SSE(Server-Sent Events) Model Context Protocol(MCP) 服务器到系统,并关联发起注册的来源对象。

Link copied to clipboard
fun registerTool(origin: Any, toolBuilder: Tool.() -> Unit): Result

注册一个工具到 Model Context Protocol(MCP) 系统,并关联发起注册的来源对象。

Link copied to clipboard
fun unregisterServer(origin: Any, serverName: String): Result

从 Model Context Protocol(MCP) 系统注销一个 SSE 服务器,并关联发起注销的来源对象。

Link copied to clipboard
fun unregisterTool(origin: Any, tool: Tool): Result

从 Model Context Protocol(MCP) 系统注销一个工具,并关联发起注销的来源对象。