From 44ecc2dab8bc2286b73372987b91485fed79d303 Mon Sep 17 00:00:00 2001 From: Charles Packer Date: Sat, 15 Mar 2025 13:45:20 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20don't=20throw=20an=20error=20if=20adding?= =?UTF-8?q?=20a=20new=20mcp=20server,=20also=20allow=20sett=E2=80=A6=20(#1?= =?UTF-8?q?293)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- letta/server/server.py | 17 ++++++++++++++++- letta/settings.py | 3 +++ tests/test_client.py | 4 +--- tests/test_streaming.py | 2 -- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/letta/server/server.py b/letta/server/server.py index 8e9ff8dc..4b199853 100644 --- a/letta/server/server.py +++ b/letta/server/server.py @@ -1266,6 +1266,11 @@ class SyncServer(Server): # TODO support both command + SSE servers (via config) def get_mcp_servers(self) -> dict[str, Union[SSEServerConfig, StdioServerConfig]]: """List the MCP servers in the config (doesn't test that they are actually working)""" + + # TODO implement non-flatfile mechanism + if not tool_settings.mcp_read_from_config: + raise RuntimeError("MCP config file disabled. Enable it in settings.") + mcp_server_list = {} # Attempt to read from ~/.letta/mcp_config.json @@ -1329,10 +1334,15 @@ class SyncServer(Server): ) -> dict[str, Union[SSEServerConfig, StdioServerConfig]]: """Add a new server config to the MCP config file""" + # TODO implement non-flatfile mechanism + if not tool_settings.mcp_read_from_config: + raise RuntimeError("MCP config file disabled. Enable it in settings.") + # If the config file doesn't exist, throw an error. mcp_config_path = os.path.join(constants.LETTA_DIR, constants.MCP_CONFIG_NAME) if not os.path.exists(mcp_config_path): - raise FileNotFoundError(f"MCP config file not found: {mcp_config_path}") + # Create the file if it doesn't exist + logger.debug(f"MCP config file not found, creating new file at: {mcp_config_path}") # If the file does exist, attempt to parse it get calling get_mcp_servers try: @@ -1384,9 +1394,14 @@ class SyncServer(Server): def delete_mcp_server_from_config(self, server_name: str) -> dict[str, Union[SSEServerConfig, StdioServerConfig]]: """Delete a server config from the MCP config file""" + # TODO implement non-flatfile mechanism + if not tool_settings.mcp_read_from_config: + raise RuntimeError("MCP config file disabled. Enable it in settings.") + # If the config file doesn't exist, throw an error. mcp_config_path = os.path.join(constants.LETTA_DIR, constants.MCP_CONFIG_NAME) if not os.path.exists(mcp_config_path): + # If the file doesn't exist, raise an error raise FileNotFoundError(f"MCP config file not found: {mcp_config_path}") # If the file does exist, attempt to parse it get calling get_mcp_servers diff --git a/letta/settings.py b/letta/settings.py index bb8eae16..81c9f2ff 100644 --- a/letta/settings.py +++ b/letta/settings.py @@ -18,6 +18,9 @@ class ToolSettings(BaseSettings): # Local Sandbox configurations local_sandbox_dir: Optional[str] = None + # MCP read from config file + mcp_read_from_config: bool = True # if False, will throw if attempting to read/write from file + class SummarizerSettings(BaseSettings): model_config = SettingsConfigDict(env_prefix="letta_summarizer_", extra="ignore") diff --git a/tests/test_client.py b/tests/test_client.py index 856c4227..5dcb7da6 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,14 +1,12 @@ import asyncio -import json import os import threading import time import uuid -from typing import List, Union import pytest from dotenv import load_dotenv -from letta_client import AgentState, JobStatus, Letta, MessageCreate, MessageRole +from letta_client import AgentState, Letta, MessageCreate from letta_client.core.api_error import ApiError from sqlalchemy import delete diff --git a/tests/test_streaming.py b/tests/test_streaming.py index 635677f0..55300ab5 100644 --- a/tests/test_streaming.py +++ b/tests/test_streaming.py @@ -5,8 +5,6 @@ import time import pytest from dotenv import load_dotenv from letta_client import AgentState, Letta, LlmConfig, MessageCreate -from letta_client.core.api_error import ApiError -from pytest import fixture def run_server():