swatplus-mcp
Serve a facts-only static index of the SWAT+ Fortran source so an assistant can navigate, trace, and debug it without reading code itself.
Find definitions:
find_procedurereturns a procedure's file, line range, module, imports, arguments, locals, inline units/meanings, and case vocabularies.Trace the call graph:
callers,callees, andcall_path(entry point down to a procedure), all exhaustive over the tree.Map file I/O:
file_iolists routines that open/read/write a file with unit numbers and lines;unit_usersdoes the same per Fortran unit, optionally filtered byopen/read/write.Track variable writes:
writersgives routines, lines, and full assignment statements for a variable or derived-type root.Set breakpoints:
loops,scope_at, andbreakpointcombine assignments, enclosing loops, index variables, and live variables at a line.Explore types and fields:
describe_typelists every field of a derived type with units and meaning;search_fieldsfinds identifiers from plain words like "lateral flow".Inspect run outputs:
read_outputsummarises a column (count, first, last, min/max with location, negatives) with optionalwherefilter.Check provenance:
provenancereports which checkout/commit the index describes, compile-check status, and warning count.Scanner warnings come as a separate content block; results are never sampled or truncated.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@swatplus-mcp List the loops in hru_control with file and line references"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Tamandua
Makes the coding assistant you already use — Claude Code, Copilot, Codex, a local model — cheaper and more accurate on SWAT+.
It is not an assistant. It builds a facts-only index of the SWAT+ Fortran
source, from static analysis alone, and serves it as MCP tools and as a
file in your checkout. Procedures with locations -- the main program in
main.f90.in among them -- the call graph with every call site, file I/O with
unit numbers, variable writes by field path and where each value is read, loop
headers with their index variables, derived types with the units and meaning
the source documents inline. Nothing in it is written by a model.
Dependency pins:
docs/pins.toml
Use it
If you just want the tools — no SWAT+ checkout or parser:
pip install "git+https://github.com/tugraskan/Tamandua.git@v0.1.1"The tagged package includes the pinned SWAT+ facts snapshot, verified fresh by
the release workflow -- pin a tag for that guarantee. Drop the @tag to track
main instead, which is the better choice once you have your own SWAT+
checkout (the server reparses that live, so the bundled snapshot is unused
anyway):
pip install --upgrade "git+https://github.com/tugraskan/Tamandua.git"The future PyPI distribution name is swatplus-tamandua (tamandua is already
owned by an unrelated project). Point your assistant at the server with no
machine-specific paths:
// .mcp.json (Claude Code) — VS Code uses .vscode/mcp.json, where these
// entries nest inside a top-level "servers" object instead.
{
"mcpServers": {
"swatplus-source": {
"command": "swatplus-mcp",
"args": ["--compact"]
}
}
}If you have a SWAT+ checkout and the parser, point the server directly at the source:
swatplus-mcp --source /path/to/swatplus --compactThe running process fingerprints the working Fortran tree before each request. It reparses only after an edit, so the next answer follows the source without a manual rebuild or server restart.
To produce a portable facts file for someone else:
cd <your swatplus checkout> && swatplus-buildThat writes swatplus-facts.json and nothing else. A server started with
--facts notices when that file is replaced and reloads the newest complete
snapshot without restarting. The package-bundled release snapshot remains
static by design.
Input-file layouts. What SWAT+ reads from each input file, column by column, in read order -- derived from the facts, with every column citing its declaration and every record the statement that reads it:
swatplus-layouts --file hru-data.hru # one file, bundled facts
swatplus-layouts --facts swatplus-facts.json --out swatplus-layouts.json
swatplus-layouts --links # every link between filesIt needs neither the parser nor a checkout. To follow your own tree, build its
facts with swatplus-build first and pass them with --facts. It reports
what the model reads, not everything a file may hold, and carries no header
names; see docs/layouts_experiment.md.
Links between input files. A column whose value names a row of another
file carries references: hru-data.hru's land_use_mgt → landuse.lum
name, evidence hru_read.f90:71. SWAT+ declares no foreign keys; it
searches at run time, and each link is one of those searches in the source --
directly, through a routine like search, or through a copy -- never a guess
from names that look alike. Against the editor schema's foreign keys, and what
neither covers: docs/links_experiment.md.
Where a value is used. writers says what assigns a variable; uses
says where its value is read, and how -- in a formula, a condition, a call, an
output list -- with the statement:
path|at|in|kind|detail|statement
hru%lumv%bmp_sed|smp_bmpfixed.f90:46|smp_bmpfixed|assignment|sedyld|sedyld(j) = sedyld(j) * (1. - hru(j)%lumv%bmp_sed)
bmpuser_db%bmp_sed|structure_set_parms.f90:103|structure_set_parms|copy|hru%lumv%bmp_sed|hru(j)%lumv%bmp_sed = bmpuser_db(istr)%bmp_sed(uses bmp_sed against SWAT+ 62.0.1, from swatplus-mcp --compact.)
A bare name matches the field under any parent; a full path
(hru%lumv%bmp_sed) only that path and what it holds. A copy only moves
the value, so a field whose every read is a copy is never computed with under
that name -- bmp_bac -- and no rows at all means it is never read. The
reads and statements are in swatplus-rhs.json, beside the facts. Kinds,
limits and the recall audit: docs/reads_experiment.md.
Related MCP server: Open Mind
Pairs with dataselector
swatplus-dataselector
serves the other half: what a column in an input file means, and what is in
a real TxtInOut dataset. The two don't overlap — this one knows what the
Fortran does, that one knows what the files hold. Run both and tell your
assistant which is for which.
Layout
tamandua/
├── index/ # build the facts, render, install pointers, snapshot
│ ├── build.py # static analysis -> SourceIndex
│ ├── snapshot.py # read/write swatplus-facts.json, so serving needs no parser
│ ├── render.py # SWATPLUS_INDEX.md
│ ├── install.py # assistant instruction-file pointers
│ ├── scope.py # loop nesting, for conditional breakpoints
│ ├── programs.py # the main program in main.f90.in, as a procedure
│ ├── reads.py # where each value is read, and how
│ └── layouts.py # input-file column layouts and the links between files
├── mcp/server.py # 16 read-only tools over the same objects
├── mcp/client.py # generic MCP stdio client (talk to another server)
├── output/reader.py # query a run's output files
└── config.py # loads docs/pins.tomlDevelop
export SWATPLUS_SOURCE=/path/to/swatplus
export SWATPLUS_REFERENCE_CORPUS=/path/to/swatplus-reference-corpus # the parser
python -m pip install -e ".[dev]"
pytestThe parser is a build-time dependency only: the bundled facts file lets the
installed server run with neither it nor the SWAT+ source. Pass --facts to use another snapshot or --source
to build live from a checkout.
# builds swatplus-facts.json plus sibling swatplus-rhs.json by default
swatplus-build --facts dist/swatplus-facts.json --out dist/SWATPLUS_INDEX.md
# serve them with nothing else installed
swatplus-mcp --facts dist/swatplus-facts.jsonTagging v*.*.* runs .github/workflows/release.yml,
which builds all three artifacts against the pinned commits, deletes the
checkouts, verifies the snapshot and sidecar still answer, and publishes them.
Principles
Facts only — if a model wrote it, it does not go in the index. Every claim
carries its file and line. Measure before concluding; findings live in
docs/*_experiment.md with the script that produced them. Eight defects in this
work were found by ordinary use and none by any harness, so prefer running the
thing over reasoning about it.
Available Tools
15 toolsbreakpointB
Where to stop to watch a variable, and on what condition: the routines that assign it, the loops enclosing each assignment, and their index variables. Relevant scanner warnings are returned separately when present.
Inputs: variable (required).
calleesA
Routines this procedure calls. Exhaustive, not truncated.
Inputs: procedure (required).
callersA
Routines that call this procedure. Exhaustive over the whole tree, never sampled or truncated -- one result means exactly one caller, not a partial list.
Inputs: procedure (required).
call_pathC
How execution reaches a procedure, from an entry point down.
Inputs: procedure (required).
describe_typeB
Every field of a derived type, with units, meaning and declaration -- what a state object like aqu_d actually contains, including whether a component is a scalar or a dimension(:), allocatable array.
Inputs: name (required).
file_ioA
Which routines open/read/write a file, with unit numbers and lines. Resolves output files opened via open_output_file. Exhaustive over the whole tree, not truncated.
Inputs: file (required).
find_procedureA
Locate a SWAT+ procedure: source file, line range, module, module imports and only lists, every argument and local declaration with source line/type/initial/inline units and meaning, and select-case vocabularies. All stored fields are returned, never sampled or truncated. Returns advisory scanner warnings in a second content block when this procedure has any; these are not compiler errors.
Inputs: name (required).
loopsA
Loop headers in a procedure with their index variables and start/end lines, for setting a conditional breakpoint. Exhaustive -- every loop in the procedure, not a sample. Relevant scanner warnings are returned separately when present.
Inputs: procedure (required).
module_variableA
A variable declared in a module body -- its declaring module, type, full declaration (so an allocatable array is distinguishable from a scalar), line, units and meaning. This is the program's global state: a state object like aqu_d is a module-level instance, which describe_type cannot confirm exists. Where a bare name is declared in more than one module, every candidate is returned rather than one being chosen. Falls back to a name and documented-meaning search when there is no exact match. Exhaustive, not truncated.
Inputs: name (required), module.
provenanceA
Which SWAT+ checkout and commit this index describes, its compile-check status, and scanner-warning count.
Inputs: no named parameters.
read_outputA
Summarise a column of a run's output file: count, first, last, min and max with where they occurred, and how many values went negative.
Inputs: file (required), column (required), where, label_by.
scope_atA
Which loops enclose a given line of a procedure, outermost first -- the variables live at that point. Relevant scanner warnings are returned separately when present.
Inputs: line (required), procedure (required).
search_fieldsA
Find a variable from ordinary words. Searches what the source says each field means, e.g. 'recharge' or 'lateral flow', and returns identifiers with units.
Inputs: text (required).
unit_usersA
Routines using a Fortran unit number, and the file each use targets. Optionally filter by operation. Exhaustive, not truncated.
Inputs: unit (required), op.
writersA
Routines that assign a variable, with line numbers and the complete logical assignment statement for derived-type paths when the RHS sidecar is installed. Exhaustive over the whole tree, never sampled or truncated. Relevant scanner warnings are returned separately when present.
Inputs: variable (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 15 tools
Each tool targets a distinct analysis query (type description, module variables, call graph, file I/O, unit numbers, writers, loops, provenance). Minor overlap exists in the loop/scope cluster (breakpoint, scope_at, loops all touch enclosing loops and conditions) and in describe_type vs module_variable, but the descriptions explicitly delineate them.
All names are snake_case, which is consistent casing. Verb styles vary somewhat (verb_noun like describe_type/find_procedure vs bare nouns like callers/writers/loops/provenance), but every name is short, readable and semantically descriptive.
15 tools sit squarely in the well-scoped range for a static-analysis server, and each one covers a distinct query surface (variables, types, control flow, call graph, I/O, provenance) rather than duplicating effort.
The surface covers variable/type introspection, control flow, the call graph in both directions, file/unit I/O, output reading, and provenance -- a strong read-only analysis toolkit. Minor gaps like enumerating all procedures in a module or listing modules could exist, but core navigation workflows are covered.
Maintenance
Related MCP Connectors
Repository knowledge graph MCP server for codebase understanding and debugging.
MCP server for querying Forkast documentation
Stateless TS/JS compiler facts for agents: references, imports, impact. No repo index or OAuth.
The Cortex MCP server provides read-only access to real-time engineering context from the Cortex developer portal, allowing AI coding assistants to answer natural language questions about your organization's catalog (microservices, libraries, domains, teams, infrastructure), scorecards (engineering standards and best practices), initiatives (goals and deadlines), and Engineering Intelligence metrics. It includes tools for querying documentation, tracking personal entities, and accessing AI-assisted insights across the entire Cortex ecosystem.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA local, SQLite-backed code index for Claude Code, exposed over MCP, enabling targeted code retrieval without external APIs.249 PyPI1MIT
- AlicenseNot gradedqualityDmaintenanceMCP server that builds a deterministic, source-traceable knowledge index of any codebase, enabling glossary lookup, code graphs, and exact-token search with every fact linked to its source file and line.1MIT
- AlicenseNot gradedqualityCmaintenanceEnables MCP clients such as Claude Desktop and Claude Code to query an indexed source repository through path-guarded tools for hybrid keyword-and-vector code search, file snippets, symbol explanations, reference lookups, and test-skeleton suggestions. Serves those results over stdio with cited file:line locations so agents can answer questions about a codebase and drive grounded code review.MIT
- AlicenseNot gradedqualityCmaintenanceEnables coding agents to search local repositories and retrieve bounded, cited source chunks, look up full indexed chunks, and inspect index statistics through read-only MCP tools over stdio.MIT