Skip to content

Commit 9e4b306

Browse files
committed
feat: 调整mcp tools的持久化结构; #241
1 parent 8a36cee commit 9e4b306

8 files changed

Lines changed: 731 additions & 403 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ naming.db
99
nacos_db/
1010
.env
1111
cluster_example/
12+
.kiro/
13+

src/common/pb/data_object.proto

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,59 @@ message McpServerDo {
1414
string token = 5;
1515
}
1616

17+
// 工具规范版本
18+
message ToolSpecVersionDo {
19+
uint64 version = 1;
20+
string parameters_json = 2;
21+
string op_user = 3;
22+
int64 update_time = 4;
23+
int64 ref_count = 5;
24+
}
25+
26+
// 工具键
27+
message ToolKey {
28+
string namespace = 1;
29+
string group = 2;
30+
string tool_name = 3;
31+
}
32+
33+
// MCP 工具规范
1734
message McpToolSpecDo {
1835
string namespace = 1;
1936
string group = 2;
2037
string tool_name = 3;
21-
uint64 version = 4;
22-
string name = 5;
23-
string description = 6;
38+
uint64 current_version = 4;
39+
int64 create_time = 5;
40+
string create_user = 6;
41+
repeated ToolSpecVersionDo versions = 7;
2442
}
2543

26-
message McpToolDo {
27-
uint64 id = 1;
28-
string tool_name = 2;
29-
string namespace = 3;
30-
string group = 4;
31-
uint64 version = 5;
44+
// 转换类型
45+
enum ConvertType {
46+
NONE = 0;
47+
FORM_TO_JSON = 1;
48+
CUSTOM = 2;
3249
}
3350

51+
// 工具路由规则
3452
message ToolRouteRuleDo {
3553
string protocol = 1;
3654
string url = 2;
3755
string method = 3;
56+
string addition_headers_json = 4;
57+
string convert_type = 5;
58+
string service_namespace = 6;
59+
string service_group = 7;
60+
string service_name = 8;
3861
}
3962

63+
// MCP 工具
64+
message McpToolDo {
65+
uint64 id = 1;
66+
string tool_name = 2;
67+
string namespace = 3;
68+
string group = 4;
69+
uint64 version = 5;
70+
string spec_json = 6;
71+
string route_rule_json = 7;
72+
}

src/common/pb/data_object.rs

Lines changed: 189 additions & 34 deletions
Large diffs are not rendered by default.

src/mcp/core.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use crate::mcp::model::actor_model::{
66
McpToolSpecQueryParam, ToolSpecDto,
77
};
88
use crate::mcp::model::mcp::{
9-
McpQueryParam, McpServer, McpServerDto, McpServerParam, McpServerWrap, ToolKey, ToolSpec,
10-
ToolSpecParam,
9+
McpQueryParam, McpServer, McpServerDto, McpServerParam, McpServerWrap,
1110
};
1211
use crate::raft::filestore::model::SnapshotRecordDto;
1312
use crate::raft::filestore::raftapply::{RaftApplyDataRequest, RaftApplyDataResponse};
@@ -18,6 +17,7 @@ use bean_factory::{bean, BeanFactory, FactoryData, Inject};
1817
use quick_protobuf::{BytesReader, Writer};
1918
use std::collections::BTreeMap;
2019
use std::sync::Arc;
20+
use crate::mcp::model::tools::{ToolKey, ToolSpec, ToolSpecParam};
2121

2222
#[bean(inject)]
2323
pub struct McpManager {

src/mcp/model/actor_model.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use crate::mcp::model::mcp::{
2-
McpQueryParam, McpServer, McpServerDto, McpServerParam, ToolSpec, ToolSpecParam,
2+
McpQueryParam, McpServer, McpServerDto, McpServerParam,
33
};
44
use actix::Message;
55
use serde::{Deserialize, Serialize};
66
use std::sync::Arc;
7+
use crate::mcp::model::tools::{ToolSpec, ToolSpecParam};
78

89
/// MCP 查询请求
910
#[derive(Debug, Message)]
@@ -60,27 +61,28 @@ pub struct McpToolSpecQueryParam {
6061
#[derive(Clone, Debug, Serialize, Deserialize)]
6162
#[serde(rename_all = "camelCase")]
6263
pub struct ToolSpecDto {
63-
pub namespace: String,
64-
pub group: String,
65-
pub tool_name: String,
64+
pub namespace: Arc<String>,
65+
pub group: Arc<String>,
66+
pub tool_name: Arc<String>,
6667
pub version: u64,
6768
pub name: String,
6869
pub description: String,
69-
pub create_time: u64,
70-
pub last_modified_millis: u64,
70+
pub create_time: i64,
71+
pub last_modified_millis: i64,
7172
}
7273

7374
impl ToolSpecDto {
7475
pub fn new_from(tool_spec: &ToolSpec) -> Self {
76+
let current_version = tool_spec.get_current_version().unwrap_or_default();
7577
Self {
76-
namespace: tool_spec.key.namespace.to_string(),
77-
group: tool_spec.key.group.to_string(),
78-
tool_name: tool_spec.key.tool_name.to_string(),
79-
version: tool_spec.version,
80-
name: tool_spec.name.to_string(),
81-
description: tool_spec.description.to_string(),
82-
create_time: 0, // 实际实现中需要从 tool_spec 获取
83-
last_modified_millis: 0, // 实际实现中需要从 tool_spec 获取
78+
namespace: tool_spec.key.namespace.clone(),
79+
group: tool_spec.key.group.clone(),
80+
tool_name: tool_spec.key.tool_name.clone(),
81+
version: tool_spec.current_version,
82+
name: current_version.parameters.name.clone(),
83+
description: current_version.parameters.name.clone(),
84+
create_time: 0, // 实际实现中需要从 tool_spec 获取
85+
last_modified_millis: current_version.update_time, // 实际实现中需要从 tool_spec 获取
8486
}
8587
}
8688
}

0 commit comments

Comments
 (0)