parser

package
v0.7.0 Latest Latest
Warning

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

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

Documentation

Overview

Package parser provides JSON parsing and writing for canonical MCP configurations. It handles loading MCP config files from disk and writing them back with proper formatting and atomic file operations.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidJSON indicates the input is not valid JSON.
	ErrInvalidJSON = errors.New("invalid JSON")

	// ErrInvalidConfig indicates the JSON doesn't represent a valid MCP config.
	ErrInvalidConfig = errors.New("invalid MCP configuration")
)

Sentinel errors for parser operations.

Functions

func Parse

func Parse(data []byte) (*mcp.Config, error)

Parse reads a canonical MCP config from JSON bytes. Returns an error if the JSON is malformed or doesn't represent a valid config.

func ParseFile

func ParseFile(path string) (*mcp.Config, error)

ParseFile reads a canonical MCP config from a file path. Returns an empty config (not error) if the file doesn't exist, following the principle that a missing config file means "no servers configured". Returns an error for other file system issues or invalid JSON.

func Write

func Write(cfg *mcp.Config) ([]byte, error)

Write writes a canonical MCP config to JSON bytes with indentation. The output is formatted with 2-space indentation for readability.

func WriteFile

func WriteFile(path string, cfg *mcp.Config) error

WriteFile writes a canonical MCP config to a file using atomic write. It writes to a temporary file first, then renames to the target path. This ensures the file is never left in a partial/corrupt state. Creates parent directories if they don't exist.

Types

type ParseError

type ParseError struct {
	Path string
	Err  error
}

ParseError wraps errors that occur during parsing with path context.

func (*ParseError) Error

func (e *ParseError) Error() string

func (*ParseError) Unwrap

func (e *ParseError) Unwrap() error

Jump to

Keyboard shortcuts

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