claude

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package claude provides an adapter for Claude Code / Claude Desktop MCP configuration files (.mcp.json).

Claude's format is the de-facto standard adopted by most AI assistants including Cursor, Windsurf, and Cline.

File locations (per https://code.claude.com/docs/en/mcp):

  • Project scope: .mcp.json (in project root, checked into source control)
  • User/Local scope: ~/.claude.json (mcpServers field, private to user)
  • Enterprise managed:
  • macOS: /Library/Application Support/ClaudeCode/managed-mcp.json
  • Linux/WSL: /etc/claude-code/managed-mcp.json
  • Windows: C:\Program Files\ClaudeCode\managed-mcp.json

Index

Constants

View Source
const (
	// AdapterName is the identifier for this adapter.
	AdapterName = "claude"

	// ProjectConfigFile is the project-level config file name.
	ProjectConfigFile = ".mcp.json"

	// UserConfigFile is the user-level config file name.
	UserConfigFile = ".claude.json"

	// ManagedConfigFile is the enterprise managed config file name.
	ManagedConfigFile = "managed-mcp.json"
)

Variables

This section is empty.

Functions

func ReadProjectConfig

func ReadProjectConfig() (*core.Config, error)

ReadProjectConfig reads the project-level .mcp.json file.

func ReadUserConfig

func ReadUserConfig() (*core.Config, error)

ReadUserConfig reads the user-level ~/.claude.json file.

func WriteProjectConfig

func WriteProjectConfig(cfg *core.Config) error

WriteProjectConfig writes to the project-level .mcp.json file.

Types

type Adapter

type Adapter struct{}

Adapter implements core.Adapter for Claude Code / Claude Desktop.

func NewAdapter

func NewAdapter() *Adapter

NewAdapter creates a new Claude adapter.

func (*Adapter) DefaultPaths

func (a *Adapter) DefaultPaths() []string

DefaultPaths returns the default config file paths for Claude.

func (*Adapter) FromCore

func (a *Adapter) FromCore(cfg *core.Config) *Config

FromCore converts canonical config to Claude format.

func (*Adapter) Marshal

func (a *Adapter) Marshal(cfg *core.Config) ([]byte, error)

Marshal converts canonical config to Claude format.

func (*Adapter) Name

func (a *Adapter) Name() string

Name returns the adapter name.

func (*Adapter) Parse

func (a *Adapter) Parse(data []byte) (*core.Config, error)

Parse parses Claude config data into the canonical format.

func (*Adapter) ReadFile

func (a *Adapter) ReadFile(path string) (*core.Config, error)

ReadFile reads a Claude config file.

func (*Adapter) ToCore

func (a *Adapter) ToCore(claudeCfg *Config) *core.Config

ToCore converts Claude config to canonical format.

func (*Adapter) WriteFile

func (a *Adapter) WriteFile(cfg *core.Config, path string) error

WriteFile writes canonical config to a Claude format file.

type Config

type Config struct {
	// MCPServers maps server names to their configurations.
	MCPServers map[string]ServerConfig `json:"mcpServers"`
}

Config represents the Claude MCP configuration file format. This is the top-level structure for .mcp.json files.

func NewConfig

func NewConfig() *Config

NewConfig creates a new empty Claude config.

func (*Config) AddServer

func (c *Config) AddServer(name string, server ServerConfig)

AddServer adds a server to the configuration.

func (*Config) GetServer

func (c *Config) GetServer(name string) (ServerConfig, bool)

GetServer returns a server by name.

func (*Config) RemoveServer

func (c *Config) RemoveServer(name string)

RemoveServer removes a server from the configuration.

func (*Config) ServerNames

func (c *Config) ServerNames() []string

ServerNames returns a list of all server names.

type ServerConfig

type ServerConfig struct {
	// Type specifies the transport type: "stdio", "http", or "sse".
	// If omitted, inferred from Command (stdio) or URL (http).
	Type string `json:"type,omitempty"`

	// Command is the executable to run for stdio servers.
	Command string `json:"command,omitempty"`

	// Args are command-line arguments for the executable.
	Args []string `json:"args,omitempty"`

	// Env contains environment variables for the server process.
	// Supports variable expansion: ${VAR} and ${VAR:-default}
	Env map[string]string `json:"env,omitempty"`

	// URL is the endpoint for remote servers.
	URL string `json:"url,omitempty"`

	// Headers contains HTTP headers for authentication.
	Headers map[string]string `json:"headers,omitempty"`
}

ServerConfig represents a single MCP server in Claude's format.

func (*ServerConfig) IsHTTP

func (s *ServerConfig) IsHTTP() bool

IsHTTP returns true if the server uses HTTP transport.

func (*ServerConfig) IsSSE

func (s *ServerConfig) IsSSE() bool

IsSSE returns true if the server uses SSE transport.

func (*ServerConfig) IsStdio

func (s *ServerConfig) IsStdio() bool

IsStdio returns true if the server uses stdio transport.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL