| 1 | import { |
| 2 | MCPServer, |
| 3 | mergeConfigYamlRequestOptions, |
| 4 | RequestOptions, |
| 5 | Rule, |
| 6 | } from "@continuedev/config-yaml"; |
| 7 | import { |
| 8 | InternalMcpOptions, |
| 9 | InternalSseMcpOptions, |
| 10 | InternalStdioMcpOptions, |
| 11 | InternalStreamableHttpMcpOptions, |
| 12 | RuleWithSource, |
| 13 | } from "../.."; |
| 14 | |
| 15 | export function convertYamlRuleToContinueRule(rule: Rule): RuleWithSource { |
| 16 | if (typeof rule === "string") { |
| 17 | return { |
| 18 | rule: rule, |
| 19 | source: "rules-block", |
| 20 | }; |
| 21 | } else { |
| 22 | return { |
| 23 | source: "rules-block", |
| 24 | rule: rule.rule, |
| 25 | globs: rule.globs, |
| 26 | name: rule.name, |
| 27 | description: rule.description, |
| 28 | ruleFile: rule.sourceFile, |
| 29 | alwaysApply: rule.alwaysApply, |
| 30 | invokable: rule.invokable ?? false, |
| 31 | }; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | export function convertYamlMcpConfigToInternalMcpOptions( |
| 36 | config: MCPServer, |
| 37 | globalRequestOptions?: RequestOptions, |
| 38 | ): InternalMcpOptions { |
| 39 | const { connectionTimeout, faviconUrl, name, sourceFile } = config; |
| 40 | const shared = { |
| 41 | id: name, |
| 42 | name, |
| 43 | faviconUrl: faviconUrl, |
| 44 | timeout: connectionTimeout, |
| 45 | sourceFile, |
| 46 | }; |
| 47 | // Stdio |
| 48 | if ("command" in config) { |
| 49 | const { args, command, cwd, env, type } = config; |
| 50 | const stdioOptions: InternalStdioMcpOptions = { |
| 51 | type, |
| 52 | command, |
| 53 | args, |
| 54 | cwd, |
| 55 | env, |
| 56 | ...shared, |
| 57 | }; |
| 58 | return stdioOptions; |
| 59 | } |
| 60 | // HTTP/SSE |
| 61 | const { type, url, requestOptions } = config; |
| 62 | const httpSseConfig: |
| 63 | | InternalStreamableHttpMcpOptions |
| 64 | | InternalSseMcpOptions = { |
| 65 | type, |
| 66 | url, |
| 67 | requestOptions: mergeConfigYamlRequestOptions( |
| 68 | requestOptions, |
| 69 | globalRequestOptions, |
| 70 | ), |
| 71 | ...shared, |
| 72 | }; |
| 73 | return httpSseConfig; |
| 74 | } |