-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
28 lines (22 loc) · 913 Bytes
/
server.py
File metadata and controls
28 lines (22 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# server.py
from mcp.server.fastmcp import FastMCP
import clickhouse_connect
import os
# Create an MCP server
mcp = FastMCP("OmopServer")
@mcp.tool()
async def query_omop_database(query: str) -> list:
"""Query the OMOP database and return results as a dictionary with column names as keys"""
client = await clickhouse_connect.get_async_client(
host=os.getenv("CLICKHOUSE_HOST", "localhost"),
port=os.getenv("CLICKHOUSE_PORT", 8123),
username=os.getenv("CLICKHOUSE_USER", "default"),
password=os.getenv("CLICKHOUSE_PASSWORD", "default"),
database=os.getenv("CLICKHOUSE_DB", "omop")
)
result = await client.query(query)
# Create a list of dictionaries where each dictionary represents a row
# with column names as keys
return [dict(zip(result.column_names, row)) for row in result.result_rows]
if __name__ == "__main__":
mcp.run()