@pheem49/mint 1.5.5 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex +0 -0
- package/.github/FUNDING.yml +2 -0
- package/.github/workflows/ci.yml +45 -0
- package/.github/workflows/release.yml +79 -0
- package/Cargo.lock +5792 -0
- package/Cargo.toml +32 -0
- package/README.md +387 -353
- package/assets/icon.png +0 -0
- package/bin/mint +0 -0
- package/crates/mint-cli/Cargo.toml +23 -0
- package/crates/mint-cli/src/agent.rs +851 -0
- package/crates/mint-cli/src/gmail.rs +216 -0
- package/crates/mint-cli/src/image.rs +142 -0
- package/crates/mint-cli/src/main.rs +2837 -0
- package/crates/mint-cli/src/mcp.rs +63 -0
- package/crates/mint-cli/src/onboard.rs +1149 -0
- package/crates/mint-cli/src/setup.rs +390 -0
- package/crates/mint-cli/src/skills.rs +8 -0
- package/crates/mint-cli/src/updater.rs +279 -0
- package/crates/mint-core/Cargo.toml +22 -0
- package/crates/mint-core/src/agent_loop.rs +94 -0
- package/crates/mint-core/src/api_server.rs +991 -0
- package/crates/mint-core/src/channels.rs +248 -0
- package/crates/mint-core/src/chat.rs +895 -0
- package/crates/mint-core/src/code_tools.rs +729 -0
- package/crates/mint-core/src/config.rs +368 -0
- package/crates/mint-core/src/files.rs +159 -0
- package/crates/mint-core/src/knowledge.rs +541 -0
- package/crates/mint-core/src/lib.rs +84 -0
- package/crates/mint-core/src/mcp.rs +273 -0
- package/crates/mint-core/src/memory.rs +673 -0
- package/crates/mint-core/src/orchestration.rs +2157 -0
- package/crates/mint-core/src/pictures.rs +314 -0
- package/crates/mint-core/src/plugins.rs +727 -0
- package/crates/mint-core/src/safety.rs +416 -0
- package/crates/mint-core/src/semantic.rs +254 -0
- package/crates/mint-core/src/shell.rs +317 -0
- package/crates/mint-core/src/skills.rs +71 -0
- package/crates/mint-core/src/symbols.rs +157 -0
- package/crates/mint-core/src/tasks.rs +308 -0
- package/crates/mint-core/src/tts.rs +92 -0
- package/crates/mint-core/src/weather.rs +93 -0
- package/crates/mint-core/src/web_search.rs +200 -0
- package/crates/mint-core/src/workflows.rs +81 -0
- package/crates/mint-core/tests/mcp_stdio.rs +45 -0
- package/crates/mint-core/tests/memory_persistence.rs +172 -0
- package/crates/mint-core/tests/pictures_storage.rs +14 -0
- package/crates/mint-core/tests/task_lifecycle.rs +87 -0
- package/package.json +35 -99
- package/src/bin/index.js +16 -0
- package/src/renderer/index-web.html +17 -0
- package/src/renderer/index.html +17 -0
- package/src/renderer/public/Live2DCubismCore.js +9 -0
- package/src/renderer/public/assets/icon.png +0 -0
- package/src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/shiroko.model3.json +36 -0
- package/src/renderer/src/App.tsx +33 -0
- package/src/renderer/src/calculator.ts +47 -0
- package/src/renderer/src/components/ChatPanel.tsx +1598 -0
- package/src/renderer/src/components/DashboardSidebar.tsx +358 -0
- package/src/renderer/src/components/Live2DStage.tsx +374 -0
- package/src/renderer/src/components/MintDashboard.tsx +950 -0
- package/src/renderer/src/components/ModelPanel.tsx +154 -0
- package/src/renderer/src/components/PicturesLibrary.tsx +46 -0
- package/src/renderer/src/components/ProactiveGlow.tsx +19 -0
- package/src/renderer/src/components/ScreenPicker.tsx +579 -0
- package/src/renderer/src/components/SettingsWindow.tsx +1467 -0
- package/src/renderer/src/components/SpotlightWindow.tsx +280 -0
- package/src/renderer/src/components/WidgetWindow.tsx +36 -0
- package/src/renderer/src/components/WorkspacePanel.tsx +268 -0
- package/src/{UI → renderer/src/css}/settings.css +69 -16
- package/src/renderer/src/css/spotlight.css +113 -0
- package/src/renderer/src/css/styles.css +3722 -0
- package/src/renderer/src/css/widget.css +185 -0
- package/src/renderer/src/env.d.ts +116 -0
- package/src/renderer/src/index.css +379 -0
- package/src/renderer/src/main.tsx +13 -0
- package/src/renderer/src/tauri.ts +996 -0
- package/src/renderer/src-web/App.tsx +25 -0
- package/src/renderer/src-web/calculator.ts +47 -0
- package/src/renderer/src-web/components/ChatPanel.tsx +1662 -0
- package/src/renderer/src-web/components/DashboardSidebar.tsx +242 -0
- package/src/renderer/src-web/components/MintDashboard.tsx +763 -0
- package/src/renderer/src-web/components/PicturesLibrary.tsx +73 -0
- package/src/renderer/src-web/components/SettingsWindow.tsx +1500 -0
- package/src/renderer/src-web/css/settings.css +1100 -0
- package/src/{UI → renderer/src-web/css}/spotlight.css +4 -4
- package/src/{UI → renderer/src-web/css}/styles.css +1055 -159
- package/src/{UI → renderer/src-web/css}/widget.css +2 -2
- package/src/renderer/src-web/env.d.ts +107 -0
- package/src/renderer/src-web/index.css +379 -0
- package/src/renderer/src-web/main.tsx +13 -0
- package/src/renderer/src-web/tauri.ts +983 -0
- package/tsconfig.json +30 -0
- package/vite.config.ts +33 -0
- package/vite.config.web.ts +51 -0
- package/GUIDE_TH.md +0 -125
- package/assets/Agent_Mint.png +0 -0
- package/assets/CLI_Screen.png +0 -0
- package/assets/Settings.png +0 -0
- package/benchmark_ai.js +0 -71
- package/install.ps1 +0 -64
- package/install.sh +0 -54
- package/main.js +0 -139
- package/mint-cli-logic.js +0 -3
- package/mint-cli.js +0 -410
- package/models/Shiroko_Model/Shiroko/Shiroko_Core//351/235/242/351/245/2740.model3.json +0 -47
- package/models/Shiroko_Model/Shiroko//342/232/241/351/253/230/344/272/256/342/232/241/344/275/277/347/224/250/346/225/231/347/250/213/344/270/216/346/263/250/346/204/217/344/272/213/351/241/271.txt +0 -23
- package/preload-picker.js +0 -11
- package/preload-settings.js +0 -11
- package/preload.js +0 -41
- package/scripts/install_linux_desktop_entry.js +0 -48
- package/src/AI_Brain/Gemini_API.js +0 -813
- package/src/AI_Brain/agent_orchestrator.js +0 -73
- package/src/AI_Brain/autonomous_brain.js +0 -179
- package/src/AI_Brain/behavior_memory.js +0 -135
- package/src/AI_Brain/headless_agent.js +0 -143
- package/src/AI_Brain/knowledge_base.js +0 -349
- package/src/AI_Brain/memory_store.js +0 -662
- package/src/AI_Brain/proactive_engine.js +0 -172
- package/src/AI_Brain/provider_adapter.js +0 -365
- package/src/Automation_Layer/browser_automation.js +0 -149
- package/src/Automation_Layer/file_operations.js +0 -286
- package/src/Automation_Layer/open_app.js +0 -85
- package/src/Automation_Layer/open_website.js +0 -38
- package/src/CLI/approval_handler.js +0 -47
- package/src/CLI/chat_router.js +0 -247
- package/src/CLI/chat_ui.js +0 -1159
- package/src/CLI/cli_colors.js +0 -115
- package/src/CLI/cli_formatters.js +0 -94
- package/src/CLI/code_agent.js +0 -1667
- package/src/CLI/code_session_memory.js +0 -62
- package/src/CLI/gmail_auth.js +0 -210
- package/src/CLI/image_input.js +0 -90
- package/src/CLI/intent_detectors.js +0 -181
- package/src/CLI/interactive_chat.js +0 -658
- package/src/CLI/list_features.js +0 -64
- package/src/CLI/onboarding.js +0 -416
- package/src/CLI/repo_summarizer.js +0 -282
- package/src/CLI/semantic_code_search.js +0 -312
- package/src/CLI/skill_manager.js +0 -41
- package/src/CLI/slash_command_handler.js +0 -418
- package/src/CLI/symbol_indexer.js +0 -231
- package/src/CLI/updater.js +0 -230
- package/src/CLI/workspace_manager.js +0 -90
- package/src/Channels/brave_search_bridge.js +0 -35
- package/src/Channels/discord_bridge.js +0 -66
- package/src/Channels/google_search_bridge.js +0 -38
- package/src/Channels/line_bridge.js +0 -60
- package/src/Channels/slack_bridge.js +0 -48
- package/src/Channels/telegram_bridge.js +0 -41
- package/src/Channels/whatsapp_bridge.js +0 -57
- package/src/Command_Parser/parser.js +0 -45
- package/src/Plugins/dev_tools.js +0 -41
- package/src/Plugins/discord.js +0 -20
- package/src/Plugins/docker.js +0 -47
- package/src/Plugins/gmail.js +0 -251
- package/src/Plugins/google_calendar.js +0 -252
- package/src/Plugins/mcp_manager.js +0 -95
- package/src/Plugins/notion.js +0 -256
- package/src/Plugins/obsidian.js +0 -54
- package/src/Plugins/plugin_manager.js +0 -81
- package/src/Plugins/spotify.js +0 -173
- package/src/Plugins/system_metrics.js +0 -31
- package/src/Plugins/system_monitor.js +0 -72
- package/src/System/action_executor.js +0 -178
- package/src/System/bridge_manager.js +0 -76
- package/src/System/chat_history_manager.js +0 -83
- package/src/System/config_manager.js +0 -194
- package/src/System/custom_workflows.js +0 -163
- package/src/System/daemon_manager.js +0 -67
- package/src/System/google_tts_urls.js +0 -51
- package/src/System/granular_automation.js +0 -157
- package/src/System/ipc_handlers.js +0 -332
- package/src/System/notifications.js +0 -23
- package/src/System/optional_require.js +0 -23
- package/src/System/picture_store.js +0 -109
- package/src/System/proactive_loop.js +0 -153
- package/src/System/safety_manager.js +0 -273
- package/src/System/sandbox_runner.js +0 -182
- package/src/System/screen_capture.js +0 -175
- package/src/System/smart_context.js +0 -227
- package/src/System/system_automation.js +0 -162
- package/src/System/system_events.js +0 -79
- package/src/System/system_info.js +0 -125
- package/src/System/task_manager.js +0 -222
- package/src/System/tool_registry.js +0 -293
- package/src/System/window_manager.js +0 -220
- package/src/UI/floating.css +0 -80
- package/src/UI/floating.html +0 -17
- package/src/UI/floating.js +0 -67
- package/src/UI/live2d_manager.js +0 -600
- package/src/UI/preload-floating.js +0 -7
- package/src/UI/preload-spotlight.js +0 -11
- package/src/UI/preload-widget.js +0 -5
- package/src/UI/proactive-glow.html +0 -42
- package/src/UI/renderer.js +0 -2127
- package/src/UI/screenPicker.html +0 -214
- package/src/UI/screenPicker.js +0 -262
- package/src/UI/settings.html +0 -577
- package/src/UI/settings.js +0 -770
- package/src/UI/spotlight.html +0 -23
- package/src/UI/spotlight.js +0 -185
- package/src/UI/widget.html +0 -29
- package/src/UI/widget.js +0 -10
- /package/{models → src/renderer/public/models}/Shiroko_Model/Shiroko/Shiroko_Core/72d86db84cfa9730b894c241fd24c0db.png +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//345/233/264/350/243/231.exp3.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/apron.exp3.json} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//347/214/253/345/222/252/346/273/244/351/225/234.exp3.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/catfilter.exp3.json} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//347/202/271/344/270/200/344/270/213.exp3.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/click.exp3.json} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//345/221/206/347/214/253.exp3.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/dazed.exp3.json} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//345/221/206/347/214/253/347/234/274/347/217/240/346/221/207/346/231/203.exp3.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/dazedeyes.exp3.json} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//347/234/274/351/225/234.exp3.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/glasses.exp3.json} +0 -0
- /package/{models → src/renderer/public/models}/Shiroko_Model/Shiroko/Shiroko_Core/items_pinned_to_model.json +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//346/213/277/347/254/224.exp3.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/pen.exp3.json} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//346/213/215/347/205/247.exp3.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/photo.exp3.json} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//351/235/242/351/245/2740.4096/texture_00.png" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/shiroko.4096/texture_00.png} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//351/235/242/351/245/2740.4096/texture_01.png" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/shiroko.4096/texture_01.png} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//351/235/242/351/245/2740.4096/texture_02.png" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/shiroko.4096/texture_02.png} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//351/235/242/351/245/2740.4096/texture_03.png" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/shiroko.4096/texture_03.png} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//351/235/242/351/245/2740.cdi3.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/shiroko.cdi3.json} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//351/235/242/351/245/2740.moc3" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/shiroko.moc3} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//351/235/242/351/245/2740.physics3.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/shiroko.physics3.json} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//351/235/242/351/245/2740.vtube.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/shiroko.vtube.json} +0 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
use std::{
|
|
2
|
+
collections::BTreeMap,
|
|
3
|
+
io::{BufRead, BufReader, Write},
|
|
4
|
+
process::{Child, Command, Stdio},
|
|
5
|
+
sync::mpsc,
|
|
6
|
+
time::{Duration, Instant},
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
use serde::{Deserialize, Serialize};
|
|
10
|
+
use serde_json::{Value, json};
|
|
11
|
+
use thiserror::Error;
|
|
12
|
+
|
|
13
|
+
use crate::{ConfigError, MintConfig, load_config, save_config};
|
|
14
|
+
|
|
15
|
+
const MCP_TIMEOUT: Duration = Duration::from_secs(10);
|
|
16
|
+
|
|
17
|
+
#[derive(Debug, Clone, Deserialize, Serialize)]
|
|
18
|
+
pub struct McpServer {
|
|
19
|
+
pub command: String,
|
|
20
|
+
#[serde(default)]
|
|
21
|
+
pub args: Vec<String>,
|
|
22
|
+
#[serde(default)]
|
|
23
|
+
pub env: BTreeMap<String, String>,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
#[derive(Debug, Error)]
|
|
27
|
+
pub enum McpError {
|
|
28
|
+
#[error(transparent)]
|
|
29
|
+
Config(#[from] ConfigError),
|
|
30
|
+
#[error("invalid MCP configuration: {0}")]
|
|
31
|
+
InvalidConfig(#[from] serde_json::Error),
|
|
32
|
+
#[error("MCP environment value must use KEY=VALUE format")]
|
|
33
|
+
InvalidEnvironment,
|
|
34
|
+
#[error("MCP server '{0}' is not configured")]
|
|
35
|
+
MissingServer(String),
|
|
36
|
+
#[error("MCP tool '{server}/{tool}' is not allowed by policy")]
|
|
37
|
+
NotAllowed { server: String, tool: String },
|
|
38
|
+
#[error("unable to start MCP server '{command}': {source}")]
|
|
39
|
+
Start {
|
|
40
|
+
command: String,
|
|
41
|
+
source: std::io::Error,
|
|
42
|
+
},
|
|
43
|
+
#[error("MCP server stdin is unavailable")]
|
|
44
|
+
MissingStdin,
|
|
45
|
+
#[error("MCP server stdout is unavailable")]
|
|
46
|
+
MissingStdout,
|
|
47
|
+
#[error("unable to write MCP request: {0}")]
|
|
48
|
+
Write(std::io::Error),
|
|
49
|
+
#[error("MCP server response timed out")]
|
|
50
|
+
Timeout,
|
|
51
|
+
#[error("MCP tool call failed: {0}")]
|
|
52
|
+
Tool(Value),
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
pub fn configured_mcp_servers(
|
|
56
|
+
config: &MintConfig,
|
|
57
|
+
) -> Result<BTreeMap<String, McpServer>, McpError> {
|
|
58
|
+
Ok(config
|
|
59
|
+
.extra
|
|
60
|
+
.get("mcpServers")
|
|
61
|
+
.cloned()
|
|
62
|
+
.map(serde_json::from_value)
|
|
63
|
+
.transpose()?
|
|
64
|
+
.unwrap_or_default())
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
pub fn list_mcp_servers() -> Result<BTreeMap<String, McpServer>, McpError> {
|
|
68
|
+
configured_mcp_servers(&load_config()?)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
pub fn add_mcp_server(
|
|
72
|
+
name: &str,
|
|
73
|
+
command: &str,
|
|
74
|
+
args: Vec<String>,
|
|
75
|
+
env: Vec<String>,
|
|
76
|
+
) -> Result<(), McpError> {
|
|
77
|
+
let mut config = load_config()?;
|
|
78
|
+
let mut servers = configured_mcp_servers(&config)?;
|
|
79
|
+
servers.insert(
|
|
80
|
+
name.into(),
|
|
81
|
+
McpServer {
|
|
82
|
+
command: command.into(),
|
|
83
|
+
args,
|
|
84
|
+
env: parse_env(env)?,
|
|
85
|
+
},
|
|
86
|
+
);
|
|
87
|
+
save_mcp_servers(&mut config, servers)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
pub fn remove_mcp_server(name: &str) -> Result<bool, McpError> {
|
|
91
|
+
let mut config = load_config()?;
|
|
92
|
+
let mut servers = configured_mcp_servers(&config)?;
|
|
93
|
+
let removed = servers.remove(name).is_some();
|
|
94
|
+
save_mcp_servers(&mut config, servers)?;
|
|
95
|
+
Ok(removed)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
pub fn clear_mcp_servers() -> Result<(), McpError> {
|
|
99
|
+
let mut config = load_config()?;
|
|
100
|
+
save_mcp_servers(&mut config, BTreeMap::new())
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
pub fn call_mcp_tool(
|
|
104
|
+
config: &MintConfig,
|
|
105
|
+
server_name: &str,
|
|
106
|
+
tool_name: &str,
|
|
107
|
+
arguments: Value,
|
|
108
|
+
) -> Result<Value, McpError> {
|
|
109
|
+
if !mcp_tool_allowed(config, server_name, tool_name) {
|
|
110
|
+
return Err(McpError::NotAllowed {
|
|
111
|
+
server: server_name.into(),
|
|
112
|
+
tool: tool_name.into(),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
let servers = configured_mcp_servers(config)?;
|
|
116
|
+
let server = servers
|
|
117
|
+
.get(server_name)
|
|
118
|
+
.ok_or_else(|| McpError::MissingServer(server_name.into()))?;
|
|
119
|
+
let mut process = start_server(server)?;
|
|
120
|
+
let result = exchange(
|
|
121
|
+
&mut process,
|
|
122
|
+
json!({
|
|
123
|
+
"jsonrpc": "2.0",
|
|
124
|
+
"id": 2,
|
|
125
|
+
"method": "tools/call",
|
|
126
|
+
"params": { "name": tool_name, "arguments": arguments }
|
|
127
|
+
}),
|
|
128
|
+
);
|
|
129
|
+
let _ = process.kill();
|
|
130
|
+
result
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
fn mcp_tool_allowed(config: &MintConfig, server_name: &str, tool_name: &str) -> bool {
|
|
134
|
+
config
|
|
135
|
+
.extra
|
|
136
|
+
.get("allowedMcpTools")
|
|
137
|
+
.and_then(|value| value.as_object())
|
|
138
|
+
.map(|servers| {
|
|
139
|
+
servers
|
|
140
|
+
.get("*")
|
|
141
|
+
.is_some_and(|tools| tool_allowed(tools, tool_name))
|
|
142
|
+
|| servers
|
|
143
|
+
.get(server_name)
|
|
144
|
+
.is_some_and(|tools| tool_allowed(tools, tool_name))
|
|
145
|
+
})
|
|
146
|
+
.unwrap_or(false)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
fn tool_allowed(tools: &Value, tool_name: &str) -> bool {
|
|
150
|
+
tools
|
|
151
|
+
.as_array()
|
|
152
|
+
.map(|values| {
|
|
153
|
+
values
|
|
154
|
+
.iter()
|
|
155
|
+
.filter_map(|value| value.as_str())
|
|
156
|
+
.any(|value| value == "*" || value == tool_name)
|
|
157
|
+
})
|
|
158
|
+
.unwrap_or(false)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
pub fn call_configured_mcp_tool(
|
|
162
|
+
server_name: &str,
|
|
163
|
+
tool_name: &str,
|
|
164
|
+
arguments: Value,
|
|
165
|
+
) -> Result<Value, McpError> {
|
|
166
|
+
call_mcp_tool(&load_config()?, server_name, tool_name, arguments)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
fn save_mcp_servers(
|
|
170
|
+
config: &mut MintConfig,
|
|
171
|
+
servers: BTreeMap<String, McpServer>,
|
|
172
|
+
) -> Result<(), McpError> {
|
|
173
|
+
config
|
|
174
|
+
.extra
|
|
175
|
+
.insert("mcpServers".into(), serde_json::to_value(servers)?);
|
|
176
|
+
Ok(save_config(config)?)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
fn parse_env(values: Vec<String>) -> Result<BTreeMap<String, String>, McpError> {
|
|
180
|
+
values
|
|
181
|
+
.into_iter()
|
|
182
|
+
.map(|value| {
|
|
183
|
+
let (key, value) = value.split_once('=').ok_or(McpError::InvalidEnvironment)?;
|
|
184
|
+
Ok((key.into(), value.into()))
|
|
185
|
+
})
|
|
186
|
+
.collect()
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
fn start_server(server: &McpServer) -> Result<Child, McpError> {
|
|
190
|
+
let mut process = Command::new(&server.command)
|
|
191
|
+
.args(&server.args)
|
|
192
|
+
.envs(&server.env)
|
|
193
|
+
.stdin(Stdio::piped())
|
|
194
|
+
.stdout(Stdio::piped())
|
|
195
|
+
.stderr(Stdio::null())
|
|
196
|
+
.spawn()
|
|
197
|
+
.map_err(|source| McpError::Start {
|
|
198
|
+
command: server.command.clone(),
|
|
199
|
+
source,
|
|
200
|
+
})?;
|
|
201
|
+
write_message(
|
|
202
|
+
&mut process,
|
|
203
|
+
&json!({
|
|
204
|
+
"jsonrpc": "2.0",
|
|
205
|
+
"id": 1,
|
|
206
|
+
"method": "initialize",
|
|
207
|
+
"params": {
|
|
208
|
+
"protocolVersion": "2025-06-18",
|
|
209
|
+
"capabilities": {},
|
|
210
|
+
"clientInfo": { "name": "mint", "version": env!("CARGO_PKG_VERSION") }
|
|
211
|
+
}
|
|
212
|
+
}),
|
|
213
|
+
)?;
|
|
214
|
+
write_message(
|
|
215
|
+
&mut process,
|
|
216
|
+
&json!({ "jsonrpc": "2.0", "method": "notifications/initialized" }),
|
|
217
|
+
)?;
|
|
218
|
+
Ok(process)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
fn exchange(process: &mut Child, request: Value) -> Result<Value, McpError> {
|
|
222
|
+
write_message(process, &request)?;
|
|
223
|
+
let stdout = process.stdout.take().ok_or(McpError::MissingStdout)?;
|
|
224
|
+
let (sender, receiver) = mpsc::channel();
|
|
225
|
+
std::thread::spawn(move || {
|
|
226
|
+
for line in BufReader::new(stdout).lines().map_while(Result::ok) {
|
|
227
|
+
if let Ok(value) = serde_json::from_str::<Value>(&line) {
|
|
228
|
+
let _ = sender.send(value);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
let started = Instant::now();
|
|
233
|
+
while started.elapsed() < MCP_TIMEOUT {
|
|
234
|
+
let response = receiver
|
|
235
|
+
.recv_timeout(MCP_TIMEOUT.saturating_sub(started.elapsed()))
|
|
236
|
+
.map_err(|_| McpError::Timeout)?;
|
|
237
|
+
if response["id"] == 2 {
|
|
238
|
+
if let Some(error) = response.get("error") {
|
|
239
|
+
return Err(McpError::Tool(error.clone()));
|
|
240
|
+
}
|
|
241
|
+
return Ok(response.get("result").cloned().unwrap_or(Value::Null));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
Err(McpError::Timeout)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
fn write_message(process: &mut Child, message: &Value) -> Result<(), McpError> {
|
|
248
|
+
let stdin = process.stdin.as_mut().ok_or(McpError::MissingStdin)?;
|
|
249
|
+
writeln!(stdin, "{message}").map_err(McpError::Write)?;
|
|
250
|
+
stdin.flush().map_err(McpError::Write)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
#[cfg(test)]
|
|
254
|
+
mod tests {
|
|
255
|
+
use super::*;
|
|
256
|
+
|
|
257
|
+
#[test]
|
|
258
|
+
fn rejects_environment_without_equals_separator() {
|
|
259
|
+
assert!(matches!(
|
|
260
|
+
parse_env(vec!["TOKEN".into()]),
|
|
261
|
+
Err(McpError::InvalidEnvironment)
|
|
262
|
+
));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
#[test]
|
|
266
|
+
fn rejects_mcp_tool_not_in_allowlist() {
|
|
267
|
+
let config = MintConfig::default();
|
|
268
|
+
assert!(matches!(
|
|
269
|
+
call_mcp_tool(&config, "fake", "ping", json!({})),
|
|
270
|
+
Err(McpError::NotAllowed { .. })
|
|
271
|
+
));
|
|
272
|
+
}
|
|
273
|
+
}
|