4.6 KiB
Context - gocp Project
CRITICAL INSTRUCTIONS - MUST FOLLOW
-
Simple commits: One-line commit messages ONLY. NEVER add "Generated by Claude" footers, emojis, or any multi-line messages. Just describe what changed in one line.
-
Minimal comments: Only add comments when absolutely critical for disambiguation
-
Never use
go build: Always usego runinstead ofgo buildfor testing Go programs -
Never change directories: Never change directories with
cd- always use absolute paths instead -
Error handling: Always propagate errors with proper messages, never silently handle errors
Project Overview
gocp is a Go MCP (Model Context Protocol) server that provides tools for building and executing Go code. It uses the go-mcp library to implement the MCP protocol.
Key Files
main.go: MCP server implementation with tools and handlersast.go: Go AST parsing and code analysis functionalitygo.mod: Module definition with go-mcp dependency
Tool Details
build_and_run_go
Executes Go code using go run
- Parameters:
code(required): Go source code to executetimeout(optional): Timeout in seconds (default: 30)
- Returns JSON with:
stdout: Standard outputstderr: Standard errorexit_code: Process exit codeerror: Error message if any
- Creates temporary directories with
gocp-*prefix
find_symbols
Find all functions, types, interfaces, constants, and variables by name/pattern
- Parameters:
dir(optional): Directory to search (default: current directory)pattern(optional): Symbol name pattern to search for (case-insensitive substring match)
- Returns JSON array of symbols with:
name: Symbol nametype: Symbol type (function, struct, interface, constant, variable)package: Package namefile: File pathline: Line numbercolumn: Column numberexported: Whether the symbol is exported
get_type_info
Get detailed information about a type including fields, methods, and embedded types
- Parameters:
dir(optional): Directory to search (default: current directory)type(required): Type name to get information for
- Returns JSON with:
name: Type namepackage: Package namefile: File pathline: Line numberkind: Type kind (struct, interface, alias, other)fields: Array of field information (for structs)methods: Array of methodsembedded: Array of embedded type namesinterface: Array of interface methods (for interfaces)underlying: Underlying type (for aliases)
find_references
Find all references to a symbol (function calls, type usage, etc.)
- Parameters:
dir(optional): Directory to search (default: current directory)symbol(required): Symbol name to find references for
- Returns JSON array of references with:
file: File pathline: Line numbercolumn: Column numbercontext: Code context around the referencekind: Reference kind (identifier, selector)
list_packages
List all Go packages in directory tree
- Parameters:
dir(optional): Directory to search (default: current directory)
- Returns JSON array of packages with:
import_path: Import path relative to search directoryname: Package namedir: Directory pathgo_files: List of Go source filesimports: List of imported packages
go_run
Execute go run command with specified path and optional flags
- Parameters:
path(required): Path to Go file or package to runflags(optional): Optional flags for go run (space-separated)timeout(optional): Timeout in seconds (default: 30)
- Returns JSON with:
stdout: Standard output from go runstderr: Standard error from go runexit_code: Process exit codeerror: Error message if anycommand: The full command that was executedwork_dir: Working directory where command was run
go_test
Execute go test command with specified path and optional flags
- Parameters:
path(required): Path to Go package or directory to testflags(optional): Optional flags for go test (space-separated, e.g., '-v -cover -race')timeout(optional): Timeout in seconds (default: 60)
- Returns JSON with:
stdout: Standard output from go teststderr: Standard error from go testexit_code: Process exit codeerror: Error message if anycommand: The full command that was executedwork_dir: Working directory where command was runpassed: Boolean indicating if tests passedtest_count: Number of tests found (if detectable)