continue-custom/core/config/yaml/yamlToContinueConfig.ts
continue[bot] 9164448c73
Add apiKey field to mcpServers block schema for Bearer token auth (#8120)
Add apiKey field to mcpServers schema and implement Bearer token auth

- Add apiKey field to sseOrHttpMcpServerSchema in packages/config-yaml
- Update MCPConnection.ts to merge apiKey as Bearer token in Authorization header
- Update CLI MCPService to merge apiKey as Bearer token in Authorization header
- Add apiKey to InternalSseMcpOptions and InternalStreamableHttpMcpOptions types
- Update yamlToContinueConfig converter to pass through apiKey field

Fixes CON-4281

Generated with [Continue](https://continue.dev)

Co-authored-by: Continue Agent <agent@continue.dev>
Co-authored-by: Continue <noreply@continue.dev>
Co-authored-by: nate <nate@continue.dev>
2025-10-08 08:33:30 -07:00

75 lines
1.6 KiB
TypeScript

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") {
return {
rule: rule,
source: "rules-block",
};
} else {
return {
source: "rules-block",
rule: rule.rule,
globs: rule.globs,
name: rule.name,
description: rule.description,
sourceFile: rule.sourceFile,
alwaysApply: rule.alwaysApply,
invokable: rule.invokable ?? false,
};
}
}
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 = {
...shared,
type,
command,
args,
cwd,
env,
};
return stdioOptions;
}
// HTTP/SSE
const { type, url, apiKey, requestOptions } = config;
const httpSseConfig:
| InternalStreamableHttpMcpOptions
| InternalSseMcpOptions = {
...shared,
type,
url,
apiKey,
requestOptions: mergeConfigYamlRequestOptions(
requestOptions,
globalRequestOptions,
),
};
return httpSseConfig;
}