Tools for generating, exploring, formatting, analyzing, and rendering source code. All tools are stateless.
Generate language-specific type definitions from raw JSON.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
json |
string | ✓ | — | Raw JSON payload |
language |
string | ✓ | — | typescript | go | rust |
root_name |
string | AutoGenerated |
Root type name |
{
"language": "go",
"root_name": "User",
"code": "type User struct { ... }"
}Build a lightweight AST outline for JavaScript/TypeScript code to inspect declarations and structure.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
code |
string | ✓ | — | JavaScript or TypeScript source code |
language |
string | javascript |
javascript | typescript |
{
"language": "typescript",
"ast": { "type": "Program", "children": [ ... ] },
"summary": {
"ImportDeclaration": 1,
"ClassDeclaration": 1,
"FunctionDeclaration": 2
}
}Format source code for a given language.
Supported languages:
go— usesgo/format.Source(), always tab-indented per Go standardjson— re-indents with configurable indent (spaces or tabs)typescript(also acceptsjavascript) — indent normalization; detects current indent unit and re-indents to targethtml— heuristic tag indentation: one tag per line, children indentedcss— normalizes rule blocks: one property per line, consistent indentation
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
code |
string | ✓ | — | Source code to format |
language |
string | ✓ | — | go | typescript | json | html | css |
indent_size |
integer | — | 2 |
Indent size in spaces (ignored for Go) |
use_tabs |
boolean | — | false |
Use tabs instead of spaces (Go always uses tabs) |
{
"result": "<formatted code>",
"language": "<lang>",
"changed": true
}| Field | Type | Description |
|---|---|---|
result |
string | Formatted source code |
language |
string | Normalized language identifier |
changed |
boolean | true if the output differs from the input |
| Condition | Error message |
|---|---|
code is empty or whitespace |
"code is required" |
| Unsupported language | "unsupported language \"X\" (supported: ...)" |
| Go syntax error | "Go format error: ..." |
| Invalid JSON | "JSON format error: ..." |
Format Go code:
{
"code": "package main\nimport \"fmt\"\nfunc main(){fmt.Println(\"hello\")}",
"language": "go"
}Format JSON with 4-space indent:
{
"code": "{\"a\":1,\"b\":[1,2]}",
"language": "json",
"indent_size": 4
}Re-indent TypeScript from 4 spaces to 2:
{
"code": "function hello() {\n const x = 1;\n return x;\n}",
"language": "typescript",
"indent_size": 2
}Compute code quality metrics for source code.
| Parameter | Type | Required | Description |
|---|---|---|---|
code |
string | ✓ | Source code to analyze |
language |
string | ✓ | go | typescript | python | generic |
{
"loc": 42,
"sloc": 30,
"blank_lines": 8,
"comment_lines": 4,
"functions": 5,
"complexity_estimate": 12,
"language": "go"
}| Field | Type | Description |
|---|---|---|
loc |
integer | Total lines including blank and comments |
sloc |
integer | Source lines (non-blank, non-comment) |
blank_lines |
integer | Lines that are empty or only whitespace |
comment_lines |
integer | Lines that are comments (//, #, /* */, docstrings) |
functions |
integer | Count of function/method declarations |
complexity_estimate |
integer | Count of branching points |
language |
string | Normalized language identifier |
Invariant: loc = sloc + blank_lines + comment_lines
Counted branching points per language:
| Token | Go | TypeScript | Python |
|---|---|---|---|
if / elif |
✓ | ✓ | ✓ |
else if |
— | ✓ | — |
for / while |
✓ | ✓ | ✓ |
case (switch) |
✓ | ✓ | ✓ |
select |
✓ | — | — |
&& / || |
✓ | ✓ | — |
and / or |
— | — | ✓ |
? (ternary) |
— | ✓ | — |
For Go, function and complexity counts use go/ast when the source is valid Go; otherwise falls back to regex.
| Condition | Error message |
|---|---|
code is empty or whitespace |
"code is required" |
| Unsupported language | "unsupported language \"X\" (supported: ...)" |
{
"code": "package main\n\nfunc add(a, b int) int {\n\tif a > 0 {\n\t\treturn a + b\n\t}\n\treturn b\n}",
"language": "go"
}Response:
{
"loc": 8,
"sloc": 7,
"blank_lines": 1,
"comment_lines": 0,
"functions": 1,
"complexity_estimate": 1,
"language": "go"
}Render a template string with JSON context bindings.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
template |
string | ✓ | — | Template string to render |
context |
string | ✓ | — | JSON object with variable bindings |
engine |
string | — | go |
Template engine: go | mustache |
{
"result": "<rendered output>"
}Uses Go's standard text/template package. Full template syntax is supported:
{{.variable}}— variable access{{range .items}}...{{end}}— iteration{{if .condition}}...{{end}}— conditional{{with .value}}...{{end}}— scope change- All built-in functions (
len,index,printf, etc.)
Security note: Uses text/template, not html/template. Callers control escaping.
Supported Mustache tags:
| Tag | Description |
|---|---|
{{variable}} |
Variable interpolation |
{{{variable}}} |
Unescaped variable (same behavior) |
{{#section}}...{{/section}} |
Truthy check; iterates if value is an array |
{{^inverted}}...{{/inverted}} |
Renders when value is falsy or empty |
{{! comment }} |
Comment (stripped from output) |
Dot notation is supported for nested values: {{user.name}}.
Iteration: When a section value is an array of objects, each item's keys are merged into the context for that iteration.
| Condition | Error message |
|---|---|
template is empty |
"template is required" |
context is empty |
"context is required" |
| Invalid context JSON | "invalid context JSON: ..." |
| Go template parse error | "template execution error: parse error: ..." |
| Go template execute error | "template execution error: execute error: ..." |
| Mustache parse/render error | "mustache error: ..." |
| Unsupported engine | "unsupported engine \"X\" (supported: go, mustache)" |
Go template with range:
{
"template": "{{range .items}}- {{.}}\n{{end}}",
"context": "{\"items\": [\"foo\", \"bar\", \"baz\"]}",
"engine": "go"
}Output: - foo\n- bar\n- baz\n
Mustache with section and iteration:
{
"template": "{{#users}}Hello, {{name}}!\n{{/users}}",
"context": "{\"users\": [{\"name\": \"Alice\"}, {\"name\": \"Bob\"}]}",
"engine": "mustache"
}Output: Hello, Alice!\nHello, Bob!\n
Mustache inverted section:
{
"template": "{{^items}}No items found.{{/items}}",
"context": "{\"items\": []}",
"engine": "mustache"
}Output: No items found.
- Package:
dev-forge-mcp/internal/tools/codetools+dev-forge-mcp/internal/tools/codetools/transform - Registration:
cmd/devforge-mcp/register_codetools.go - Dependencies: Standard library (
go/format,go/parser,go/ast,go/token,text/template,regexp,strings,unicode,encoding/json) - No external formatters — no Prettier, no goimports beyond the stdlib
go/format - All tools accept
context.Contextas first argument - All errors return
{"error": "message"}— tools never panic