Update mcp_server.py
Browse files- mcp_server.py +26 -23
mcp_server.py
CHANGED
|
@@ -1,38 +1,39 @@
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import json
|
| 3 |
import sqlite3
|
| 4 |
-
|
| 5 |
from mcp.server.fastmcp import FastMCP
|
| 6 |
-
from connectors
|
| 7 |
|
| 8 |
mcp = FastMCP("EnterpriseData")
|
| 9 |
|
| 10 |
-
# βββ 1
|
| 11 |
conn = sqlite3.connect(":memory:", check_same_thread=False)
|
| 12 |
-
cur
|
| 13 |
cur.execute("""
|
| 14 |
CREATE TABLE Customers (
|
| 15 |
-
CustomerID
|
| 16 |
-
Name
|
| 17 |
-
Region
|
| 18 |
-
LastOrderDate
|
| 19 |
)
|
| 20 |
""")
|
| 21 |
cur.executemany(
|
| 22 |
-
"INSERT INTO Customers (Name, Region, LastOrderDate) VALUES (
|
| 23 |
[
|
| 24 |
-
("Acme Corp",
|
| 25 |
-
("Beta Inc",
|
| 26 |
-
("Gamma Co",
|
| 27 |
-
("Delta LLC",
|
| 28 |
-
("Epsilon Ltd","Northeast", "2025-07-10"),
|
| 29 |
],
|
| 30 |
)
|
| 31 |
conn.commit()
|
| 32 |
|
| 33 |
@mcp.tool()
|
| 34 |
def query_database(sql: str) -> str:
|
| 35 |
-
"""Run SQL
|
| 36 |
try:
|
| 37 |
cur.execute(sql)
|
| 38 |
cols = [d[0] for d in cur.description or []]
|
|
@@ -41,15 +42,17 @@ def query_database(sql: str) -> str:
|
|
| 41 |
except Exception as e:
|
| 42 |
return json.dumps({"error": str(e)})
|
| 43 |
|
| 44 |
-
# βββ 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
@mcp.tool()
|
| 46 |
-
def
|
| 47 |
-
"""
|
| 48 |
-
|
| 49 |
-
Example: object_type="contacts"
|
| 50 |
-
"""
|
| 51 |
-
return query_hubspot(object_type, limit)
|
| 52 |
|
| 53 |
-
# βββ 3
|
| 54 |
if __name__ == "__main__":
|
| 55 |
mcp.run(transport="stdio")
|
|
|
|
| 1 |
+
# mcp_server.py
|
| 2 |
+
|
| 3 |
import os
|
| 4 |
import json
|
| 5 |
import sqlite3
|
|
|
|
| 6 |
from mcp.server.fastmcp import FastMCP
|
| 7 |
+
from connectors import hubspot_connector
|
| 8 |
|
| 9 |
mcp = FastMCP("EnterpriseData")
|
| 10 |
|
| 11 |
+
# βββ 1. SQLite tool (in-memory) βββββββββββββ
|
| 12 |
conn = sqlite3.connect(":memory:", check_same_thread=False)
|
| 13 |
+
cur = conn.cursor()
|
| 14 |
cur.execute("""
|
| 15 |
CREATE TABLE Customers (
|
| 16 |
+
CustomerID INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 17 |
+
Name TEXT,
|
| 18 |
+
Region TEXT,
|
| 19 |
+
LastOrderDate TEXT
|
| 20 |
)
|
| 21 |
""")
|
| 22 |
cur.executemany(
|
| 23 |
+
"INSERT INTO Customers (Name, Region, LastOrderDate) VALUES (?, ?, ?)",
|
| 24 |
[
|
| 25 |
+
("Acme Corp", "Northeast", "2024-12-01"),
|
| 26 |
+
("Beta Inc", "West", "2025-06-01"),
|
| 27 |
+
("Gamma Co", "Northeast", "2023-09-15"),
|
| 28 |
+
("Delta LLC", "South", "2025-03-20"),
|
| 29 |
+
("Epsilon Ltd", "Northeast", "2025-07-10"),
|
| 30 |
],
|
| 31 |
)
|
| 32 |
conn.commit()
|
| 33 |
|
| 34 |
@mcp.tool()
|
| 35 |
def query_database(sql: str) -> str:
|
| 36 |
+
"""Run SQL and return JSON results."""
|
| 37 |
try:
|
| 38 |
cur.execute(sql)
|
| 39 |
cols = [d[0] for d in cur.description or []]
|
|
|
|
| 42 |
except Exception as e:
|
| 43 |
return json.dumps({"error": str(e)})
|
| 44 |
|
| 45 |
+
# βββ 2. HubSpot tool ββββββββββββββββ
|
| 46 |
+
@mcp.tool()
|
| 47 |
+
def query_hubspot_contacts(limit: int = 100) -> str:
|
| 48 |
+
"""List HubSpot contacts"""
|
| 49 |
+
return hubspot_connector.list_contacts(limit)
|
| 50 |
+
|
| 51 |
@mcp.tool()
|
| 52 |
+
def query_hubspot_companies(limit: int = 100) -> str:
|
| 53 |
+
"""List HubSpot companies"""
|
| 54 |
+
return hubspot_connector.list_companies(limit)
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
+
# βββ 3. Start MCP βββββββββββββββββββ
|
| 57 |
if __name__ == "__main__":
|
| 58 |
mcp.run(transport="stdio")
|