<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: leviyi</title>
    <description>The latest articles on DEV Community by leviyi (@leviyi).</description>
    <link>https://dev.to/leviyi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4058377%2F6d12556a-1ac2-45bd-9168-f9e501e6bc19.png</url>
      <title>DEV Community: leviyi</title>
      <link>https://dev.to/leviyi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/leviyi"/>
    <language>en</language>
    <item>
      <title>I open-sourced a deterministic crochet chart engine — no AI hallucinations, plus an MCP server so agents can use it</title>
      <dc:creator>leviyi</dc:creator>
      <pubDate>Mon, 10 Aug 2026 15:43:26 +0000</pubDate>
      <link>https://dev.to/leviyi/i-open-sourced-a-deterministic-crochet-chart-engine-no-ai-hallucinations-plus-an-mcp-server-so-3a0k</link>
      <guid>https://dev.to/leviyi/i-open-sourced-a-deterministic-crochet-chart-engine-no-ai-hallucinations-plus-an-mcp-server-so-3a0k</guid>
      <description>&lt;p&gt;A crochet chart is a grid. Each cell is one stitch, each color is a yarn, and if row 14 says "7 blue, 3 white" then row 14 has exactly ten stitches — not eleven, never "approximately ten."&lt;/p&gt;

&lt;p&gt;That property is exactly why AI image generators are useless at making them. Ask a diffusion model for a "crochet chart of a frog" and you get something that &lt;em&gt;looks&lt;/em&gt; like a chart: wavy grid lines, cells that change size mid-row, a legend with nine colors and a frog made of eleven. Pretty. Unworkable. You can't crochet from a vibe.&lt;/p&gt;

&lt;p&gt;So the engine behind my crochet site is &lt;strong&gt;deterministic image processing&lt;/strong&gt;, and this week I open-sourced it: &lt;a href="https://github.com/dengyu123456/crochet-engine" rel="noopener noreferrer"&gt;&lt;code&gt;crochetpatterngen-engine&lt;/code&gt;&lt;/a&gt; — Python library, CLI, and MCP server. Same input, same chart, same stitch counts, every time.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it does
&lt;/h2&gt;

&lt;p&gt;Feed it a photo, get back a stitch-ready chart PNG plus exact per-color stitch counts that sum exactly to the grid size:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;PIL&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Image&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;crochet_chart_engine&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;generate_chart&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;estimate_yarn&lt;/span&gt;

&lt;span class="n"&gt;png_bytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;meta&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;generate_chart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;Image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;dog.jpg&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;technique&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;c2c&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;# graph | c2c | tapestry | mosaic | filet
&lt;/span&gt;    &lt;span class="n"&gt;grid_w&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;         &lt;span class="c1"&gt;# 20..120
&lt;/span&gt;    &lt;span class="n"&gt;n_colors&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;        &lt;span class="c1"&gt;# 2..16
&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# meta: {"grid_w", "grid_h", "colors": [{"hex", "count"}],
#        "total_stitches", "technique", "warning"}
&lt;/span&gt;
&lt;span class="n"&gt;yarn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;estimate_yarn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;worsted&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# per-color yardage, so you know how much yarn to buy before you start
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The pipeline is resize → median-cut color quantization → confetti cleanup (isolated single-stitch specks get absorbed into their neighbors, because nobody wants to change yarn for one stitch). Pillow + numpy, no heavy deps.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fun bug: C2C blankets come out squashed
&lt;/h2&gt;

&lt;p&gt;The most interesting problem wasn't color — it was geometry. Corner-to-corner (C2C) crochet blocks are physically &lt;strong&gt;wider than tall&lt;/strong&gt;, roughly a 0.7:1 height-to-width ratio. A square grid of C2C blocks does not produce a square piece of fabric.&lt;/p&gt;

&lt;p&gt;Every naive photo-to-chart converter gets this wrong: your dog photo comes out vertically stretched on the actual blanket, like a funhouse mirror. The engine corrects grid dimensions by the block aspect ratio, so the &lt;em&gt;worked piece&lt;/em&gt; keeps the photo's proportions instead of the chart's.&lt;/p&gt;

&lt;p&gt;It's a one-line insight and a week of testing. That's most of applied software, honestly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why an MCP server
&lt;/h2&gt;

&lt;p&gt;The same engine also ships as an &lt;a href="https://github.com/dengyu123456/crochet-engine#mcp-server-claude-desktop--friends" rel="noopener noreferrer"&gt;MCP server&lt;/a&gt;, so AI agents (Claude Desktop, Cursor, whatever comes next) can call it as a tool:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"mcpServers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"crochet"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"uvx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"args"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"--from"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"crochetpatterngen-engine[mcp]"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"crochetpatterngen-mcp"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three tools: &lt;code&gt;photo_to_chart&lt;/code&gt;, &lt;code&gt;render_ascii_design&lt;/code&gt;, &lt;code&gt;estimate_yarn_tool&lt;/code&gt;. The pitch: an agent that can say "here's your chart, 60×44, 8 colors, you'll need about 210 yards of the green" is doing something generative AI structurally can't — because the answer is &lt;em&gt;computed&lt;/em&gt;, not sampled.&lt;/p&gt;

&lt;p&gt;I think "deterministic tools behind an agent frontend" is an underrated pattern right now. Everyone is wrapping LLMs around fuzzy tasks; there's a lot of value in wrapping them around precise ones.&lt;/p&gt;

&lt;h2&gt;
  
  
  The ASCII design format is my favorite part
&lt;/h2&gt;

&lt;p&gt;Charts can also come from text files — one character per stitch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;palette&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;G=#58A05C, W=#FFFFFF, .=#FAFAF7&lt;/span&gt;
&lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Frog Face&lt;/span&gt;
&lt;span class="na"&gt;technique&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;graph&lt;/span&gt;
&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;span class="s"&gt;..GGGG..........GGGG....&lt;/span&gt;
&lt;span class="s"&gt;.GGWWGG........GGWWGG...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hand-draw designs in a text editor and git-diff my frogs. There's something deeply satisfying about version-controllable pixel art that becomes a physical object.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub&lt;/strong&gt;: &lt;a href="https://github.com/dengyu123456/crochet-engine" rel="noopener noreferrer"&gt;dengyu123456/crochet-engine&lt;/a&gt; — MIT, &lt;code&gt;pytest tests/&lt;/code&gt; passes, PRs welcome&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PyPI&lt;/strong&gt;: &lt;code&gt;pip install crochetpatterngen-engine&lt;/code&gt; (&lt;code&gt;[mcp]&lt;/code&gt; and &lt;code&gt;[rembg]&lt;/code&gt; extras)&lt;/li&gt;
&lt;li&gt;The hosted version with a free pattern library: &lt;a href="https://crochetpatterngen.com" rel="noopener noreferrer"&gt;crochetpatterngen.com&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you build something with it — graphgans, a knitting variant, a cross-stitch port — I'd genuinely love to hear about it. And if you've ever tried to crochet from an AI-generated "chart," I owe you a beer and an apology on behalf of the industry.&lt;/p&gt;

</description>
      <category>python</category>
      <category>opensource</category>
      <category>mcp</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
