diff --git a/.continue/mcpServers/DeepWiki.json b/.continue/mcpServers/DeepWiki.json new file mode 100644 index 000000000..842e5211b --- /dev/null +++ b/.continue/mcpServers/DeepWiki.json @@ -0,0 +1,11 @@ +{ + "type": [ + "hi", + "hello", + { + "hi": "hello", + "val2": "val3" + } + ], + "url": "https://mcp.deepwiki.com/mcp" +} diff --git a/.continue/mcpServers/hello.yaml b/.continue/mcpServers/hello.yaml new file mode 100644 index 000000000..e69de29bb diff --git a/core/config/profile/doLoadConfig.ts b/core/config/profile/doLoadConfig.ts index c213bcb66..61f01279d 100644 --- a/core/config/profile/doLoadConfig.ts +++ b/core/config/profile/doLoadConfig.ts @@ -68,6 +68,7 @@ async function loadRules(ide: IDE) { return { rules, errors }; } + export default async function doLoadConfig(options: { ide: IDE; controlPlaneClient: ControlPlaneClient; diff --git a/core/context/mcp/json/loadJsonMcpConfigs.ts b/core/context/mcp/json/loadJsonMcpConfigs.ts new file mode 100644 index 000000000..4e90396d3 --- /dev/null +++ b/core/context/mcp/json/loadJsonMcpConfigs.ts @@ -0,0 +1,83 @@ +import ignore from "ignore"; +import { IDE } from "../../.."; +import { + DEFAULT_IGNORE_DIRS, + DEFAULT_IGNORE_FILETYPES, +} from "../../../indexing/ignore"; +import { walkDir } from "../../../indexing/walkDir"; +import { getGlobalFolderWithName } from "../../../util/paths"; +import { localPathToUri } from "../../../util/pathToUri"; +import { joinPathsToUri } from "../../../util/uri"; + +async function getDefinitionFilesInDir( + ide: IDE, + dir: string, +): Promise<{ path: string; content: string }[]> { + try { + let assistantFilePaths: string[]; + if (fileExtType === "yaml") { + assistantFilePaths = uris.filter( + (p) => p.endsWith(".yaml") || p.endsWith(".yml"), + ); + } else if (fileExtType === "markdown") { + assistantFilePaths = uris.filter((p) => p.endsWith(".md")); + } else { + assistantFilePaths = uris.filter( + (p) => p.endsWith(".yaml") || p.endsWith(".yml") || p.endsWith(".md"), + ); + } + + const results = assistantFilePaths.map(async (uri) => { + const content = await ide.readFile(uri); // make a try catch + return { path: uri, content }; + }); + return Promise.all(results); + } catch (e) { + console.error(e); + return []; + } +} + +/** + * This method searches in both ~/.continue and workspace .continue + * for all YAML/Markdown files in the specified subdirectory, for example .continue/assistants or .continue/prompts + */ +export async function getJsonConfigs( + ide: IDE, + includeGlobal: boolean, +): Promise<{ path: string; content: string }[]> { + const dirsToCheck = await ide.getWorkspaceDirs(); + if (includeGlobal) { + dirsToCheck.push(localPathToUri(getGlobalFolderWithName("mcpServers"))); + } + + const fullDirs = dirsToCheck.map((dir) => + joinPathsToUri(dir, ".continue", "mcpServers"), + ); + + const exists = await ide.fileExists(dir); + + const overrideDefaultIgnores = ignore() + .add( + DEFAULT_IGNORE_FILETYPES.filter( + (val) => !["config.json", "settings.json"].includes(val), + ), + ) + .add(DEFAULT_IGNORE_DIRS); + + const uris = await walkDir(dir, ide, { + overrideDefaultIgnores, + source: "get mcp json files", + }); + + // Get all definition files from the directories + const definitionFiles = ( + await Promise.all( + fullDirs.map((dir) => + getDefinitionFilesInDir(ide, dir, options.fileExtType), + ), + ) + ).flat(); + + return definitionFiles; +} diff --git a/packages/config-yaml/src/browser.ts b/packages/config-yaml/src/browser.ts index 9edef65aa..5a27278fb 100644 --- a/packages/config-yaml/src/browser.ts +++ b/packages/config-yaml/src/browser.ts @@ -12,6 +12,7 @@ export * from "./load/unroll.js"; export * from "./markdown/index.js"; export * from "./modelName.js"; // Note: registryClient.js is excluded because it uses Node.js fs/path APIs +export * from "./mcp/jsonTypes.js"; export * from "./schemas/data/index.js"; export * from "./schemas/index.js"; export * from "./schemas/models.js"; diff --git a/packages/config-yaml/src/mcp/jsonTypes.ts b/packages/config-yaml/src/mcp/jsonTypes.ts new file mode 100644 index 000000000..a2e32fd40 --- /dev/null +++ b/packages/config-yaml/src/mcp/jsonTypes.ts @@ -0,0 +1,36 @@ +import z from "zod"; + +// This is the schema for an entry in e.g. Claude Desktop, Claude code mcp config +const httpOrSseMcpJsonSchema = z.object({ + type: z.union([z.literal("sse"), z.literal("http")]).optional(), + url: z.string().url(), + headers: z.record(z.string(), z.string()).optional(), +}); +export type HttpMcpJsonConfig = z.infer; +export type SseMcpJsonConfig = z.infer; + +const stdioMcpJsonSchema = z.object({ + type: z.literal("stdio").optional(), + command: z.string(), + args: z.array(z.string()).optional(), + env: z.record(z.string(), z.string()).optional(), + envFile: z.string().optional(), +}); +export type StdioMcpJsonConfig = z.infer; + +const mcpServersJsonSchema = z.union([ + httpOrSseMcpJsonSchema, + stdioMcpJsonSchema, +]); +export type McpJsonConfig = z.infer; + +export const mcpServersRecordSchema = z.record( + z.string(), + mcpServersJsonSchema, +); +export type McpServersJsonConfigRecord = z.infer; + +export const mcpServerConfigFileSchema = z.object({ + mcpServers: mcpServersRecordSchema, +}); +export type McpServersJsonConfigFile = z.infer;