🛰️航天仿真算法库 SpaceAST 0.4.0
载入中...
搜索中...
未找到
ast::McpServer类 参考

#include <McpServer.hpp>

Public 成员函数

void setServerName (StringView name)
 
const std::string & serverName () const
 
void setServerVersion (StringView version)
 
const std::string & serverVersion () const
 
void setInstructions (StringView instructions)
 
const std::string & instructions () const
 
ChatTools & tools ()
 
const ChatTools & tools () const
 
McpTool * addTool (std::unique_ptr< McpTool > tool)
 
template<typename T >
McpTool * addTool (std::unique_ptr< T > tool)
 
template<typename Func >
McpTool * addTool (Func func)
 
void clearTools ()
 
size_t toolCount () const
 
McpTool * findTool (StringView name) const
 
bool handleRequest (const JsonValue &request, JsonValue &response)
 
std::string handleLine (StringView line)
 
int runStdio ()
 

详细描述

MCP服务器

按行收发JSON-RPC消息,通过stdio与MCP客户端通信。 服务器只负责协议处理,不包含任何具体业务工具;工具通过 addTool 注册。

成员函数说明

◆ addTool() [1/2]

template<typename Func >
McpTool * ast::McpServer::addTool ( Func func)
inline

添加函数形式的工具

参数
func工具函数,签名为 std::string(const JsonValue&)
返回
添加成功返回工具指针;同名工具已存在时返回nullptr

◆ addTool() [2/2]

McpTool * ast::McpServer::addTool ( std::unique_ptr< McpTool > tool)

添加工具

参数
tool工具指针
返回
添加成功返回工具指针;同名工具已存在时返回nullptr
注解
工具名称可以在添加后通过 McpTool::setName 设置

◆ findTool()

McpTool * ast::McpServer::findTool ( StringView name) const

查找工具

参数
name工具名称
返回
工具指针,不存在返回nullptr

◆ handleLine()

std::string ast::McpServer::handleLine ( StringView line)

处理一行文本消息

参数
line一行JSON文本
返回
响应文本(通知、空行返回空字符串)

◆ handleRequest()

bool ast::McpServer::handleRequest ( const JsonValue & request,
JsonValue & response )

处理一条JSON-RPC消息

参数
request请求
[out]response响应
返回
是否需要回包(通知不需要回包)

◆ runStdio()

int ast::McpServer::runStdio ( )

在stdio上运行服务器主循环

返回
进程退出码

该类的文档由以下文件生成: