mcp

package
v0.56.2 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2025 License: MIT Imports: 7 Imported by: 0

README

protolint MCP Server

This document describes protolint's implementation of the Model Context Protocol (MCP), which allows AI models like Claude to interact with protolint directly.

Overview

The Model Context Protocol (MCP) is a standardized protocol that facilitates communication between AI assistants and external tools. By implementing MCP, protolint can be used directly by AI assistants to lint Protocol Buffer files.

Usage

To start protolint in MCP server mode:

protolint --mcp

This starts protolint as an MCP server, which listens for commands via stdin and writes responses to stdout.

Integrating with Claude Desktop

To use protolint with Claude Desktop:

  1. Edit the Claude Desktop configuration file:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
  2. Add the following configuration:

    {
      "mcpServers": {
        "protolint": {
          "command": "/path/to/protolint",
          "args": ["--mcp"],
          "type": "stdio"
        }
      }
    }
    
  3. Replace /path/to/protolint with the absolute path to your protolint executable.

  4. Restart Claude Desktop.

Protocol Implementation

The MCP server implementation follows the Model Context Protocol specification and uses JSON-RPC 2.0 for communication:

  1. Protocol Version: The server supports version "2024-11-05" of the MCP protocol. If a client requests a different version, the server will respond with this supported version as specified in the protocol's version negotiation mechanism.

  2. Server Information: The server identifies itself as "protolint-mcp" with version "1.0.0".

  3. Communication: Uses stdio for communication between the client and server.

  4. Request Methods:

    • initialize: Initializes the connection and negotiates protocol version
    • notifications/initialized: Notification that the client is ready
    • tools/list: Returns a list of available tools
    • tools/call: Calls a specific tool with arguments
  5. Response Format: All responses follow the JSON-RPC 2.0 format with appropriate result or error fields.

Available Tools

When running in MCP mode, protolint provides the following tools:

lint-files

Lint Protocol Buffer files using protolint.

Arguments:

  • files: (required) An array of file paths to lint
  • config_path: (optional) Path to protolint config file
  • fix: (optional) Fix lint errors if possible

Example request:

{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "id": "request-1234",
  "params": {
    "name": "lint-files",
    "arguments": {
      "files": ["/path/to/file1.proto", "/path/to/file2.proto"],
      "config_path": "/path/to/config.yaml",
      "fix": true
    }
  }
}

Example response:

{
  "jsonrpc": "2.0",
  "id": "request-1234",
  "result": {
    "content": [
      {
        "type": "text",
        "text": "{\"exit_code\":0,\"results\":[{\"file_path\":\"/path/to/file1.proto\",\"failures\":[{\"rule_id\":\"ENUM_NAMES_UPPER_CAMEL_CASE\",\"message\":\"Enum name must be UpperCamelCase\",\"line\":5,\"column\":6,\"severity\":\"error\"}]}]}"
      }
    ],
    "isError": false
  }
}

Example Usage in Claude Desktop

Once configured, you can ask Claude to lint your Protocol Buffer files:

Can you lint my protocol buffer files /path/to/file1.proto and /path/to/file2.proto?

Claude will use protolint to analyze the files and report any issues it finds.

Exit Codes

The lint-files tool returns the following exit codes:

  • 0: No lint errors found
  • 1: Lint errors found
  • 2: Internal error occurred

Development

The MCP implementation is located in the mcp directory and consists of:

  • protocol.go: Protocol message definitions and JSON-RPC 2.0 structures
  • server.go: The MCP server implementation with request handling
  • tools.go: Tool implementations, currently only the lint-files tool

The server uses the MCP reporter for output formatting, which is configured when executing the lint command.

Troubleshooting

If you encounter issues with the MCP server:

  1. Check that the protolint executable is in your PATH or use an absolute path in the configuration.
  2. Verify that the configuration file is correctly formatted.
  3. Restart Claude Desktop after making changes to the configuration.
  4. Check if there are any error messages in the Claude Desktop logs.
  5. Ensure the protocol version in your client configuration matches "2024-11-05" or is omitted to allow version negotiation.

Documentation

Overview

Package mcp implements the Model Context Protocol (MCP) server for protolint.

Package mcp implements the Model Context Protocol (MCP) server for protolint.

Package mcp implements the Model Context Protocol (MCP) server for protolint.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallToolPayload

