Skip to content

Commit 05d52ce

Browse files
authored
add ai libs check (#5)
1 parent 0437835 commit 05d52ce

File tree

5 files changed

+39
-5
lines changed

5 files changed

+39
-5
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ Before installing and running the KDB-X MCP Server, ensure you have met the foll
6666
- `npx` comes bundled with the [nodejs](https://nodejs.org/en) installer - available on Windows/Mac/Linux/WSL
6767
- See [example configuration with streamable-http](#example-configuration-with-streamable-http)
6868

69+
> Note: ⚠️ KDB-X public preview has recently been extended. If you have installed KDB-X prior to Sept 30th 2025, you will receive an email notification about this update. Please update to the latest [KDB-X](https://kdb-x.kx.com/sign-in) to ensure uninterrupted access, valid through January 4, 2026
70+
6971
## Quickstart
7072

7173
To demonstrate basic usage of the KDB-X MCP Server, using an empty KDB-X database, follow the quickstart steps below.
@@ -438,6 +440,10 @@ The below tools can aid in the development, testing and debugging of new MCP too
438440

439441
## Troubleshooting
440442

443+
### KDB-X license expired
444+
445+
KDB-X public preview has recently been extended. If you have installed KDB-X prior to Sept 30th 2025, you will receive an email notification about this update. Please update to the latest [KDB-X](https://kdb-x.kx.com/sign-in) to ensure uninterrupted access, valid through January 4, 2026
446+
441447
### KDB-X connection error
442448

443449
Ensure that your KDB-X database is online and accessible on the specified kdb host and port.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ readme = "README.md"
66
requires-python = ">=3.11"
77
dependencies = [
88
"mcp[cli]>=1.2.0",
9-
"pykx>=4.0.0.b2",
9+
"pykx>=4.0.0.b3",
1010
"pydantic-settings",
1111
# Optional: Manage below packages for embedding support
1212
# "sentence_transformers",

src/mcp_server/server.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ def __init__(self, kdbx_mcp_transport=None, kdbx_mcp_port=None, kdbx_host=None,
5555
self.host = self.settings.host
5656
self.transport = self.settings.transport
5757

58+
# Global flag to track AI Libs availability
59+
_ai_libs_available = False
60+
61+
def set_ai_libs_available(available: bool):
62+
global _ai_libs_available
63+
_ai_libs_available = available
64+
65+
def is_ai_libs_available() -> bool:
66+
return _ai_libs_available
67+
5868
class McpServer:
5969

6070
def __init__(self, config: Optional[MCPServerConfig] = None):
@@ -111,11 +121,18 @@ def _check_kdb_connection(self):
111121
if not conn('@[{2< count .s};(::);{0b}]').py():
112122
self.logger.error("KDB-X SQL interface check: FAILED - KDB-X service does not have the SQL interface loaded. Load it by running .s.init[] in your KDB-X Session")
113123
sys.exit(1)
114-
if not conn('@[{2< count .ai};(::);{0b}]').py():
115-
self.logger.error("KDB-X AI Libs check: FAILED - KDB-X service does not have the AI Libs loaded. Load it by running \l ai-libs/init.q in your KDB-X Session")
116-
sys.exit(1)
117124
else:
118125
self.logger.info("KDB-X SQL interface check: SUCCESS - SQL interface is loaded")
126+
127+
# check if AI libs are loaded on KDB-X service
128+
ai_libs_available = conn('@[{2< count .ai};(::);{0b}]').py()
129+
if not ai_libs_available:
130+
self.logger.warning("KDB-X AI Libs check: NOT AVAILABLE - AI-powered tools (similarity_search, hybrid_search) will be disabled.")
131+
self.logger.warning("To enable AI tools, load the KDB-X AI libraries by running: \l ai-libs/init.q in your KDB-X Session and then restart the MCP server")
132+
else:
133+
self.logger.info("KDB-X AI Libs check: SUCCESS - AI Libs are loaded, AI tools will be available")
134+
135+
set_ai_libs_available(ai_libs_available)
119136
conn.close()
120137

121138
except QError as e:

src/mcp_server/tools/kdbx_sim_search.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ async def kdbx_similarity_search_impl( table_name: str,
9090

9191

9292
def register_tools(mcp_server):
93+
# Check if AI Libs are available
94+
try:
95+
from mcp_server.server import is_ai_libs_available
96+
97+
if not is_ai_libs_available():
98+
logger.info("AI Libs not available - skipping...")
99+
return []
100+
except Exception as e:
101+
logger.warning(f"Could not check AI Libs availability: {e}. Skipping AI tools.")
102+
return []
103+
93104
@mcp_server.tool()
94105
async def kdbx_similarity_search(table_name: str,
95106
query: str,

src/mcp_server/utils/embeddings_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ def get_embedding_config(
4040
row = matching_rows.iloc[0]
4141

4242
# Choose columns based on config_type flag
43-
return [row['embedding_column'], row['embedding_provider'], row['embedding_model'], row['sparse_tokenizer_provider'], row['sparse_tokenizer_model']]
43+
return [row['embedding_column'], row['embedding_provider'], row['embedding_model'], row['sparse_tokenizer_provider'], row['sparse_tokenizer_model']]

0 commit comments

Comments
 (0)