Inspiration
A small shop with several suppliers has the same product on several price lists. Each factory uses its own item codes, pack sizes, currency and delivery terms. The lists arrive as spreadsheets and are replaced every few months. An ordinary question then takes manual work across all of them:
- Which supplier is cheapest for 500 units?
- Which products depend on one supplier?
- What got more expensive since the previous list?
- What does a customer need to tile a 6 m² bathroom, and what does it cost?
I am a backend and integrations developer in Latvia. These questions are about connections between records, not about rows in one table. Relate made the idea practical: a graph database that runs inside the Python process, with no server to install. So I modelled the price lists of a home repair shop as a graph and put an MCP server in front of it.
The shop, the four factories and every price are invented for the demo.
What it does
liepa-relate is an MCP server with nine tools in two roles:
- Public role, six tools: search products, look one up, find alternatives, find what goes with a product, list repair jobs, and work out the materials and retail cost of a job.
- Owner role, three more tools: compare supplier offers by landed cost, list single-source products, and list price changes between lists.
The graph has two sides. Suppliers, price lists and offers are confidential. Products, categories and jobs are public. One relationship type, IS_FOR, crosses from an offer to a product. A customer query that never follows IS_FOR cannot reach a purchase price.
How I built it
I built it in four steps with an AI coding assistant, one prompt at a time and one commit per prompt. All prompts are in docs/prompts/, so the build can be followed and repeated.
- Sample data. A catalogue of 64 products and 6 repair jobs, and eight raw price lists. Each list looks the way its supplier would send it: one uses semicolons and yuan per carton, one has two title lines above the header, one writes prices with a dollar sign.
- The Relate store. A loader builds the whole graph in one transaction: 372 nodes and 868 relationships in a single
.rlfile. The file is committed, so judges can open it without building anything. - The MCP server. Each question is one Cypher file in
queries/. The tools hold no Cypher. They run the queries by name. - Test questions. 30 questions with known answers, put to an assistant that saw only the tools.
Suppliers quote in different currencies and on different delivery terms, so the server compares landed cost in euros:
$$ C = \frac{p}{u} \cdot r \cdot \left(1 + \frac{f}{100}\right) \cdot \left(1 + \frac{d}{100}\right) $$
Here \(p\) is the supplier's unit price, \(u\) the number of shop units in one supplier unit, \(r\) the exchange rate to euros, \(f\) the freight percentage and \(d\) the duty percentage. The demo uses fixed rates, and every result states them.
Challenges I ran into
- Latvian search. A customer types "deli" and the catalogue says "dēlis". No analyzer stemmed Latvian words in my tests, and the
latviananalyzer gave the same results as the default. The fix: thestandard-foldinganalyzer removes diacritics, the server adds*to each word, and the tool description tells the assistant to send a stem. - Money in floats. Relate has no decimal type. A job needs \(q = \lceil a + b \cdot s \rceil\) units, with a fixed part \(a\), a part \(b\) per m² and the size \(s\). In floats \(1.1 \cdot 50\) is 55.00000000000001, which rounds up to 56 units where 55 are enough. The queries round to eight decimals first.
- One file, one writer. A
.rlfile cannot be read while a writer has it open. The loader and the server never run at the same time, and the server opens the store read-only. - Tool descriptions. In the blind run the assistant searched for "nails" and found nothing, because the catalogue says "Wire nail". The description had explained stems for Latvian words only. I changed the description, not the code.
What I learned
- A relationship type can be a security boundary. The public role has no tool that reads the supplier side, and a script checks every customer tool for leaked supplier names, item codes and prices.
- Shaped tools beat a general query tool. "What do I need to tile 6 m²?" is one call of
materials_for_job. With a general Cypher tool the model writes the query each time, and it can followIS_FORto what the shop pays. - Test the database before designing on it. A smoke script found one wrong assumption of mine and three places where Relate 1.5.0 differs from its documentation. They are recorded in
docs/relate-notes.md. - A full score proves little. Both roles answered all their questions correctly: 21 of 21 and 9 of 9. That is one model, one run per role, scored by the same model.
docs/eval-results.mdlists these limits next to the numbers.
What's next
- A blind run with another model and another client.
- Streamable HTTP with OAuth, so that a caller is identified. Today the boundary is separation by process, not authentication.
- Real price lists. Text from an outside supplier has to be reviewed before it reaches a model.
How do you keep purchase prices away from a customer-facing assistant: two separate stores, or a boundary inside one graph?