This document describes protolint's implementation of the Model Context Protocol (MCP), which allows AI models like Claude to interact with protolint directly.
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.
To start protolint in MCP server mode:
protolint --mcpThis starts protolint as an MCP server, which listens for commands via stdin and writes responses to stdout.
To use protolint with Claude Desktop:
-
Edit the Claude Desktop configuration file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
- macOS:
-
Add the following configuration:
{ "mcpServers": { "protolint": { "command": "/path/to/protolint", "args": ["--mcp"], "type": "stdio" } } } -
Replace
/path/to/protolintwith the absolute path to your protolint executable. -
Restart Claude Desktop.
The MCP server implementation follows the Model Context Protocol specification and uses JSON-RPC 2.0 for communication:
-
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.
-
Server Information: The server identifies itself as "protolint-mcp" with version "1.0.0".
-
Communication: Uses stdio for communication between the client and server.
-
Request Methods:
initialize: Initializes the connection and negotiates protocol versionnotifications/initialized: Notification that the client is readytools/list: Returns a list of available toolstools/call: Calls a specific tool with arguments
-
Response Format: All responses follow the JSON-RPC 2.0 format with appropriate result or error fields.
When running in MCP mode, protolint provides the following tools:
Lint Protocol Buffer files using protolint.
Arguments:
files: (required) An array of file paths to lintconfig_path: (optional) Path to protolint config filefix: (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
}
}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.
The lint-files tool returns the following exit codes:
0: No lint errors found1: Lint errors found2: Internal error occurred
The MCP implementation is located in the mcp directory and consists of:
protocol.go: Protocol message definitions and JSON-RPC 2.0 structuresserver.go: The MCP server implementation with request handlingtools.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.
If you encounter issues with the MCP server:
- Check that the protolint executable is in your PATH or use an absolute path in the configuration.
- Verify that the configuration file is correctly formatted.
- Restart Claude Desktop after making changes to the configuration.
- Check if there are any error messages in the Claude Desktop logs.
- Ensure the protocol version in your client configuration matches "2024-11-05" or is omitted to allow version negotiation.