feat(mcp): currency param on create_article and update_article (#1184)

Fixes #1168. articles.currency exists in the DB and REST API, but the
staged-operation schemas and the two MCP tools had no currency param,
so agent-created articles were always SEK and an agent asked to create
an EUR-priced article could not.

- CreateArticleParamsSchema/UpdateArticleParamsSchema accept an
  optional ISO 4217 code (normalized to upper case; empty/null =
  unset). The currencies-table FK stays the allow-list: a 23503 on the
  currency FK maps to a clear 400 instead of a raw 500.
- commitCreateArticle inserts currency ?? 'SEK'; the sparse update
  executor passes it through only when staged.
- gnubok_create_article / gnubok_update_article expose the param.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Jakob Wennberg
2026-07-25 12:59:32 +02:00
committed by GitHub
co-authored by Claude Fable 5
parent 36a1df4f6b
commit d012d40b18
4 changed files with 62 additions and 2 deletions
+12 -1
View File
@@ -488,6 +488,7 @@ async function commitCreateArticle(
type: validated.type,
unit: validated.unit ?? 'st',
price_excl_vat: validated.price_excl_vat,
currency: validated.currency ?? 'SEK',
vat_rate: validated.vat_rate,
revenue_account: validated.revenue_account ?? null,
cost_price: validated.cost_price ?? null,
@@ -499,7 +500,13 @@ async function commitCreateArticle(
.select()
.single()
if (error) return { error: error.message, status: 500 }
if (error) {
// FK to public.currencies: the reference table is the allow-list.
if (error.code === '23503' && error.message.includes('currency')) {
return { error: `Currency ${validated.currency} is not supported`, status: 400 }
}
return { error: error.message, status: 500 }
}
if (!data.article_number) {
try {
@@ -552,6 +559,10 @@ async function commitUpdateArticle(
if (error) {
if (error.code === 'PGRST116') return { error: 'Article not found', status: 404 }
// FK to public.currencies: the reference table is the allow-list.
if (error.code === '23503' && error.message.includes('currency')) {
return { error: `Currency ${validated.currency} is not supported`, status: 400 }
}
return { error: error.message, status: 500 }
}