forked from secoda/secoda-mcp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
84 lines (60 loc) · 2.01 KB
/
server.py
File metadata and controls
84 lines (60 loc) · 2.01 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import json
import os
import typing
import requests
from fastmcp import FastMCP
from prompt import MCP_PROMPT
# --------------------------------
# Configuration
# --------------------------------
API_URL = os.getenv("API_URL", "https://app.secoda.co/api/v1/")
API_TOKEN = os.getenv("API_TOKEN")
# --------------------------------
# Tools
# --------------------------------
mcp = FastMCP(
name="Secoda MCP",
instructions=MCP_PROMPT,
)
def call_tool(tool_name: str, args: dict):
"""Call a tool."""
api_url = API_URL if API_URL.endswith("/") else f"{API_URL}/"
response = requests.post(
f"{api_url}ai/mcp/tools/call/",
headers={
"Authorization": f"Bearer {API_TOKEN}",
"Content-Type": "application/json",
},
json={
"name": tool_name,
"arguments": args,
},
)
response.raise_for_status()
return json.dumps(response.json())
@mcp.tool()
def run_sql(query: str, integration_id: typing.Optional[str] = None) -> str:
"""Run a SQL query on the database."""
return call_tool("run_sql", {"query": query, "integration_id": integration_id})
@mcp.tool()
def search_data_assets(query: str, page: int = 1) -> str:
"""Search for data assets in the database."""
return call_tool("search_data_assets", {"query": query, "page": page})
@mcp.tool()
def search_documentation(query: str, page: int = 1) -> str:
"""Search for documentation in the database."""
return call_tool("search_documentation", {"query": query, "page": page})
@mcp.tool()
def retrieve_entity(entity_id: str) -> str:
"""Retrieve an entity from the database."""
return call_tool("retrieve_entity", {"entity_id": entity_id})
@mcp.tool()
def entity_lineage(entity_id: str) -> str:
"""Retrieve the lineage of an entity."""
return call_tool("entity_lineage", {"entity_id": entity_id})
@mcp.tool()
def glossary() -> str:
"""Retrieve the glossary."""
return call_tool("glossary", {})
if __name__ == "__main__":
mcp.run()