feat: mcp json config types
This commit is contained in:
parent
e48921329e
commit
404f8d7981
6 changed files with 132 additions and 0 deletions
11
.continue/mcpServers/DeepWiki.json
Normal file
11
.continue/mcpServers/DeepWiki.json
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"type": [
|
||||
"hi",
|
||||
"hello",
|
||||
{
|
||||
"hi": "hello",
|
||||
"val2": "val3"
|
||||
}
|
||||
],
|
||||
"url": "https://mcp.deepwiki.com/mcp"
|
||||
}
|
||||
0
.continue/mcpServers/hello.yaml
Normal file
0
.continue/mcpServers/hello.yaml
Normal file
|
|
@ -68,6 +68,7 @@ async function loadRules(ide: IDE) {
|
|||
|
||||
return { rules, errors };
|
||||
}
|
||||
|
||||
export default async function doLoadConfig(options: {
|
||||
ide: IDE;
|
||||
controlPlaneClient: ControlPlaneClient;
|
||||
|
|
|
|||
83
core/context/mcp/json/loadJsonMcpConfigs.ts
Normal file
83
core/context/mcp/json/loadJsonMcpConfigs.ts
Normal file
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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";
|
||||
|
|
|
|||
36
packages/config-yaml/src/mcp/jsonTypes.ts
Normal file
36
packages/config-yaml/src/mcp/jsonTypes.ts
Normal file
|
|
@ -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<typeof httpOrSseMcpJsonSchema>;
|
||||
export type SseMcpJsonConfig = z.infer<typeof httpOrSseMcpJsonSchema>;
|
||||
|
||||
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<typeof stdioMcpJsonSchema>;
|
||||
|
||||
const mcpServersJsonSchema = z.union([
|
||||
httpOrSseMcpJsonSchema,
|
||||
stdioMcpJsonSchema,
|
||||
]);
|
||||
export type McpJsonConfig = z.infer<typeof stdioMcpJsonSchema>;
|
||||
|
||||
export const mcpServersRecordSchema = z.record(
|
||||
z.string(),
|
||||
mcpServersJsonSchema,
|
||||
);
|
||||
export type McpServersJsonConfigRecord = z.infer<typeof mcpServersRecordSchema>;
|
||||
|
||||
export const mcpServerConfigFileSchema = z.object({
|
||||
mcpServers: mcpServersRecordSchema,
|
||||
});
|
||||
export type McpServersJsonConfigFile = z.infer<typeof stdioMcpJsonSchema>;
|
||||
Loading…
Add table
Reference in a new issue