Skip to content

Commit 7da6182

Browse files
committed
GML-2042 MCP support multiple profiles
1 parent 23298c2 commit 7da6182

2 files changed

Lines changed: 52 additions & 8 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,16 @@ conn = TigerGraphConnection(
140140

141141
### Synchronous mode (`TigerGraphConnection`)
142142

143-
- Each thread gets its own `requests.Session` backed by a private connection pool. This eliminates the `_cookies_lock` contention that a shared session causes under concurrent load.
144-
- Install `pyTigerGraph[fast]` to activate the `orjson` backend and significantly reduce GIL contention between threads during JSON parsing.
143+
- Each thread gets its own dedicated HTTP session and connection pool, so concurrent threads never block each other.
144+
- Install `pyTigerGraph[fast]` to activate the `orjson` backend and reduce JSON parsing overhead under concurrent load.
145145
- Use `ThreadPoolExecutor` to run queries in parallel:
146146

147147
```python
148148
from concurrent.futures import ThreadPoolExecutor, as_completed
149149

150150
with TigerGraphConnection(...) as conn:
151151
with ThreadPoolExecutor(max_workers=16) as executor:
152-
futures = {executor.submit(conn.runInstalledQuery, "q", {"p": v}): v for v in values}
152+
futures = [executor.submit(conn.runInstalledQuery, "q", {"p": v}) for v in values]
153153
for f in as_completed(futures):
154154
print(f.result())
155155
```

pyTigerGraph/mcp/MCP_README.md

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pyTigerGraph now includes Model Context Protocol (MCP) support, allowing AI agen
88
- [Usage](#usage)
99
- [Running the MCP Server](#running-the-mcp-server)
1010
- [Configuration](#configuration)
11+
- [Multiple Connection Profiles](#multiple-connection-profiles)
1112
- [Using with Existing Connection](#using-with-existing-connection)
1213
- [Client Examples](#client-examples)
1314
- [Using MultiServerMCPClient](#using-multiserverMCPclient)
@@ -83,7 +84,6 @@ TG_USERNAME=tigergraph
8384
TG_PASSWORD=tigergraph
8485
TG_RESTPP_PORT=9000
8586
TG_GS_PORT=14240
86-
TG_CONN_LIMIT=10 # Optional - increase for parallel tool calls (e.g. 32)
8787
```
8888

8989
The server will automatically load the `.env` file if it exists. Environment variables take precedence over `.env` file values.
@@ -104,7 +104,52 @@ The following environment variables are supported:
104104
- `TG_SSL_PORT` - SSL port (default: 443)
105105
- `TG_TGCLOUD` - Whether using TigerGraph Cloud (default: False)
106106
- `TG_CERT_PATH` - Path to certificate (optional)
107-
- `TG_CONN_LIMIT` - Max keep-alive HTTP connections in the async client pool (default: 10). Should be ≥ the number of concurrent MCP tool calls you expect. Named profiles use `<PROFILE>_TG_CONN_LIMIT`.
107+
108+
### Multiple Connection Profiles
109+
110+
If you work with more than one TigerGraph environment — for example, development, staging, and production — you can define named profiles in your `.env` file and switch between them without changing any code.
111+
112+
#### Defining profiles
113+
114+
Each named profile uses a `<PROFILE>_` prefix on the standard `TG_*` variables. Only the variables that differ from the default need to be set.
115+
116+
```bash
117+
# .env
118+
119+
# Default profile (no prefix) — used when TG_PROFILE is not set
120+
TG_HOST=http://localhost
121+
TG_USERNAME=tigergraph
122+
TG_PASSWORD=tigergraph
123+
TG_GRAPHNAME=MyGraph
124+
125+
# Staging profile
126+
STAGING_TG_HOST=https://staging.example.com
127+
STAGING_TG_PASSWORD=staging_secret
128+
STAGING_TG_TGCLOUD=true
129+
130+
# Production profile
131+
PROD_TG_HOST=https://prod.example.com
132+
PROD_TG_USERNAME=admin
133+
PROD_TG_PASSWORD=prod_secret
134+
PROD_TG_GRAPHNAME=ProdGraph
135+
PROD_TG_TGCLOUD=true
136+
```
137+
138+
Profiles are discovered automatically at startup. Any variable matching `<PROFILE>_TG_HOST` registers a new profile. Values not set for a named profile fall back to the default profile's values.
139+
140+
#### Selecting the active profile
141+
142+
Pass `TG_PROFILE` as an environment variable or add it to your `.env`:
143+
144+
```bash
145+
# Switch to the staging profile for this run
146+
TG_PROFILE=staging tigergraph-mcp
147+
148+
# Or set it permanently in .env
149+
TG_PROFILE=prod
150+
```
151+
152+
If `TG_PROFILE` is not set, the default profile (unprefixed `TG_*` variables) is used.
108153

109154
### Using with Existing Connection
110155

@@ -136,7 +181,6 @@ async with AsyncTigerGraphConnection(
136181
graphname="MyGraph",
137182
username="tigergraph",
138183
password="tigergraph",
139-
connLimit=10, # set >= number of concurrent MCP tool calls (default: 10)
140184
) as conn:
141185
# Set as default for MCP tools
142186
ConnectionManager.set_default_connection(conn)
@@ -396,8 +440,8 @@ result = await session.call_tool(
396440

397441
- **Transport**: The MCP server uses stdio transport by default
398442
- **Error Detection**: GSQL operations include error detection for syntax and semantic errors (since `conn.gsql()` does not raise Python exceptions for GSQL failures)
399-
- **Connection Management**: Connections are pooled by profile — each profile's `AsyncTigerGraphConnection` holds a persistent HTTP connection pool (sized by `TG_CONN_LIMIT`, default 10). The pool is automatically released at server shutdown via `ConnectionManager.close_all()`. To adjust pool size per profile, set `<PROFILE>_TG_CONN_LIMIT`.
400-
- **Performance**: Persistent HTTP connection pool per profile (no TCP handshake per request); async non-blocking I/O; `v.outdegree()` for O(1) degree counting; batch operations for multiple vertices/edges
443+
- **Connection Management**: Connections are pooled by profile and reused across requests — no TCP handshake overhead per tool call. The pool is released automatically at server shutdown.
444+
- **Performance**: Persistent HTTP connection pool per profile; async non-blocking I/O; `v.outdegree()` for O(1) degree counting; batch operations for multiple vertices/edges
401445

402446
## Backward Compatibility
403447

0 commit comments

Comments
 (0)