chore: add mcp write and read commands
This commit is contained in:
parent
72cb1c16cc
commit
80d11e1057
@ -7,6 +7,9 @@ use tauri::{AppHandle, Manager, Runtime, State};
|
||||
use super::{server, setup, state::AppState};
|
||||
|
||||
const CONFIGURATION_FILE_NAME: &str = "settings.json";
|
||||
const DEFAULT_MCP_CONFIG: &str = r#"{
|
||||
"mcpServers": {}
|
||||
}"#;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct AppConfiguration {
|
||||
@ -352,3 +355,29 @@ pub async fn call_tool(
|
||||
|
||||
Err(format!("Tool {} not found", tool_name))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_mcp_configs(app: AppHandle) -> Result<String, String> {
|
||||
let mut path = get_jan_data_folder_path(app);
|
||||
path.push("mcp_config.json");
|
||||
log::info!("read mcp configs, path: {:?}", path);
|
||||
|
||||
// Create default empty config if file doesn't exist
|
||||
if !path.exists() {
|
||||
log::info!("mcp_config.json not found, creating default empty config");
|
||||
fs::write(&path, DEFAULT_MCP_CONFIG)
|
||||
.map_err(|e| format!("Failed to create default MCP config: {}", e))?;
|
||||
}
|
||||
|
||||
let contents = fs::read_to_string(path).map_err(|e| e.to_string())?;
|
||||
return Ok(contents);
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn save_mcp_configs(app: AppHandle, configs: String) -> Result<(), String> {
|
||||
let mut path = get_jan_data_folder_path(app);
|
||||
path.push("mcp_config.json");
|
||||
log::info!("save mcp configs, path: {:?}", path);
|
||||
|
||||
fs::write(path, configs).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
@ -39,6 +39,8 @@ pub fn run() {
|
||||
core::cmd::app_token,
|
||||
core::cmd::start_server,
|
||||
core::cmd::stop_server,
|
||||
core::cmd::save_mcp_configs,
|
||||
core::cmd::get_mcp_configs,
|
||||
// MCP commands
|
||||
core::cmd::get_tools,
|
||||
core::cmd::call_tool,
|
||||
|
||||
@ -17,31 +17,9 @@ const MCP = () => {
|
||||
|
||||
const readConfigFile = useCallback(async () => {
|
||||
try {
|
||||
const configPath = await joinPath([janDataFolderPath, 'mcp_config.json'])
|
||||
|
||||
// Check if the file exists
|
||||
const fileExists = await fs.existsSync(configPath)
|
||||
|
||||
if (fileExists) {
|
||||
// Read the file
|
||||
const content = await fs.readFileSync(configPath, 'utf-8')
|
||||
const content = await window.core?.api.getMcpConfigs()
|
||||
setConfigContent(content)
|
||||
} else {
|
||||
// Create a default config if it doesn't exist
|
||||
const defaultConfig = JSON.stringify(
|
||||
{
|
||||
servers: [],
|
||||
settings: {
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
|
||||
await fs.writeFileSync(configPath, defaultConfig)
|
||||
setConfigContent(defaultConfig)
|
||||
}
|
||||
|
||||
setError('')
|
||||
} catch (err) {
|
||||
@ -70,11 +48,7 @@ const MCP = () => {
|
||||
setIsSaving(false)
|
||||
return
|
||||
}
|
||||
|
||||
const configPath = await joinPath([janDataFolderPath, 'mcp_config.json'])
|
||||
|
||||
// Write to the file
|
||||
await fs.writeFileSync(configPath, configContent)
|
||||
await window.core?.api?.saveMcpConfigs({ configs: configContent })
|
||||
|
||||
setSuccess('Config saved successfully')
|
||||
setIsSaving(false)
|
||||
|
||||
@ -19,6 +19,8 @@ export const Routes = [
|
||||
'getThreadAssistant',
|
||||
'createThreadAssistant',
|
||||
'modifyThreadAssistant',
|
||||
'saveMcpConfigs',
|
||||
'getMcpConfigs',
|
||||
].map((r) => ({
|
||||
path: `app`,
|
||||
route: r,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user