MCPcopy
hub / github.com/continuedev/continue / connectServer

Method connectServer

extensions/cli/src/services/MCPService.ts:239–341  ·  view source on GitHub ↗
(serverConfig: MCPServerConfig)

Source from the content-addressed store, hash-verified

237 }
238
239 private async connectServer(serverConfig: MCPServerConfig) {
240 const connection: ServerConnection = {
241 config: serverConfig,
242 client: null,
243 prompts: [],
244 tools: [],
245 status: "connecting",
246 warnings: [],
247 };
248 const serverName = serverConfig.name;
249 this.connections.set(serverName, connection);
250 this.updateState();
251
252 const vars = getTemplateVariables(JSON.stringify(serverConfig));
253 const secretVars = vars.filter((v) => v.startsWith("secrets."));
254 const unrendered = secretVars.map((v) => {
255 return decodeFQSN(v.replace("secrets.", "")).secretName;
256 });
257
258 try {
259 if (unrendered.length > 0) {
260 const message = `${serverConfig.name} MCP Server has unresolved secrets: ${unrendered.join(", ")}
261For personal use you can set the secret in the hub at https://continue.dev/settings/secrets or pass it to the CLI environment.
262Org-level secrets can only be used for MCP by Background Agents (https://docs.continue.dev/hub/agents/overview) when \"Include in Env\" is enabled for the secret.`;
263 if (this.isHeadless) {
264 throw new Error(message);
265 } else {
266 connection.warnings.push(message);
267 }
268 }
269
270 const client = await this.getConnectedClient(serverConfig, connection);
271
272 connection.client = client;
273 connection.status = "connected";
274 this.updateState();
275
276 const capabilities = client.getServerCapabilities();
277
278 if (capabilities?.prompts) {
279 try {
280 connection.prompts = await this.withTokenRefresh(
281 serverName,
282 async () => {
283 const conn = this.connections.get(serverName);
284 if (!conn?.client) {
285 throw new Error(`Client for ${serverName} not available`);
286 }
287 return (await conn.client.listPrompts()).prompts;
288 },
289 );
290 } catch (error) {
291 const errorMessage = getErrorString(error);
292 connection.warnings.push(`Failed to load prompts: ${errorMessage}`);
293 logger.warn("Failed to load MCP prompts", {
294 name: serverName,
295 error: errorMessage,
296 });

Callers 2

doInitializeMethod · 0.95
restartServerMethod · 0.95

Calls 12

updateStateMethod · 0.95
getConnectedClientMethod · 0.95
withTokenRefreshMethod · 0.95
getTemplateVariablesFunction · 0.90
decodeFQSNFunction · 0.90
getErrorStringFunction · 0.85
warnMethod · 0.80
errorMethod · 0.80
setMethod · 0.65
pushMethod · 0.65
getMethod · 0.65
replaceMethod · 0.45

Tested by

no test coverage detected