You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browse filesBrowse the repository at this point in the historyBrowse files
Akangsha Goel
committed
refactor(sources): reach connection handles through ConnectOnce
Every source builds its handle through sources.ConnectOnce and reaches it
through an accessor, instead of connecting inline in Initialize and
storing the result on an exported field.
Initialize takes a deferConnect parameter, but the only caller passes
false, so each source still connects during startup and still reports a
connect failure there. The flag that sets it lands separately.
Config that needs no network is resolved in newSource, which runs whether
or not the connect is deferred: a malformed queryTimeout, baseUrl or
writeMode is a configuration error and must fail at startup rather than on
the first tool call.
Sources keep their context-free accessors, which report the handle only
once connected. They exist so tools can express a capability as an
interface and type-assert on it; none of them is invoked. The exception is
Looker, where LookerApiSettings is read after GetLookerSDK has connected.
ConnectOnce bounds the attempt at ConnectTimeout, which the startup
connect did not have before. Sources whose own config permits a longer
connect raise the ceiling to match, as postgres and looker already did:
mysql, oceanbase, singlestore and mindsdb through the driver read timeout
the ping honours, trino through the timeout it sends with that query, and
cockroachdb through the backoff its retry loop sleeps.
The branch was cut before #3902, #3905 and #3921 landed, so it also
restores alloydbpg's pre-PG17 read-only diagnostic and three test files it
would otherwise have reverted, detaches the bigquery client creator from
the connect's context, and stops InitConnectionSpan panicking on the nil
tracer that some source tests still pass.
returnnil, fmt.Errorf("failed to initialize AlloyDB source in read-only mode: 'alloydb_session_read_only' is not supported on this instance version. See documentation for details: https://mcp-toolbox.dev/integrations/alloydb/source/#reference: %w", err)
84
-
}
85
-
returnnil, fmt.Errorf("unable to connect successfully: %w", err)
returnnil, fmt.Errorf("failed to initialize AlloyDB source in read-only mode: 'alloydb_session_read_only' is not supported on this instance version. See documentation for details: https://mcp-toolbox.dev/integrations/alloydb/source/#reference: %w", err)
110
+
}
111
+
returnnil, fmt.Errorf("unable to connect successfully: %w", err)
112
+
}
113
+
returnpool, nil
114
+
})
100
115
}
101
116
102
117
func (s*Source) IsReadOnly() bool {
@@ -111,13 +126,24 @@ func (s *Source) ToConfig() sources.SourceConfig {
111
126
returns.Config
112
127
}
113
128
129
+
// PostgresPool reports the pool once connected; use PostgresPoolContext to guarantee one.
114
130
func (s*Source) PostgresPool() *pgxpool.Pool {
115
-
returns.Pool
131
+
pool, _:=s.conn.Get()
132
+
returnpool
133
+
}
134
+
135
+
// PostgresPoolContext returns the pool, connecting on first use.
0 commit comments