Skip to content

Commit 7e6f7b2

Browse files
FabioLissikAI Shtefan
authored andcommitted
fix: propagate EmbeddingModelMismatchError through MCP tools
@NickShtefan fixed the CLI path in PR MemPalace#442 (searcher.py) by re-raising EmbeddingModelMismatchError past the generic except clause. The MCP path had the same bug via two additional swallows: - mcp_server.py:_get_collection() wraps _palace_get_collection in except Exception: return None, so every tool using _get_collection (status, list_wings, list_rooms, get_taxonomy, check_duplicate, search, etc.) silently showed "No palace found" instead of the actual mismatch error. - The top-level dispatcher in handle_request() catches Exception and returns hardcoded "Internal tool error", so even if the wrapper re-raises, the actionable message (stored vs current model + recovery instructions) never reaches the caller. Fix in three spots: 1. searcher.py: re-raise EmbeddingModelMismatchError in search() and search_memories() before the generic except (matches @NickShtefan's fix). 2. mcp_server.py:_get_collection(): re-raise EmbeddingModelMismatchError before the generic swallow. 3. mcp_server.py handle_request(): catch EmbeddingModelMismatchError explicitly and return the message as a JSON result so MCP clients see the real error and recovery instructions.
1 parent 1e00e19 commit 7e6f7b2

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

mempalace/mcp_server.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@
2626
from datetime import datetime
2727
from pathlib import Path
2828

29-
from .config import MempalaceConfig, sanitize_name, sanitize_content
29+
from .config import (
30+
EmbeddingModelMismatchError,
31+
MempalaceConfig,
32+
sanitize_name,
33+
sanitize_content,
34+
)
3035
from .version import __version__
3136
from .palace import get_collection as _get_collection_from_palace
3237
from .query_sanitizer import sanitize_query
@@ -111,6 +116,8 @@ def _get_collection(create=False):
111116
create=create,
112117
)
113118
return _collection_cache
119+
except EmbeddingModelMismatchError:
120+
raise
114121
except Exception:
115122
return None
116123

@@ -981,6 +988,17 @@ def handle_request(request):
981988
"id": req_id,
982989
"result": {"content": [{"type": "text", "text": json.dumps(result, indent=2)}]},
983990
}
991+
except EmbeddingModelMismatchError as e:
992+
logger.error(f"Embedding model mismatch in {tool_name}: {e}")
993+
return {
994+
"jsonrpc": "2.0",
995+
"id": req_id,
996+
"result": {
997+
"content": [
998+
{"type": "text", "text": json.dumps({"error": str(e)}, indent=2)}
999+
]
1000+
},
1001+
}
9841002
except Exception:
9851003
logger.exception(f"Tool error in {tool_name}")
9861004
return {

0 commit comments

Comments
 (0)