Skip to content

Commit 8a36cee

Browse files
committed
feat: 初步完成McpManager基本结构开发
1 parent 5fe81c1 commit 8a36cee

File tree

15 files changed

+1345
-34
lines changed

15 files changed

+1345
-34
lines changed

src/common/appdata.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::config::core::ConfigActor;
33
use crate::grpc::bistream_manage::BiStreamManage;
44
use crate::health::core::HealthManager;
55
use crate::ldap::core::LdapManager;
6+
use crate::mcp::core::McpManager;
67
use crate::metrics::core::MetricsManager;
78
use crate::namespace::NamespaceActor;
89
use crate::naming::cluster::node_manage::{InnerNodeManage, NodeManage};
@@ -54,4 +55,5 @@ pub struct AppShareData {
5455
pub ldap_manager: Addr<LdapManager>,
5556
pub sequence_db_manager: Addr<SequenceDbManager>,
5657
pub sequence_manager: Addr<SequenceManager>,
58+
pub mcp_manager: Addr<McpManager>,
5759
}

src/common/constant.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ lazy_static::lazy_static! {
2525
pub static ref USER_TREE_NAME: Arc<String> = Arc::new("T_USER".to_string());
2626
pub static ref CACHE_TREE_NAME: Arc<String> = Arc::new("T_CACHE".to_string());
2727
pub static ref NAMESPACE_TREE_NAME: Arc<String> = Arc::new("T_NAMESPACE".to_string());
28+
pub static ref MCP_SERVER_TABLE_NAME: Arc<String> = Arc::new("T_MCP_SERVER".to_string());
29+
pub static ref MCP_TOOL_SPEC_TABLE_NAME: Arc<String> = Arc::new("T_MCP_TOOL_SPEC".to_string());
2830
pub static ref EMPTY_ARC_STRING: Arc<String> = Arc::new("".to_string());
2931
pub static ref DEFAULT_NAMESPACE_ARC_STRING: Arc<String> = Arc::new("".to_string());
3032
pub static ref EMPTY_CLIENT_VERSION: Arc<ClientVersion> = Arc::new(ClientVersion::default());

src/common/datetime_utils.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,38 @@ use std::time::SystemTime;
33

44
const DATETIME_TIMESTAMP_FMT: &str = "%Y-%m-%dT%H:%M:%S%.3f%:z";
55

6+
pub fn now_millis() -> u64 {
7+
use std::time::SystemTime;
8+
SystemTime::now()
9+
.duration_since(SystemTime::UNIX_EPOCH)
10+
.unwrap()
11+
.as_millis() as u64
12+
}
13+
14+
pub fn now_millis_i64() -> i64 {
15+
use std::time::SystemTime;
16+
SystemTime::now()
17+
.duration_since(SystemTime::UNIX_EPOCH)
18+
.unwrap()
19+
.as_millis() as i64
20+
}
21+
22+
pub fn now_second_i32() -> i32 {
23+
use std::time::SystemTime;
24+
SystemTime::now()
25+
.duration_since(SystemTime::UNIX_EPOCH)
26+
.unwrap()
27+
.as_secs() as i32
28+
}
29+
30+
pub fn now_second_u32() -> u32 {
31+
use std::time::SystemTime;
32+
SystemTime::now()
33+
.duration_since(SystemTime::UNIX_EPOCH)
34+
.unwrap()
35+
.as_secs() as u32
36+
}
37+
638
pub fn get_now_timestamp_str(offset: &FixedOffset) -> String {
739
DateTime::<Utc>::from(SystemTime::now())
840
.with_timezone(offset)

src/common/pb/data_object.proto

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// 用于生成 data_object.rs
2+
// pb-rs data_object.proto
3+
4+
syntax = "proto3";
5+
6+
package data_object;
7+
8+
9+
message McpServerDo {
10+
uint64 id = 1;
11+
string namespace = 2;
12+
string name = 3;
13+
string description = 4;
14+
string token = 5;
15+
}
16+
17+
message McpToolSpecDo {
18+
string namespace = 1;
19+
string group = 2;
20+
string tool_name = 3;
21+
uint64 version = 4;
22+
string name = 5;
23+
string description = 6;
24+
}
25+
26+
message McpToolDo {
27+
uint64 id = 1;
28+
string tool_name = 2;
29+
string namespace = 3;
30+
string group = 4;
31+
uint64 version = 5;
32+
}
33+
34+
message ToolRouteRuleDo {
35+
string protocol = 1;
36+
string url = 2;
37+
string method = 3;
38+
}
39+

src/common/pb/data_object.rs

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
// Automatically generated rust module for 'data_object.proto' file
2+
3+
#![allow(non_snake_case)]
4+
#![allow(non_upper_case_globals)]
5+
#![allow(non_camel_case_types)]
6+
#![allow(unused_imports)]
7+
#![allow(unknown_lints)]
8+
#![allow(clippy::all)]
9+
#![cfg_attr(rustfmt, rustfmt_skip)]
10+
11+
12+
use std::borrow::Cow;
13+
use quick_protobuf::{MessageInfo, MessageRead, MessageWrite, BytesReader, Writer, WriterBackend, Result};
14+
use quick_protobuf::sizeofs::*;
15+
use super::*;
16+
17+
#[allow(clippy::derive_partial_eq_without_eq)]
18+
#[derive(Debug, Default, PartialEq, Clone)]
19+
pub struct McpServerDo<'a> {
20+
pub id: u64,
21+
pub namespace: Cow<'a, str>,
22+
pub name: Cow<'a, str>,
23+
pub description: Cow<'a, str>,
24+
pub token: Cow<'a, str>,
25+
}
26+
27+
impl<'a> MessageRead<'a> for McpServerDo<'a> {
28+
fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
29+
let mut msg = Self::default();
30+
while !r.is_eof() {
31+
match r.next_tag(bytes) {
32+
Ok(8) => msg.id = r.read_uint64(bytes)?,
33+
Ok(18) => msg.namespace = r.read_string(bytes).map(Cow::Borrowed)?,
34+
Ok(26) => msg.name = r.read_string(bytes).map(Cow::Borrowed)?,
35+
Ok(34) => msg.description = r.read_string(bytes).map(Cow::Borrowed)?,
36+
Ok(42) => msg.token = r.read_string(bytes).map(Cow::Borrowed)?,
37+
Ok(t) => { r.read_unknown(bytes, t)?; }
38+
Err(e) => return Err(e),
39+
}
40+
}
41+
Ok(msg)
42+
}
43+
}
44+
45+
impl<'a> MessageWrite for McpServerDo<'a> {
46+
fn get_size(&self) -> usize {
47+
0
48+
+ if self.id == 0u64 { 0 } else { 1 + sizeof_varint(*(&self.id) as u64) }
49+
+ if self.namespace == "" { 0 } else { 1 + sizeof_len((&self.namespace).len()) }
50+
+ if self.name == "" { 0 } else { 1 + sizeof_len((&self.name).len()) }
51+
+ if self.description == "" { 0 } else { 1 + sizeof_len((&self.description).len()) }
52+
+ if self.token == "" { 0 } else { 1 + sizeof_len((&self.token).len()) }
53+
}
54+
55+
fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
56+
if self.id != 0u64 { w.write_with_tag(8, |w| w.write_uint64(*&self.id))?; }
57+
if self.namespace != "" { w.write_with_tag(18, |w| w.write_string(&**&self.namespace))?; }
58+
if self.name != "" { w.write_with_tag(26, |w| w.write_string(&**&self.name))?; }
59+
if self.description != "" { w.write_with_tag(34, |w| w.write_string(&**&self.description))?; }
60+
if self.token != "" { w.write_with_tag(42, |w| w.write_string(&**&self.token))?; }
61+
Ok(())
62+
}
63+
}
64+
65+
#[allow(clippy::derive_partial_eq_without_eq)]
66+
#[derive(Debug, Default, PartialEq, Clone)]
67+
pub struct McpToolSpecDo<'a> {
68+
pub namespace: Cow<'a, str>,
69+
pub group: Cow<'a, str>,
70+
pub tool_name: Cow<'a, str>,
71+
pub version: u64,
72+
pub name: Cow<'a, str>,
73+
pub description: Cow<'a, str>,
74+
}
75+
76+
impl<'a> MessageRead<'a> for McpToolSpecDo<'a> {
77+
fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
78+
let mut msg = Self::default();
79+
while !r.is_eof() {
80+
match r.next_tag(bytes) {
81+
Ok(10) => msg.namespace = r.read_string(bytes).map(Cow::Borrowed)?,
82+
Ok(18) => msg.group = r.read_string(bytes).map(Cow::Borrowed)?,
83+
Ok(26) => msg.tool_name = r.read_string(bytes).map(Cow::Borrowed)?,
84+
Ok(32) => msg.version = r.read_uint64(bytes)?,
85+
Ok(42) => msg.name = r.read_string(bytes).map(Cow::Borrowed)?,
86+
Ok(50) => msg.description = r.read_string(bytes).map(Cow::Borrowed)?,
87+
Ok(t) => { r.read_unknown(bytes, t)?; }
88+
Err(e) => return Err(e),
89+
}
90+
}
91+
Ok(msg)
92+
}
93+
}
94+
95+
impl<'a> MessageWrite for McpToolSpecDo<'a> {
96+
fn get_size(&self) -> usize {
97+
0
98+
+ if self.namespace == "" { 0 } else { 1 + sizeof_len((&self.namespace).len()) }
99+
+ if self.group == "" { 0 } else { 1 + sizeof_len((&self.group).len()) }
100+
+ if self.tool_name == "" { 0 } else { 1 + sizeof_len((&self.tool_name).len()) }
101+
+ if self.version == 0u64 { 0 } else { 1 + sizeof_varint(*(&self.version) as u64) }
102+
+ if self.name == "" { 0 } else { 1 + sizeof_len((&self.name).len()) }
103+
+ if self.description == "" { 0 } else { 1 + sizeof_len((&self.description).len()) }
104+
}
105+
106+
fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
107+
if self.namespace != "" { w.write_with_tag(10, |w| w.write_string(&**&self.namespace))?; }
108+
if self.group != "" { w.write_with_tag(18, |w| w.write_string(&**&self.group))?; }
109+
if self.tool_name != "" { w.write_with_tag(26, |w| w.write_string(&**&self.tool_name))?; }
110+
if self.version != 0u64 { w.write_with_tag(32, |w| w.write_uint64(*&self.version))?; }
111+
if self.name != "" { w.write_with_tag(42, |w| w.write_string(&**&self.name))?; }
112+
if self.description != "" { w.write_with_tag(50, |w| w.write_string(&**&self.description))?; }
113+
Ok(())
114+
}
115+
}
116+
117+
#[allow(clippy::derive_partial_eq_without_eq)]
118+
#[derive(Debug, Default, PartialEq, Clone)]
119+
pub struct McpToolDo<'a> {
120+
pub id: u64,
121+
pub tool_name: Cow<'a, str>,
122+
pub namespace: Cow<'a, str>,
123+
pub group: Cow<'a, str>,
124+
pub version: u64,
125+
}
126+
127+
impl<'a> MessageRead<'a> for McpToolDo<'a> {
128+
fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
129+
let mut msg = Self::default();
130+
while !r.is_eof() {
131+
match r.next_tag(bytes) {
132+
Ok(8) => msg.id = r.read_uint64(bytes)?,
133+
Ok(18) => msg.tool_name = r.read_string(bytes).map(Cow::Borrowed)?,
134+
Ok(26) => msg.namespace = r.read_string(bytes).map(Cow::Borrowed)?,
135+
Ok(34) => msg.group = r.read_string(bytes).map(Cow::Borrowed)?,
136+
Ok(40) => msg.version = r.read_uint64(bytes)?,
137+
Ok(t) => { r.read_unknown(bytes, t)?; }
138+
Err(e) => return Err(e),
139+
}
140+
}
141+
Ok(msg)
142+
}
143+
}
144+
145+
impl<'a> MessageWrite for McpToolDo<'a> {
146+
fn get_size(&self) -> usize {
147+
0
148+
+ if self.id == 0u64 { 0 } else { 1 + sizeof_varint(*(&self.id) as u64) }
149+
+ if self.tool_name == "" { 0 } else { 1 + sizeof_len((&self.tool_name).len()) }
150+
+ if self.namespace == "" { 0 } else { 1 + sizeof_len((&self.namespace).len()) }
151+
+ if self.group == "" { 0 } else { 1 + sizeof_len((&self.group).len()) }
152+
+ if self.version == 0u64 { 0 } else { 1 + sizeof_varint(*(&self.version) as u64) }
153+
}
154+
155+
fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
156+
if self.id != 0u64 { w.write_with_tag(8, |w| w.write_uint64(*&self.id))?; }
157+
if self.tool_name != "" { w.write_with_tag(18, |w| w.write_string(&**&self.tool_name))?; }
158+
if self.namespace != "" { w.write_with_tag(26, |w| w.write_string(&**&self.namespace))?; }
159+
if self.group != "" { w.write_with_tag(34, |w| w.write_string(&**&self.group))?; }
160+
if self.version != 0u64 { w.write_with_tag(40, |w| w.write_uint64(*&self.version))?; }
161+
Ok(())
162+
}
163+
}
164+
165+
#[allow(clippy::derive_partial_eq_without_eq)]
166+
#[derive(Debug, Default, PartialEq, Clone)]
167+
pub struct ToolRouteRuleDo<'a> {
168+
pub protocol: Cow<'a, str>,
169+
pub url: Cow<'a, str>,
170+
pub method: Cow<'a, str>,
171+
}
172+
173+
impl<'a> MessageRead<'a> for ToolRouteRuleDo<'a> {
174+
fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
175+
let mut msg = Self::default();
176+
while !r.is_eof() {
177+
match r.next_tag(bytes) {
178+
Ok(10) => msg.protocol = r.read_string(bytes).map(Cow::Borrowed)?,
179+
Ok(18) => msg.url = r.read_string(bytes).map(Cow::Borrowed)?,
180+
Ok(26) => msg.method = r.read_string(bytes).map(Cow::Borrowed)?,
181+
Ok(t) => { r.read_unknown(bytes, t)?; }
182+
Err(e) => return Err(e),
183+
}
184+
}
185+
Ok(msg)
186+
}
187+
}
188+
189+
impl<'a> MessageWrite for ToolRouteRuleDo<'a> {
190+
fn get_size(&self) -> usize {
191+
0
192+
+ if self.protocol == "" { 0 } else { 1 + sizeof_len((&self.protocol).len()) }
193+
+ if self.url == "" { 0 } else { 1 + sizeof_len((&self.url).len()) }
194+
+ if self.method == "" { 0 } else { 1 + sizeof_len((&self.method).len()) }
195+
}
196+
197+
fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
198+
if self.protocol != "" { w.write_with_tag(10, |w| w.write_string(&**&self.protocol))?; }
199+
if self.url != "" { w.write_with_tag(18, |w| w.write_string(&**&self.url))?; }
200+
if self.method != "" { w.write_with_tag(26, |w| w.write_string(&**&self.method))?; }
201+
Ok(())
202+
}
203+
}
204+

