Skip to main content

surjection_core/adapters/
claude_code.rs

1//! Claude Code (`claude-code`): SPEC 7.3 and 7.4.
2//!
3//! - User scope: `mcpServers` in `~/.claude.json`, or in
4//!   `$CLAUDE_CONFIG_DIR/.claude.json` when that is set (`[verify]`).
5//! - Project scope: `mcpServers` in `<P>/.mcp.json`.
6//! - Project-local scope: `projects["<P>"].mcpServers` in the user file. A
7//!   user server is hidden in a project by listing it in
8//!   `projects["<P>"].disabledMcpServers`.
9
10use crate::adapters::caps::{
11    Caps, CommandRef, EnvRefSyntax, FieldSet, ProjectDisable, ProjectSemantics, Source,
12    TransportSet, TrustGate,
13};
14use crate::adapters::detect::Probe;
15use crate::adapters::location::Location;
16use crate::adapters::mapper::{McpServersJson, dotted_word_name};
17use crate::adapters::spec::{AdapterSpec, ContainerPath, McpSpec, Tier, exact_names};
18use crate::env::Os;
19use crate::formats::Format;
20use crate::model::clients::passthrough_of;
21
22pub const ID: &str = "claude-code";
23
24/// `~/.claude.json`, or `$CLAUDE_CONFIG_DIR/.claude.json`.
25const USER_FILE: Location = Location::EnvDir {
26    var: "CLAUDE_CONFIG_DIR",
27    fallback: &Location::Home(""),
28    rel: ".claude.json",
29    tilde: false,
30};
31
32/// `~/.claude`, or `$CLAUDE_CONFIG_DIR`.
33const CONFIG_DIR: Location = Location::EnvDir {
34    var: "CLAUDE_CONFIG_DIR",
35    fallback: &Location::Home(".claude"),
36    rel: "",
37    tilde: false,
38};
39
40const CAPS: Caps = Caps {
41    // `ws` entries are read as unsupported: the store has no `ws` transport.
42    transports: TransportSet::ALL,
43    env_ref: Some(EnvRefSyntax::DollarBrace {
44        default: true,
45        bare: false,
46    }),
47    env_ref_fields: FieldSet::COMMAND
48        .union(FieldSet::ARGS)
49        .union(FieldSet::ENV)
50        .union(FieldSet::URL)
51        .union(FieldSet::HEADERS),
52    command_ref: Some(CommandRef::HeadersHelper),
53    native_disable: None,
54    project_disable: Some(ProjectDisable::ListMember(ContainerPath(&[
55        "projects",
56        ContainerPath::PROJECT_KEY,
57        "disabledMcpServers",
58    ]))),
59    project_semantics: ProjectSemantics::Replace,
60    precedence: &[Source::ProjectLocal, Source::Project, Source::User],
61    compat_reads: &[],
62    trust_gate: Some(TrustGate::ApprovalPrompt),
63    rewrites_file_at_runtime: true,
64    restart_required: false,
65    tool_filter: None,
66    windows_shell_shim: false,
67    timeouts: &[],
68    passthrough_allowlist: passthrough_of(ID),
69};
70
71/// Names are `[A-Za-z0-9_.-]+` (gate V1, CC-7; SPEC 5.1 had no `.`).
72static MAPPER: McpServersJson = McpServersJson {
73    caps: &CAPS,
74    type_field: true,
75    remote_type: true,
76    cwd: false,
77    http_aliases: &[],
78    url_implies_http: false,
79    valid_name: dotted_word_name,
80};
81
82pub static SPEC: AdapterSpec = AdapterSpec {
83    id: ID,
84    display_name: "Claude Code",
85    tier: Tier::A,
86    detect: &[
87        Probe::Path(USER_FILE),
88        Probe::Path(CONFIG_DIR),
89        Probe::Executable("claude"),
90    ],
91    mcp: Some(McpSpec {
92        oses: &[Os::Windows, Os::Linux, Os::MacOs],
93        read_only: false,
94        user: &[USER_FILE],
95        user_files: None,
96        user_mirrors: &[],
97        profiles: None,
98        project: &[Location::Project(".mcp.json")],
99        project_local: &[USER_FILE],
100        format: Format::Json,
101        skeleton: "",
102        container: ContainerPath(&["mcpServers"]),
103        project_local_container: ContainerPath(&[
104            "projects",
105            ContainerPath::PROJECT_KEY,
106            "mcpServers",
107        ]),
108        legacy_containers: &[],
109        same_name: exact_names,
110        replaced_by: &[],
111        mapper: &MAPPER,
112        caps: CAPS,
113    }),
114};