type CallToolPayload struct {
	Name      string          `json:"name"`
	Arguments json.RawMessage `json:"arguments"`
}

CallToolPayload represents the payload for call_tool request

type CallToolResponse

type CallToolResponse struct {
	Content []ContentItem `json:"content"`
	IsError bool          `json:"isError"`
}

CallToolResponse represents the response for call_tool request

type ClientCapabilities

type ClientCapabilities struct {
	Roots        map[string]interface{} `json:"roots,omitempty"`
	Sampling     map[string]interface{} `json:"sampling,omitempty"`
	Experimental map[string]interface{} `json:"experimental,omitempty"`
}

ClientCapabilities represents client capabilities

type ClientInfo

type ClientInfo struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

ClientInfo represents information about the client

type ContentItem

type ContentItem struct {
	Type     string      `json:"type"`
	Text     string      `json:"text,omitempty"`
	Data     string      `json:"data,omitempty"`
	MimeType string      `json:"mimeType,omitempty"`
	Resource interface{} `json:"resource,omitempty"`
}

ContentItem represents a content item in a tool result

type Error

type Error struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

Error represents a JSON-RPC 2.0 error

type InitializeParams

type InitializeParams struct {
	ProtocolVersion string             `json:"protocolVersion"`
	Capabilities    ClientCapabilities `json:"capabilities"`
	ClientInfo      ClientInfo         `json:"clientInfo,omitempty"`
}

InitializeParams represents the parameters for initialize request

type InitializeResult

type InitializeResult struct {
	ProtocolVersion string             `json:"protocolVersion"`
	Capabilities    ServerCapabilities `json:"capabilities"`
	ServerInfo      ServerInfo         `json:"serverInfo"`
	Instructions    string             `json:"instructions,omitempty"`
}

InitializeResult represents the response for initialize request

type LintFilesArgs

type LintFilesArgs struct {
	Files      []string `json:"files"`
	ConfigPath string   `json:"config_path,omitempty"`
	Fix        bool     `json:"fix,omitempty"`
}

LintFilesArgs represents arguments for lint-files tool

type LintFilesTool

type LintFilesTool struct{}

LintFilesTool is a tool for linting Proto files

func NewLintFilesTool

func NewLintFilesTool() *LintFilesTool

NewLintFilesTool creates a new LintFilesTool

func (*LintFilesTool) Execute

func (t *LintFilesTool) Execute(args json.RawMessage) (any, error)

Execute runs the lint-files tool

func (*LintFilesTool) GetInfo

func (t *LintFilesTool) GetInfo() ToolInfo

GetInfo returns the tool information

type ListToolsResponse

type ListToolsResponse struct {
	Tools []ToolInfo `json:"tools"`
}

ListToolsResponse represents the response for list_tools request

type Request

type Request struct {
	JSONRPC string          `json:"jsonrpc"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params"`
	ID      interface{}     `json:"id"`
}

Request represents a JSON-RPC 2.0 request

type Response

type Response struct {
	JSONRPC string      `json:"jsonrpc"`
	Result  interface{} `json:"result,omitempty"`
	Error   *Error      `json:"error,omitempty"`
	ID      interface{} `json:"id"`
}

Response represents a JSON-RPC 2.0 response

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents an MCP server

func NewServer

func NewServer(stdout, stderr io.Writer) *Server

NewServer creates a new MCP server

func (*Server) Run

func (s *Server) Run() osutil.ExitCode

Run starts the MCP server

type ServerCapabilities

type ServerCapabilities struct {
	Prompts      map[string]interface{} `json:"prompts,omitempty"`
	Resources    map[string]interface{} `json:"resources,omitempty"`
	Tools        map[string]interface{} `json:"tools,omitempty"`
	Logging      map[string]interface{} `json:"logging,omitempty"`
	Experimental map[string]interface{} `json:"experimental,omitempty"`
}

ServerCapabilities represents the server's capabilities

type ServerInfo

type ServerInfo struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

ServerInfo represents information about the server

type Tool

type Tool interface {
	GetInfo() ToolInfo
	Execute(args json.RawMessage) (any, error)
}

Tool defines the interface for MCP tools

type ToolInfo

type ToolInfo struct {
	Name        string      `json:"name"`
	Description string      `json:"description"`
	InputSchema interface{} `json:"inputSchema,omitempty"`
}

ToolInfo represents information about a tool

Jump to

Keyboard shortcuts

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