Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions core/config/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import {
ConfigResult,
ConfigValidationError,
mergeConfigYamlRequestOptions,
ModelRole,
} from "@continuedev/config-yaml";
import * as JSONC from "comment-json";
Expand All @@ -25,6 +26,7 @@
IdeType,
ILLM,
ILLMLogger,
InternalMcpOptions,
LLMOptions,
ModelDescription,
RerankerDescription,
Expand Down Expand Up @@ -57,8 +59,9 @@
} from "../util/paths";
import { localPathToUri } from "../util/pathToUri";

import { PolicySingleton } from "../control-plane/PolicySingleton";
import { loadJsonMcpConfigs } from "../context/mcp/json/loadJsonMcpConfigs";
import CustomContextProviderClass from "../context/providers/CustomContextProvider";
import { PolicySingleton } from "../control-plane/PolicySingleton";
import { getBaseToolDefinitions } from "../tools";
import { resolveRelativePathInDir } from "../util/ideUtils";
import { getWorkspaceRcConfigs } from "./json/loadRcConfigs";
Expand Down Expand Up @@ -462,7 +465,7 @@
}
if (name === "llm") {
const llm = models.find((model) => model.title === params?.modelTitle);
if (!llm) {

Check warning on line 468 in core/config/load.ts

View workflow job for this annotation

GitHub Actions / core-checks

Unexpected negated condition
errors.push({
fatal: false,
message: `Unknown reranking model ${params?.modelTitle}`,
Expand Down Expand Up @@ -550,17 +553,27 @@
if (orgPolicy?.policy?.allowMcpServers === false) {
await mcpManager.shutdown();
} else {
mcpManager.setConnections(
(config.experimental?.modelContextProtocolServers ?? []).map(
(server, index) => ({
id: `continue-mcp-server-${index + 1}`,
name: `MCP Server`,
...server,
requestOptions: config.requestOptions,
}),
const mcpOptions: InternalMcpOptions[] = (
config.experimental?.modelContextProtocolServers ?? []
).map((server, index) => ({
id: `continue-mcp-server-${index + 1}`,
name: `MCP Server`,
requestOptions: mergeConfigYamlRequestOptions(
server.transport.type !== "stdio"

Check warning on line 562 in core/config/load.ts

View workflow job for this annotation

GitHub Actions / core-checks

Unexpected negated condition
? server.transport.requestOptions
: undefined,
config.requestOptions,
),
false,
...server.transport,
}));
const { errors: jsonMcpErrors, mcpServers } = await loadJsonMcpConfigs(
ide,
true,
config.requestOptions,
);
errors.push(...jsonMcpErrors);
mcpOptions.push(...mcpServers);
mcpManager.setConnections(mcpOptions, false);
}

// Handle experimental modelRole config values for apply and edit
Expand Down
31 changes: 28 additions & 3 deletions core/config/loadLocalAssistants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BLOCK_TYPES } from "@continuedev/config-yaml";
import ignore from "ignore";
import * as URI from "uri-js";
import { IDE } from "..";
Expand All @@ -6,12 +7,32 @@ import {
DEFAULT_IGNORE_FILETYPES,
} from "../indexing/ignore";
import { walkDir } from "../indexing/walkDir";
import { RULES_MARKDOWN_FILENAME } from "../llm/rules/constants";
import { getGlobalFolderWithName } from "../util/paths";
import { localPathToUri } from "../util/pathToUri";
import { joinPathsToUri } from "../util/uri";
import { getUriPathBasename, joinPathsToUri } from "../util/uri";
import { SYSTEM_PROMPT_DOT_FILE } from "./getWorkspaceContinueRuleDotFiles";
export function isContinueConfigRelatedUri(uri: string): boolean {
return (
uri.endsWith(".continuerc.json") ||
uri.endsWith(".prompt") ||
uri.endsWith("AGENTS.md") ||
uri.endsWith("AGENT.md") ||
uri.endsWith("CLAUDE.md") ||
uri.endsWith(SYSTEM_PROMPT_DOT_FILE) ||
(uri.includes(".continue") &&
(uri.endsWith(".yaml") ||
uri.endsWith(".yml") ||
uri.endsWith(".json"))) ||
[...BLOCK_TYPES, "agents", "assistants"].some((blockType) =>
uri.includes(`.continue/${blockType}`),
)
);
}

export function isLocalDefinitionFile(uri: string): boolean {
if (!uri.endsWith(".yaml") && !uri.endsWith(".yml") && !uri.endsWith(".md")) {
export function isContinueAgentConfigFile(uri: string): boolean {
const isYaml = uri.endsWith(".yaml") || uri.endsWith(".yml");
if (!isYaml) {
return false;
}

Expand All @@ -22,6 +43,10 @@ export function isLocalDefinitionFile(uri: string): boolean {
);
}

export function isColocatedRulesFile(uri: string): boolean {
return getUriPathBasename(uri) === RULES_MARKDOWN_FILENAME;
}

async function getDefinitionFilesInDir(
ide: IDE,
dir: string,
Expand Down
64 changes: 35 additions & 29 deletions core/config/yaml/loadYaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ import {
} from "@continuedev/config-yaml";
import { dirname } from "node:path";

import { ContinueConfig, IDE, IdeInfo, IdeSettings, ILLMLogger } from "../..";
import {
ContinueConfig,
IDE,
IdeInfo,
IdeSettings,
ILLMLogger,
InternalMcpOptions,
} from "../..";
import { MCPManagerSingleton } from "../../context/mcp/MCPManagerSingleton";
import { ControlPlaneClient } from "../../control-plane/client";
import TransformersJsEmbeddingsProvider from "../../llm/llms/TransformersJsEmbeddingsProvider";
Expand All @@ -25,6 +32,7 @@ import { modifyAnyConfigWithSharedConfig } from "../sharedConfig";

import { convertPromptBlockToSlashCommand } from "../../commands/slash/promptBlockSlashCommand";
import { slashCommandFromPromptFile } from "../../commands/slash/promptFileSlashCommand";
import { loadJsonMcpConfigs } from "../../context/mcp/json/loadJsonMcpConfigs";
import { getControlPlaneEnvSync } from "../../control-plane/env";
import { PolicySingleton } from "../../control-plane/PolicySingleton";
import { getBaseToolDefinitions } from "../../tools";
Expand All @@ -34,7 +42,10 @@ import { getAllDotContinueDefinitionFiles } from "../loadLocalAssistants";
import { unrollLocalYamlBlocks } from "./loadLocalYamlBlocks";
import { LocalPlatformClient } from "./LocalPlatformClient";
import { llmsFromModelConfig } from "./models";
import { convertYamlRuleToContinueRule } from "./yamlToContinueConfig";
import {
convertYamlMcpConfigToInternalMcpOptions,
convertYamlRuleToContinueRule,
} from "./yamlToContinueConfig";

async function loadConfigYaml(options: {
overrideConfigYaml: AssistantUnrolled | undefined;
Expand Down Expand Up @@ -227,17 +238,19 @@ export async function configYamlToContinueConfig(options: {
}));

config.mcpServers?.forEach((mcpServer) => {
const mcpArgVariables =
mcpServer.args?.filter((arg) => TEMPLATE_VAR_REGEX.test(arg)) ?? [];
if ("args" in mcpServer) {
const mcpArgVariables =
mcpServer.args?.filter((arg) => TEMPLATE_VAR_REGEX.test(arg)) ?? [];

if (mcpArgVariables.length === 0) {
return;
}
if (mcpArgVariables.length === 0) {
return;
}

localErrors.push({
fatal: false,
message: `MCP server "${mcpServer.name}" has unsubstituted variables in args: ${mcpArgVariables.join(", ")}. Please refer to https://docs.continue.dev/hub/secrets/secret-types for managing hub secrets.`,
});
localErrors.push({
fatal: false,
message: `MCP server "${mcpServer.name}" has unsubstituted variables in args: ${mcpArgVariables.join(", ")}. Please refer to https://docs.continue.dev/hub/secrets/secret-types for managing hub secrets.`,
});
}
});

// Prompt files -
Expand Down Expand Up @@ -381,25 +394,18 @@ export async function configYamlToContinueConfig(options: {
if (orgPolicy?.policy?.allowMcpServers === false) {
await mcpManager.shutdown();
} else {
mcpManager.setConnections(
(config.mcpServers ?? []).map((server) => ({
id: server.name,
name: server.name,
sourceFile: server.sourceFile,
transport: {
type: "stdio",
args: [],
requestOptions: mergeConfigYamlRequestOptions(
server.requestOptions,
config.requestOptions,
),
...(server as any), // TODO: fix the types on mcpServers in config-yaml
},
timeout: server.connectionTimeout,
})),
false,
{ ide },
const mcpOptions: InternalMcpOptions[] = (config.mcpServers ?? []).map(
(server) =>
convertYamlMcpConfigToInternalMcpOptions(server, config.requestOptions),
);
const { errors: jsonMcpErrors, mcpServers } = await loadJsonMcpConfigs(
ide,
true,
config.requestOptions,
);
localErrors.push(...jsonMcpErrors);
mcpOptions.push(...mcpServers);
mcpManager.setConnections(mcpOptions, false, { ide });
}

return { config: continueConfig, errors: localErrors };
Expand Down
65 changes: 51 additions & 14 deletions core/config/yaml/yamlToContinueConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { MCPServer, Rule } from "@continuedev/config-yaml";
import { ExperimentalMCPOptions, RuleWithSource } from "../..";
import {
MCPServer,
mergeConfigYamlRequestOptions,
RequestOptions,
Rule,
} from "@continuedev/config-yaml";
import {
InternalMcpOptions,
InternalSseMcpOptions,
InternalStdioMcpOptions,
InternalStreamableHttpMcpOptions,
RuleWithSource,
} from "../..";

export function convertYamlRuleToContinueRule(rule: Rule): RuleWithSource {
if (typeof rule === "string") {
Expand All @@ -21,17 +32,43 @@ export function convertYamlRuleToContinueRule(rule: Rule): RuleWithSource {
}
}

export function convertYamlMcpToContinueMcp(
server: MCPServer,
): ExperimentalMCPOptions {
return {
transport: {
type: "stdio",
command: server.command,
args: server.args ?? [],
env: server.env,
cwd: server.cwd,
} as any, // TODO: Fix the mcpServers types in config-yaml (discriminated union)
timeout: server.connectionTimeout,
export function convertYamlMcpConfigToInternalMcpOptions(
config: MCPServer,
globalRequestOptions?: RequestOptions,
): InternalMcpOptions {
const { connectionTimeout, faviconUrl, name, sourceFile } = config;
const shared = {
id: name,
name,
faviconUrl: faviconUrl,
timeout: connectionTimeout,
sourceFile,
};
// Stdio
if ("command" in config) {
const { args, command, cwd, env, type } = config;
const stdioOptions: InternalStdioMcpOptions = {
type,
command,
args,
cwd,
env,
...shared,
};
return stdioOptions;
}
// HTTP/SSE
const { type, url, requestOptions } = config;
const httpSseConfig:
| InternalStreamableHttpMcpOptions
| InternalSseMcpOptions = {
type,
url,
requestOptions: mergeConfigYamlRequestOptions(
requestOptions,
globalRequestOptions,
),
...shared,
};
return httpSseConfig;
}
Loading
Loading