Repository navigation
MCP Server
MatPlotLibNet.Mcp is a Model Context Protocol server. It is a .NET tool that an
MCP host (Claude Code, Claude Desktop, VS Code) starts over stdio. Through it, a model can render this library's
charts and look at the result.
The package is a .NET tool. The .NET 10 SDK resolves and runs it, so there is nothing to install by hand.
{
"servers": {
"MatPlotLibNet.Mcp": {
"type": "stdio",
"command": "dnx",
"args": ["MatPlotLibNet.Mcp", "--yes"]
}
}
}For Claude Code, run claude mcp add matplotlibnet -- dnx MatPlotLibNet.Mcp --yes.
The server is listed in the official MCP Registry under the name
io.github.xkqg/matplotlibnet, so a host that resolves servers by name finds it there. The NuGet package id
stays MatPlotLibNet.Mcp.
There is one optional setting, MATPLOTLIBNET_MCP_OUTPUT_ROOT. It sets the only directory save_chart may
write under. It defaults to the system temp directory.
| tool | what it does |
|---|---|
render_chart(spec, format) |
renders the spec and returns a PNG the model can see, with a text summary beside it |
save_chart(spec, path, format, overwrite) |
writes PNG, SVG or PDF to a file and returns the path it wrote |
chart_data_table(spec) |
returns the chart's data twice: markdown tables to read, and the same values as structured content to compute with |
list_chart_types() |
lists the chart types a spec may name |
describe_chart_schema(seriesType) |
describes the fields of a spec, or of one chart type, with a worked example |
SVG and PDF are not returned inline, because a single SVG of a normal chart is tens of thousands of characters in
the model's context. save_chart writes them to a file instead.
Each tool also tells the host what it does to the machine it runs on, which is what a host uses to decide whether
to run it without asking. Four of the five change nothing and are marked read-only. save_chart writes a file,
and with overwrite: true it replaces one, so it is marked as changing things and as able to destroy something.
None of the five reaches out to the internet or to anything outside its own arguments. Left unsaid, the protocol
assumes the opposite on both counts, so a host would warn about a tool that only draws a picture.
A spec is the library's own figure JSON: the same document that figure.ToJson() writes and
ChartSerializer.FromJson reads. Because there is one definition of a chart, an agent can ask for anything the
library draws.
{
"width": 800,
"height": 600,
"title": "Revenue",
"subPlots": [
{
"xAxis": { "label": "Quarter" },
"yAxis": { "label": "€M" },
"series": [
{ "type": "line", "xData": [1, 2, 3, 4], "yData": [12, 18, 15, 22], "label": "2026", "color": "steelblue" }
]
}
]
}The same JSON in C#:
using MatPlotLibNet;
using MatPlotLibNet.Styling;
string spec = Plt.Create()
.WithSize(800, 600)
.WithTitle("Revenue")
.AddSubPlot(1, 1, 1, ax => ax
.SetXLabel("Quarter")
.SetYLabel("€M")
.Plot([1, 2, 3, 4], [12, 18, 15, 22], s => { s.Label = "2026"; s.Color = Color.FromName("steelblue"); }))
.Build()
.ToJson(indented: true);That is the fastest way to learn the format. Build the chart you want with the fluent API, print its JSON, and give that JSON to the model.
The document carries everything the figure draws: every setting of every series, the axes, legend, colour bar, grid
and spines, the theme, a colour map built in code, and a missing value, written "NaN" (the infinities
"Infinity" and "-Infinity"). A spec read back draws the picture the figure drew.
Four fields are new and each is written only when it is set: gridChange (what the author changed over the theme's grid, next
to the grid as it resolved), neutralColor on a theme, wearsNeutral on a series that wears the theme's neutral grey, and
firstCellDate on a calendar heatmap. A server that does not know them refuses them by name, and a figure that sets none
writes the file it wrote before.
Pareto, Ridgeline, CalendarHeatmap, BumpChart and the other verbs that build a chart in one call add
ordinary series (bars, lines, areas, a heatmap, a scatter) with the ticks and limits the chart needs. Their JSON is
those parts and names no verb: a Pareto chart is a bar series and a line on the right-hand axis, a ridgeline one area
for each ridge with the group names as the Y axis' ticks. The server renders such a document like any other, and a
spec that names a verb as its type ("type": "pareto") is refused like any type the server does not list. To hand a
model one of these charts, build it in C# and print its JSON, as above.
The server lists three more chart types, waffle, pointandfigure and icicle, and accepts the fields that came with them:
waffleRows, waffleColumns and cellGap on a waffle chart, boxSize and reversal on a Point and Figure series,
gradientColor on a bar or an area series, targets and targetColor on a waterfall, columnAlignments (accepted: Left,
Center, Right) and columnWidths on a table, boundsFrom and boundsTo on a spine, aspect on an axes, and Arc as a
network graph's layout. Renko, Kagi, ConnectedScatter, StemAndLeaf, MatShow and CalendarEvents are verbs, so
they travel as their parts like the others, and a figure that sets none of the new fields writes the JSON it wrote before.
Four fields are new, and each is written only when it is set. On the figure, texts lists the texts placed on the figure itself
(matplotlib's figtext: a text, an x and a y as fractions of the figure counted up from the bottom-left corner, and an optional
font, color, alignment, verticalAlignment and rotation), images lists the images placed on it (figimage: data as a list of
rows of equal length, the first row on top, a missing cell the string "NaN", xOffset and yOffset in pixels, and an optional colour
map, vMin, vMax and alpha), and legends lists the legends of the whole figure (fig.legend()): {} is a legend at its
defaults; each lists the labelled series of every subplot and is static, and an outside position stands it at the middle of that edge
of the figure, where a constrained layout keeps room for it. The one legend of an older document is read as the first of them. On an inset, zoomIndicator is the
zoom the inset indicates on its parent (indicate_inset_zoom); {} is an indicator at its defaults, and color, alpha,
lineWidth, lineStyle and connectors change it.
Stairs, VLines, HLines, Triplot, Psd, Csd, Cohere, MagnitudeSpectrum, PhaseSpectrum, AngleSpectrum, Acorr and
Xcorr are verbs, so they travel as their parts like the others: a line series whose missing points are the string "NaN" (a
correlation drawn as stems adds a reference line at 0, and a staircase with a baseline is an area series), and the spec never names
a verb. A figure that sets none of the new fields writes the JSON it wrote before, and a 1.27.0 reader skips them without a word and
draws the figure without them. describe_chart_schema lists all four with the words above, and chart_data_table gives the
text of a figure and the size and place of each image as tables of their own.
A subplot carries its shapes as patches, matplotlib's patches in data coordinates, each told apart by type: rectangle
(anchor, width, height, angle), polygon (vertices, closed), arrow (start, dx, dy, width, headWidth,
headLength, lengthIncludesHead, shape, overhang), circle (center, radius), ellipse (center, width, height,
angle), wedge (center, radius, theta1, theta2, width) and arc (center, width, height, angle, theta1,
theta2). A point is {"dataX": …, "dataY": …} and an angle is in degrees, counter-clockwise. Every kind takes edgeColor,
edgeWidth, edgeLineStyle, alpha, label, hatch and hatchColor, and every kind but the arc faceColor. An axis carries
link when it shows the primary axis' values in another unit (matplotlib's secondary_xaxis and secondary_yaxis, on the top
axis or a Y axis past the primary): {"type": "linear", "scale": 1.8, "offset": 32}, or reciprocal (numerator), logarithm
(base) or power (exponent). A subplot of a grid of more than one cell carries subplot (rows, cols, index), and the
buy and sell markers of a subplot are signals.
The server checks the kind of a patch and of a link, and a patch's edgeLineStyle, hatch, zDir and an arrow's shape, by name at
every place they stand, an inset included: "type": "circel" is refused with the seven kinds it accepts. It now also checks an
axes' coordinateSystem, the position of a spine (in any case: "DATA" reads as data, where it became the default edge
silently), a theme's defaultLegendPosition and the hatch of a node of a tree. A spec with no series is drawn when a subplot
holds an overlay of its own (a patch, a span, a reference line, an annotation, a trendline, a level, a Fibonacci retracement or
a signal); a legend, a colour bar, an axis break or a linked axis alone is still refused as having nothing to draw. A figure that
sets none of the new fields writes the JSON it wrote before, and a 1.28.0 reader skips them.
A table carries tableLocation (accepted: InPlot, BelowAxes), where it stands: in the plot from its top, or below the axes as
matplotlib's ax.table stands one. A table with none stands where its theme stands it, below the axes under the matplotlib themes and in
the plot under the library's own; a stem-and-leaf display writes InPlot, so it stands in its plot under every theme.
FromJson is a round-trip reader for the library's own writer. It drops an unknown series type, skips an unknown
property and leaves out a misspelled enum value with only a diagnostic, so that a newer document still loads in an older build. When a model
writes the document, that lenience turns every typo into a blank chart that is reported as a success. So the server
validates the spec first, and the error message names the field:
| what the model wrote | what it gets back |
|---|---|
"type": "lien" |
'lien' at $.subPlots[0].series[0].type is not a chart type this server lists — did you mean 'line'? |
"type": "Line" |
the same message, with 'line' as the suggestion; the serializer's lookup is case-sensitive |
"x": [...] |
Unknown field 'x' at $.subPlots[0].series[0]. describe_chart_schema lists the fields a spec accepts. |
"scale": "logarithmic" |
'logarithmic' … is not an accepted value; accepted: Linear, Log, SymLog, Logit, Date. |
"color": "reddish" |
'reddish' … is not a colour the library knows: use a CSS4 colour name or #RRGGBB. |
xData of 3, yData of 1 |
The 'line' series at $.subPlots[0].series[0] was refused: Array lengths must match. Got 3 and 1. |
a surface of 2 rows over 3 yData and 3 xData
|
The 'surface' series at $.subPlots[0].series[0] was refused: Array lengths must match. The values have 2 rows and 3 columns; the axes give 3 y and 3 x values. |
"type": "lien" on a series of a left axis past the primary one |
'lien' at $.subPlots[0].leftYAxes[1].series[0].type is not a chart type this server lists — did you mean 'line'? |
"leftYAxes": [null], or null in any other list of objects |
The entry at $.subPlots[0].leftYAxes[0] is null; it must be an object. |
no width
|
rendered at the library default, 800×600 |
"width": 16000 |
'width' must be between 1 and 4000 … the picture goes into a context window. |
"dpi": 600 on an 800×600 spec |
'dpi' 600 draws the picture 5000 by 3750 pixels (width and height times dpi / 96); the ceiling is 4000 by 4000 … |
The check covers every axis and every series of a subplot, not only the first two. A subplot holds its Y axes past the
primary one as lists: extraRightYAxes for the right axes past the first, leftYAxes for the left axes past the
primary, each outward from the plot, and rightYAxesOverflow and leftYAxesOverflow, which continue them in the same
order for a chart with more axes than 1.23.0 allowed. The primary axes, those four lists, the top axis, the Z axis and
the series of each are all seats, and every seat is checked the way the primary one is: a chart type that does not
exist, a misspelled scale or a label over 512 characters is refused wherever it stands, and the refusal names the seat
by its path. Before, such a spec was refused on the primary axes and silently accepted on a left axis, on a right axis
past the first, on a top-axis series and on a Z axis: the chart rendered without that series, or on a linear axis. A
null entry in any list of objects of a spec (series, Y axes, subplots, insets, annotations, reference lines, spans,
trendlines, levels, breaks) is refused with its path, instead of failing without a name. describe_chart_schema lists
the axis seats and the series seats, and explains the fields of a Y axis entry and yAxisTitleGap, the gap in pixels
between each Y axis title and its tick labels, 4 when absent.
Whether a series fits its own data (arrays that pair, a grid with a row for each y value and a column for each x value, a
count of at least one) is the library's rule and not the server's: the server builds the series with the library, on a
scratch axes, and names the place it stands with the library's own words, so a rule the library gains is a rule here too.
A stacked-area spec (xData and the layers, no yData) is accepted, and a signal given xData alone is read as the empty
signal it is.
The server carries MatPlotLibNet.Geo, so a map is a chart type of a spec: a geo_polygon series whose packageData names
the projection and the features, as the figure JSON of a map is written. The projection goes by its name, with its numbers by
their PROJ names when it takes any ({"name": "Orthographic", "parameters": {"lat_0": 50, "lon_0": 10}}); the features are a
built-in Natural Earth set by source (ne_110m_admin_0_countries, ne_110m_coastline, ne_110m_admin_0_boundary_lines_land) or a
GeoJSON FeatureCollection of
your own as features, whose properties are kept as written. A projection, a source or a number the package does not know is
refused with its place and the names it accepts, where the library's reader would leave the map out and draw a blank picture,
and describe_chart_schema for geo_polygon lists them. The JSON a map figure writes in code is a spec the server takes.
A spec's dpi sizes the PNG it renders, as WithDpi does in code: 800×600 at 192 dpi is a 1600×1200 PNG with the same
layout. SVG and PDF ignore it.
Colour names go through the library's own CSS4 table, and #f00 is expanded, so a model may write "red",
"CornflowerBlue" or #6495ED.
render_chart returns two blocks: the PNG, and a summary of what was drawn.
"Revenue" — 800×600, 1 subplot, 1 series
· line "2026", 4 points, x 1…4, y 12…22
The ranges come from the same ComputeDataRange call the renderer makes to place the axes, so the text and the
picture always agree. When a count does not apply, it is left out rather than guessed: a pie has slices, not
points.
chart_data_table gives the model the values themselves, which it cannot get from the PNG. A model can see that a
line rises, but it cannot read the value 18.4 from the picture. The tool returns the figure's own data tables as
markdown, one table per group of series that share an x, captioned with the chart's name:
**Revenue**
| Quarter | 2026 |
| --- | --- |
| 1 | 12 |
| 2 | 18 |
| 3 | 15 |
The tables are the same figure.ToDataTables() output that every other host serves, so the numbers a model reads
and the table a screen reader reads are the same data. The same tables come back a second time beside the markdown, as
structured content with an output schema, so a model that wants to add a column up does not have to parse a pipe
table back into numbers first:
{
"tables": [
{
"caption": "Revenue",
"columns": [
{ "header": "Quarter", "kind": "number", "axis": "x" },
{ "header": "2026", "kind": "number", "axis": "y" }
],
"rows": [[1, 12], [2, 18], [3, 15]]
}
]
}A column says what it holds — number, date or text — and which axis its values are positions on. The two
forms differ deliberately in one place: markdown is for reading, so a date is spelled the way a person reads it,
while the structured form writes it out in full as 2026-09-12T12:00:00.000, which sorts correctly as text. A chart with more rows than the server's MaxTableRows
ceiling is refused, because a table is text and text takes up the model's context. The message gives the row
count, the ceiling and the way around it: call save_chart, then read the file.
The SVG this server writes carries glyph outlines, not <text>. The PNG backend is loaded in the same
process, and it installs a glyph-path provider, so text is drawn with the library's own embedded font everywhere.
The SVG is self-contained and identical to the PNG, but the text in it is not machine-readable.
Every chart type is available through the spec. sankey, sunburst, treemap, polarbar, polarline,
polarscatter, treegrid and dendrogram used to have a JSON reader that built a fixed placeholder instead of
reading the document, and were refused by name for it; each now reads its own document back, and list_chart_types
lists all of them like any other type.
See also: Package Map · Getting Started · the same page in the cookbook
MatPlotLibNet 1.30.0
- Home
- Getting Started
- Fluent Cheatsheet
- Examples — each release in code
- Migrating to 1.30.0 — what was removed and what takes its place
-
Package Map
- MatPlotLibNet — the core package
- Chart Types
- Styling
- Advanced
- Streaming
- Bidirectional SignalR
- Interactive Controls
- MCP Server
- Verso
- Notebooks
- Accessibility
- International Text
- Benchmarks
- Roadmap
- Contributing
On the docs site
- Playground — try a chart in the browser
- Cookbook — copy-paste code with its picture
- API reference — every public type and member