1- import os
2-
31import httpx
4-
52from mcp .server .fastmcp import FastMCP
63
7- from .constants import Queries , DOCUMENTATION_INDEX
4+ from .constants import DOCUMENTATION_INDEX , Queries
5+ from .settings import HTTP_URL
86
97mcp = FastMCP ("cratedb-mcp" )
108
119
1210def query_cratedb (query : str ) -> list [dict ]:
13- return httpx .post (f'{ os . getenv ( "CRATEDB_MCP_HTTP_URL" ) } /_sql' , json = {'stmt' : query }).json ()
11+ return httpx .post (f'{ HTTP_URL } /_sql' , json = {'stmt' : query }).json ()
1412
1513
1614@mcp .tool (description = "Send a SQL query to CrateDB, only 'SELECT' queries are allows, queries that"
1715 " modify data, columns or are otherwise deemed un-safe are rejected." )
1816def query_sql (query : str ):
19- if not 'select' in query .lower ():
17+ if 'select' not in query .lower ():
2018 raise ValueError ('Only queries that have a SELECT statement are allowed.' )
2119 return query_cratedb (query )
2220
@@ -29,7 +27,7 @@ def get_cratedb_documentation_index():
2927 ' Only used to download CrateDB docs.' )
3028def fetch_cratedb_docs (link : str ):
3129 """Fetches a CrateDB documentation link from GitHub raw content."""
32- if not 'https://raw.githubusercontent.com/crate/crate/' in link :
30+ if 'https://raw.githubusercontent.com/crate/crate/' not in link :
3331 raise ValueError ('Only github cratedb links can be fetched.' )
3432 return httpx .get (link ).text
3533
0 commit comments