This document describes the Model Context Protocol (MCP) server for Goblint, which allows Large Language Models (LLMs) and other MCP-compatible clients to interact with Goblint's static analysis capabilities.
The MCP server provides a standardized JSON-RPC 2.0 based interface for:
- Configuring Goblint analysis options
- Running analysis on single C files
- Running analysis on projects using compilation databases
- Querying analysis results
Build and install the MCP server:
make
make installThis will install the goblint-mcp-server executable into your opam switch.
The MCP server communicates via stdin/stdout using JSON-RPC 2.0:
goblint-mcp-serverThe server follows the MCP protocol specification and can be integrated with any MCP-compatible client or LLM framework.
The client should initialize the connection with:
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "your-client-name",
"version": "1.0.0"
}
}
}The server provides the following tools (accessible via tools/list and tools/call):
Configure Goblint analysis options.
Input Schema:
{
"option": "string",
"value": "string"
}Example:
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "configure",
"arguments": {
"option": "ana.activated[+]",
"value": "'base'"
}
}
}Reset all configuration to default values.
Input Schema:
{}Run Goblint analysis on a single C source file.
Input Schema:
{
"file": "string",
"reset": "boolean (optional)"
}Example:
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "analyze_file",
"arguments": {
"file": "/path/to/source.c",
"reset": false
}
}
}Run Goblint analysis on a project using a compilation database.
Input Schema:
{
"compilation_database": "string",
"reset": "boolean (optional)"
}Example:
{
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "analyze_project",
"arguments": {
"compilation_database": "/path/to/compile_commands.json",
"reset": false
}
}
}Retrieve all analysis messages (warnings, errors, etc.) from the last analysis run.
Input Schema:
{}Returns: JSON array of message objects with location, severity, and text.
Get a list of all functions found in the analyzed code.
Input Schema:
{}Returns: JSON array of function objects with name and location.
Query the analysis state at a specific program location.
Input Schema:
{
"node": "string"
}Example:
{
"jsonrpc": "2.0",
"id": 5,
"method": "tools/call",
"params": {
"name": "query_state",
"arguments": {
"node": "main:1"
}
}
}Add to your Claude Desktop configuration (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"goblint": {
"command": "goblint-mcp-server",
"args": []
}
}
}The server is compatible with any MCP client that follows the Model Context Protocol specification. Refer to your client's documentation for integration instructions.
- Initialize the connection
- (Optional) Configure analysis options using
configure - Run analysis using either
analyze_fileoranalyze_project - Query results using
get_messages,get_functions, orquery_state - (Optional) Analyze another file or project
For complex projects, use a compilation database (compile_commands.json) which can be generated by build systems like CMake or using tools like Bear:
# Using Bear to capture compilation commands
bear -- make
# This generates compile_commands.json
goblint-mcp-server
# Then use the analyze_project tool with the path to compile_commands.jsonGoblint has many configuration options. Common options include:
ana.activated[+]: Add an analysis (e.g.,'base','threadid','race')dbg.level: Set debug level ("info","debug","verbose")pre.includes[+]: Add include directoryana.sv-comp.functions: Enable SV-COMP mode
See the Goblint documentation for a complete list of options.
Ensure the server is receiving properly formatted JSON-RPC 2.0 messages. Each message should be a single line terminated with a newline.
Check the tool result's isError field and content for error messages. Common issues:
- File not found
- Invalid C syntax
- Missing include files
- Invalid configuration options
To enable debug logging, configure Goblint before analyzing:
{
"method": "tools/call",
"params": {
"name": "configure",
"arguments": {
"option": "dbg.level",
"value": "\"debug\""
}
}
}- The MCP server currently supports a subset of Goblint's full functionality
- Complex queries and incremental analysis features from the standard Goblint server mode are not yet exposed via MCP
- Large projects may take significant time to analyze
To add new MCP tools or improve the server, modify:
src/util/mcpServer.ml- Core MCP server implementationsrc/goblint_mcp_server.ml- Executable entry point
Follow the existing tool patterns and ensure new tools are documented in this file.