Skip to content

Commit d808841

Browse files
authored
feat: add dynamic connection management to multiserver.Manager (#54)
* feat: add dynamic connection management to multiserver.Manager Add AddConnection and RemoveConnection methods to support runtime addition and removal of Trino clients from downstream projects. Also add RLock to read-path methods for thread safety with mutations. * refactor: remove deprecation support and fix lint issues Remove Deprecation struct, IncludeDeprecated filter, formatDeprecation, mapDeprecation, matchesDeprecation, and all related tests/docs. The project is too new for deprecation machinery. Also fix pre-existing lint issues: gosec G706 in server.go (nolint for operator-controlled env var), staticcheck QF1012 in schema.go (fmt.Fprintf instead of WriteString+Sprintf), and update multi-server docs with dynamic connection management API. * ci: bump golangci-lint to v2.11.4 for Go 1.25 support
1 parent df72b79 commit d808841

24 files changed

Lines changed: 312 additions & 249 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Run golangci-lint
2828
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
2929
with:
30-
version: v2.1.6
30+
version: v2.11.4
3131
args: --timeout=5m
3232

3333
test:

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ mcp-trino is part of a broader suite of open-source MCP servers designed to work
3030

3131
**Semantic Context**
3232
- Surface business descriptions, ownership, and data quality from metadata catalogs
33-
- Mark sensitive columns and deprecation warnings for AI assistants
33+
- Mark sensitive columns for AI assistants
3434
- Connect to DataHub, static files, or build custom metadata providers
3535

3636
**Multi-Cluster Connectivity**
@@ -204,7 +204,6 @@ mcp-trino's semantic layer integrates with metadata catalogs to surface this con
204204
| **Glossary Terms** | Links to formal business definitions |
205205
| **Data Quality** | Freshness scores and quality metrics |
206206
| **Sensitivity** | PII and sensitive data markers at column level |
207-
| **Deprecation** | Warnings with replacement guidance |
208207
| **Lineage** | Upstream and downstream data dependencies |
209208

210209
### Providers

docs/library/extensibility.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ When configured, `trino_describe_table` enriches output with:
402402
- Ownership information
403403
- Tags and domain classifications
404404
- Sensitivity markers (PII, sensitive data)
405-
- Deprecation warnings
406405

407406
See the [Semantic Layer documentation](../semantic/index.md) for provider setup, caching, and building custom providers.
408407

docs/library/quickstart.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -275,22 +275,31 @@ func main() {
275275
Connect to multiple Trino clusters:
276276

277277
```go
278-
// Create connection manager
279-
manager := tools.NewManager()
278+
import "github.com/txn2/mcp-trino/pkg/multiserver"
280279

281-
// Add connections
282-
prodClient, _ := client.New(client.Config{Host: "prod.trino.example.com", ...})
283-
stagingClient, _ := client.New(client.Config{Host: "staging.trino.example.com", ...})
284-
285-
manager.Add("production", prodClient)
286-
manager.Add("staging", stagingClient)
287-
manager.SetDefault("production")
280+
// Create manager from environment (TRINO_* + TRINO_ADDITIONAL_SERVERS)
281+
mgr, _ := multiserver.NewManagerFromEnv()
288282

289283
// Create toolkit with manager
290-
toolkit := tools.NewToolkitWithManager(manager, tools.DefaultConfig())
284+
toolkit := tools.NewToolkitWithManager(mgr, tools.DefaultConfig())
285+
```
286+
287+
### Dynamic Connections
288+
289+
Add and remove connections at runtime:
290+
291+
```go
292+
// Add a connection dynamically
293+
mgr.AddConnection("analytics", multiserver.ConnectionConfig{
294+
Host: "analytics.trino.example.com",
295+
Catalog: "iceberg",
296+
})
297+
298+
// Remove a connection (closes any cached client)
299+
mgr.RemoveConnection("analytics")
291300
```
292301

293-
Users can now specify which connection to use:
302+
Users can specify which connection to use:
294303

295304
```json
296305
{"tool": "trino_query", "arguments": {"sql": "SELECT * FROM users", "connection": "staging"}}

docs/semantic/custom.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,6 @@ overrides := semantic.ProviderFunc{
203203
return &semantic.TableContext{
204204
Identifier: t,
205205
Description: "OVERRIDE: Use v2_customers instead",
206-
Deprecation: &semantic.Deprecation{
207-
Deprecated: true,
208-
ReplacedBy: "v2_customers",
209-
},
210206
}, nil
211207
}
212208
return nil, nil // Fall through to next provider

docs/semantic/datahub.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ The provider retrieves the following metadata from DataHub:
6666
| Tags | Global tags with descriptions |
6767
| Glossary Terms | Glossary term associations |
6868
| Domain | Domain assignment |
69-
| Deprecation | Deprecation aspect |
7069

7170
### Column-Level
7271

docs/semantic/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ and their subscription status.
3939
| **Glossary Terms** | Links to formal business term definitions |
4040
| **Data Quality** | Freshness scores and quality metrics |
4141
| **Sensitivity** | PII and sensitive data markers at column level |
42-
| **Deprecation** | Warnings with replacement guidance |
4342
| **Lineage** | Upstream and downstream data dependencies |
4443

4544
## Providers

docs/semantic/static.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,6 @@ tables:
6161
glossary_terms:
6262
- urn:glossary:subscription-tier
6363

64-
- catalog: analytics
65-
schema: public
66-
table: orders_legacy
67-
description: Legacy orders table
68-
deprecated: true
69-
deprecation_note: Migrated to iceberg.sales.orders
70-
replaced_by: iceberg.sales.orders
71-
7264
glossary:
7365
- urn: urn:glossary:customer
7466
name: Customer
@@ -120,9 +112,6 @@ glossary:
120112
| `tags` | array | List of tags |
121113
| `domain` | object | Domain assignment |
122114
| `glossary_terms` | array | URNs of associated terms |
123-
| `deprecated` | boolean | Deprecation flag |
124-
| `deprecation_note` | string | Deprecation explanation |
125-
| `replaced_by` | string | Replacement table identifier |
126115
| `columns` | object | Column metadata (keyed by name) |
127116
| `custom_properties` | object | Additional key-value metadata |
128117

docs/server/multi-server.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,31 @@ export TRINO_ADDITIONAL_SERVERS='{
8181
}'
8282
```
8383

84+
## Dynamic Connections (Library Use)
85+
86+
When using mcp-trino as a library, connections can be added and removed at runtime via the `multiserver.Manager`:
87+
88+
```go
89+
import "github.com/txn2/mcp-trino/pkg/multiserver"
90+
91+
mgr, _ := multiserver.NewManagerFromEnv()
92+
toolkit := tools.NewToolkitWithManager(mgr, tools.DefaultConfig())
93+
94+
// Add a connection at runtime
95+
mgr.AddConnection("analytics", multiserver.ConnectionConfig{
96+
Host: "analytics.trino.example.com",
97+
Catalog: "iceberg",
98+
})
99+
100+
// Remove a connection (closes any cached client)
101+
mgr.RemoveConnection("analytics")
102+
```
103+
104+
- `AddConnection` replaces an existing connection if one with the same name exists
105+
- Cached clients are automatically closed and recreated on next access
106+
- The primary/default connection cannot be added or removed via these methods
107+
- All operations are thread-safe
108+
84109
## Usage
85110

86111
### Connection Parameter

docs/server/tools.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ When a [semantic provider](../semantic/index.md) is configured, this tool enrich
153153
- **Ownership**: Data stewards and technical owners
154154
- **Tags & Domain**: Classification labels and business domain
155155
- **Sensitivity**: Columns marked as containing PII or sensitive data
156-
- **Deprecation**: Warnings if the table is deprecated
157156

158157
### Parameters
159158

0 commit comments

Comments
 (0)