Installing mcp-scan as a Go Library¶
This guide explains how to install and configure mcp-scan for use as a library in your Go projects.
Prerequisites¶
- Go 1.24 or higher
- Go modules enabled (
GO111MODULE=on)
Installation¶
1. Add the dependency¶
Or specifying a specific version:
2. Import the package¶
Package Structure¶
mcp-scan exposes a public API through the pkg/scanner package. Internal packages (internal/) are not available for external use.
github.com/mcphub/mcp-scan/
pkg/
scanner/ <- Main public API
internal/ <- Internal implementation (not exported)
types/ <- Shared types
surface/ <- MCP surface extraction
msss/ <- MSSS score calculation
baseline/ <- Baseline management
...
Importable Packages¶
| Package | Import Path | Use |
|---|---|---|
| Scanner | github.com/mcphub/mcp-scan/pkg/scanner |
Main API |
Support types like Finding, Severity, etc. are embedded in the scanner package structures.
Installation Verification¶
Create a test file to verify the installation is correct:
// test_install.go
package main
import (
"context"
"fmt"
"log"
"os"
"path/filepath"
"github.com/mcphub/mcp-scan/pkg/scanner"
)
func main() {
// Create temporary directory with test file
tmpDir, err := os.MkdirTemp("", "mcp-scan-test")
if err != nil {
log.Fatal(err)
}
defer os.RemoveAll(tmpDir)
// Create test Python file
testFile := filepath.Join(tmpDir, "server.py")
testCode := `
import os
from mcp import tool
@tool
def execute_command(cmd: str) -> str:
return os.system(cmd) # Vulnerable!
`
if err := os.WriteFile(testFile, []byte(testCode), 0644); err != nil {
log.Fatal(err)
}
// Execute scan
cfg := scanner.DefaultConfig()
s := scanner.New(cfg)
result, err := s.Scan(context.Background(), tmpDir)
if err != nil {
log.Fatal(err)
}
fmt.Println("mcp-scan installed successfully!")
fmt.Printf("Files scanned: %d\n", result.Manifest.TotalFiles)
fmt.Printf("Findings: %d\n", len(result.Findings))
}
Run:
Expected output:
Development Environment Configuration¶
Optional Environment Variables¶
mcp-scan does not require environment variables to function. However, the following may be useful:
| Variable | Description | Default Value |
|---|---|---|
MCP_SCAN_WORKERS |
Number of parallel workers | runtime.NumCPU() |
Build Dependencies¶
mcp-scan uses tree-sitter for code parsing. The native tree-sitter libraries are included as Go bindings and compile automatically.
If you experience build issues on systems without a C compiler:
# Linux (Debian/Ubuntu)
sudo apt-get install build-essential
# macOS
xcode-select --install
# Windows
# Install MinGW-w64 or use WSL
Updating¶
To update to the latest version:
To update to a specific version:
Versioning¶
mcp-scan follows Semantic Versioning:
- MAJOR: Incompatible API changes
- MINOR: New backward-compatible functionality
- PATCH: Backward-compatible bug fixes
Common Issues¶
Error: "cannot find module"¶
Make sure Go modules are enabled:
Error: "cgo: C compiler not found"¶
Install C development tools (see build dependencies section above).
Error: "version not found"¶
Verify you are using an existing version:
Next Step¶
See the Public API Reference to learn about all available types and methods.