i更新
This commit is contained in:
@@ -4,13 +4,23 @@ declare(strict_types=1);
|
||||
namespace app\mcp\service;
|
||||
|
||||
/**
|
||||
* MCP 工具:少量通用工具覆盖目录里的全部资源,另有几个高频统计的快捷工具;业绩类工具见 PerfTools。
|
||||
* MCP 工具:少量通用工具覆盖目录里的全部资源,另有几个高频统计的快捷工具;业绩类工具见 PerfTools,物流查询见 LogisticsTools。
|
||||
* 所有工具只读;结果同时给文字摘要 + JSON(很多客户端只把 text 交给模型)。
|
||||
*/
|
||||
class Tools
|
||||
{
|
||||
private const READ_ONLY = ['readOnlyHint' => true, 'destructiveHint' => false, 'idempotentHint' => true, 'openWorldHint' => false];
|
||||
|
||||
/** 工具的中文显示名称(MCP title / annotations.title):客户端的执行步骤里显示它,而不是工具标识 */
|
||||
private const TITLES = [
|
||||
'zyt_whoami' => '我的账号与权限', 'zyt_catalog' => '可查询的数据目录', 'zyt_describe' => '数据资源说明',
|
||||
'zyt_query' => '查询业务数据', 'zyt_get' => '查看记录详情', 'zyt_count' => '统计记录条数', 'zyt_file' => '读取附件',
|
||||
'zyt_stats_appointments' => '挂号接诊统计', 'zyt_stats_doctor_workload' => '医生工作量统计', 'zyt_stats_orders' => '收款订单统计',
|
||||
'zyt_stats_prescription_orders' => '处方业务订单统计', 'zyt_my_patients' => '我的患者', 'zyt_roster' => '医生排班',
|
||||
'zyt_perf_assistants' => '医助业绩排行', 'zyt_perf_doctors' => '医生业绩排行', 'zyt_stats_performance' => '部门业绩看板',
|
||||
'zyt_perf_trend' => '业绩走势', 'zyt_logistics_order' => '订单物流查询', 'zyt_logistics_patient' => '患者物流查询',
|
||||
];
|
||||
|
||||
/** tools/list */
|
||||
public static function definitions(Identity $identity): array
|
||||
{
|
||||
@@ -53,7 +63,7 @@ class Tools
|
||||
$tools[] = self::tool($name, $preset['description'], $preset['args'], $preset['required']);
|
||||
}
|
||||
}
|
||||
return array_merge($tools, PerfTools::definitions($identity));
|
||||
return array_merge($tools, PerfTools::definitions($identity), LogisticsTools::definitions($identity));
|
||||
}
|
||||
|
||||
/** tools/call,返回 CallToolResult */
|
||||
@@ -73,6 +83,7 @@ class Tools
|
||||
$name === 'zyt_count' => self::count($identity, $args, $audit),
|
||||
$name === 'zyt_file' => self::file($identity, $args, $audit),
|
||||
PerfTools::handles($name) => PerfTools::call($identity, $name, $args, $audit),
|
||||
LogisticsTools::handles($name) => LogisticsTools::call($identity, $name, $args, $audit),
|
||||
isset($presets[$name]) => self::preset($identity, $presets[$name], $args, $audit),
|
||||
default => throw new McpException('没有这个工具:' . $name, 'unknown_tool'),
|
||||
};
|
||||
@@ -554,7 +565,9 @@ class Tools
|
||||
if ($required) {
|
||||
$schema['required'] = $required;
|
||||
}
|
||||
return ['name' => $name, 'description' => $description, 'inputSchema' => $schema, 'annotations' => self::READ_ONLY];
|
||||
$title = self::TITLES[$name] ?? '';
|
||||
$tool = ['name' => $name, 'description' => $description, 'inputSchema' => $schema, 'annotations' => self::READ_ONLY + ($title !== '' ? ['title' => $title] : [])];
|
||||
return $title !== '' ? ['name' => $name, 'title' => $title] + $tool : $tool;
|
||||
}
|
||||
|
||||
private static function ok(string $summary, array $data): array
|
||||
|
||||
Reference in New Issue
Block a user