src/common/pb/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
pub mod data_object;
12
pub mod transfer;

src/lib.rs

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,14 @@ pub mod health;
1616
pub mod transfer;
1717

1818
pub mod ldap;
19+
pub mod mcp;
1920
pub mod sequence;
2021

2122
pub use inner_mem_cache::TimeoutSet;
2223

23-
fn now_millis() -> u64 {
24-
use std::time::SystemTime;
25-
SystemTime::now()
26-
.duration_since(SystemTime::UNIX_EPOCH)
27-
.unwrap()
28-
.as_millis() as u64
29-
}
30-
31-
fn now_millis_i64() -> i64 {
32-
use std::time::SystemTime;
33-
SystemTime::now()
34-
.duration_since(SystemTime::UNIX_EPOCH)
35-
.unwrap()
36-
.as_millis() as i64
37-
}
38-
39-
fn now_second_i32() -> i32 {
40-
use std::time::SystemTime;
41-
SystemTime::now()
42-
.duration_since(SystemTime::UNIX_EPOCH)
43-
.unwrap()
44-
.as_secs() as i32
45-
}
46-
47-
fn now_second_u32() -> u32 {
48-
use std::time::SystemTime;
49-
SystemTime::now()
50-
.duration_since(SystemTime::UNIX_EPOCH)
51-
.unwrap()
52-
.as_secs() as u32
53-
}
24+
pub use crate::common::datetime_utils::{
25+
now_millis, now_millis_i64, now_second_i32, now_second_u32,
26+
};
5427

5528
#[cfg(test)]
5629
mod tests {}

0 commit comments

Comments
 (0)