mgbam commited on
Commit
7bc9e4c
Β·
verified Β·
1 Parent(s): d8a673e

Update mcp_server.py

Browse files
Files changed (1) hide show
  1. mcp_server.py +31 -12
mcp_server.py CHANGED
@@ -1,17 +1,17 @@
1
  """
2
  mcp_server.py – MCP tool server exposing:
3
- β€’ query_database – SQLite sample
4
- β€’ query_salesforce – Salesforce via CData JDBC
5
- Add more connectors under connectors/ and register the same way.
6
  """
7
 
8
  from mcp.server.fastmcp import FastMCP
9
- import sqlite3, json
10
- from connectors.salesforce_connector import sf_query # ← new connector
11
 
 
12
  mcp = FastMCP("EnterpriseData")
13
 
14
- # ─── in-memory SQLite sample ─────────────────────────────────────────────
15
  conn = sqlite3.connect(":memory:", check_same_thread=False)
16
  cur = conn.cursor()
17
 
@@ -35,10 +35,10 @@ cur.executemany(
35
  )
36
  conn.commit()
37
 
38
- # ─── SQLite tool ─────────────────────────────────────────────────────────
39
  @mcp.tool()
40
  def query_database(sql: str) -> str:
41
- """Run arbitrary SQL against the Customers SQLite table."""
42
  try:
43
  cur.execute(sql)
44
  cols = [d[0] for d in cur.description or []]
@@ -47,11 +47,30 @@ def query_database(sql: str) -> str:
47
  except Exception as exc:
48
  return json.dumps({"error": str(exc)})
49
 
50
- # ─── Salesforce tool (premium) ───────────────────────────────────────────
 
 
 
 
 
51
  @mcp.tool()
52
- def query_salesforce(sql: str) -> str:
53
- """Run SOQL-as-SQL against Salesforce objects (requires Pro plan)."""
54
- return sf_query(sql)
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
 
56
  if __name__ == "__main__":
57
  mcp.run(transport="stdio")
 
1
  """
2
  mcp_server.py – MCP tool server exposing:
3
+ β€’ query_database – built-in SQLite demo
4
+ β€’ query_hubspot – HubSpot CRM via CData Python connector
 
5
  """
6
 
7
  from mcp.server.fastmcp import FastMCP
8
+ import sqlite3, json, os
9
+ from cdata.hubspot import connect # pip install cdata-hubspot
10
 
11
+ # ─── 1. FastMCP instance ────────────────────────────────────────────────
12
  mcp = FastMCP("EnterpriseData")
13
 
14
+ # ─── 2. In-memory SQLite sample ─────────────────────────────────────────
15
  conn = sqlite3.connect(":memory:", check_same_thread=False)
16
  cur = conn.cursor()
17
 
 
35
  )
36
  conn.commit()
37
 
38
+ # ─── 3. SQLite tool ─────────────────────────────────────────────────────
39
  @mcp.tool()
40
  def query_database(sql: str) -> str:
41
+ """Run SQL against the in-memory Customers table and return JSON rows."""
42
  try:
43
  cur.execute(sql)
44
  cols = [d[0] for d in cur.description or []]
 
47
  except Exception as exc:
48
  return json.dumps({"error": str(exc)})
49
 
50
+ # ─── 4. HubSpot connector setup ─────────────────────────────────────────
51
+ # Uses CData’s HubSpot Python connector :contentReference[oaicite:4]{index=4}
52
+ HUBSPOT_TOKEN = os.getenv("HUBSPOT_TOKEN")
53
+ hs_conn = connect(PrivateAppToken=HUBSPOT_TOKEN)
54
+
55
+ # ─── 5. HubSpot tool ────────────────────────────────────────────────────
56
  @mcp.tool()
57
+ def query_hubspot(sql: str) -> str:
58
+ """
59
+ Execute SQL/ODBC-style queries on HubSpot objects (Contacts, Deals, etc.).
60
+ Example:
61
+ SELECT firstname, lastname, email
62
+ FROM contacts
63
+ WHERE lifecyclestage = 'lead';
64
+ """
65
+ try:
66
+ cur_hs = hs_conn.cursor()
67
+ cur_hs.execute(sql)
68
+ cols = [d[0] for d in cur_hs.description or []]
69
+ rows = [dict(zip(cols, r)) for r in cur_hs.fetchall()]
70
+ return json.dumps(rows)
71
+ except Exception as exc:
72
+ return json.dumps({"error": str(exc)})
73
 
74
+ # ─── 6. Run the server ───────────────────────────────────────────────────
75
  if __name__ == "__main__":
76
  mcp.run(transport="stdio")