feat(api): expose bank-connection freshness in MCP and v1 REST (#2124)

* feat(api): expose bank-connection freshness in MCP and v1 REST

gnubok_connect_bank now returns last_synced_at, consent_expires and
error_message per connection, and its instructions tell the agent to
flag stale or expiring connections. New read-only endpoint
GET /api/v1/companies/{companyId}/bank-connections exposes the same
fields to API-key integrations (scope companies:read).

Background: a user's PSD2 feed died silently in July; bookkeeping
looked complete while three weeks stale, and nothing on the API/MCP
surface could reveal it. Sync stays cron-driven; an agent-triggerable
sync was considered and deferred (see DECISIONS.md).

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01USJHnxsindrs9X6zqQDLix

* fix(api): address skeptic findings on bank-connection freshness

- Map the bank-connections group into skills/accounted-api (apiskill:check
  crashed on the unmapped group; regenerated skill files included).
- Gate the v1 route on the bank_sync capability, mirroring the MCP twin:
  a lapsed entitlement now answers with a capability error instead of
  status=active with a frozen last_synced_at.
- Reword MCP instructions + v1 pitfalls: null last_synced_at right after
  connecting is normal, staleness threshold aligned to the UI's 36 hours,
  and re-authorisation is only advised for expired/error/consent-out, not
  for stale-but-active connections (lapsed subscription or deselected
  accounts are the usual causes there).

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01USJHnxsindrs9X6zqQDLix

* fix(mcp): keep gnubok_connect_bank schema under the tools/list token ceiling

The enriched outputSchema plus the worked examples that landed on main
(#2100) pushed the projected tools/list payload 20 tokens over the
61.6K context-budget ceiling. Drop the per-property descriptions from
the new freshness fields; the instructions string (runtime output, not
catalog payload) already explains them.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01USJHnxsindrs9X6zqQDLix

---------

Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
Mattsson
2026-09-01 20:54:55 +02:00
committed by GitHub
co-authored by Claude Fable 5.1
parent a08bf51ced
commit b56da5d6c5
11 changed files with 453 additions and 14 deletions
@@ -86,15 +86,52 @@ describe('onboarding connect-link tools', () => {
expect(named.instructions).not.toContain('BETTER LINK AVAILABLE')
})
it('bank: reports an active connection', async () => {
it('bank: reports an active connection with freshness fields', async () => {
const { from } = listClient([
{ id: 'c1', bank_name: 'Swedbank', status: 'active', created_at: '2026-08-01T00:00:00Z' },
{
id: 'c1',
bank_name: 'Swedbank',
status: 'active',
created_at: '2026-08-01T00:00:00Z',
last_synced_at: '2026-08-30T05:00:00Z',
consent_expires: '2026-11-01T00:00:00Z',
error_message: null,
},
])
const result = (await bankTool.execute({}, COMPANY_ID, 'user-1', { from } as never)) as Record<string, unknown>
expect(result.connected).toBe(true)
expect(result.connections).toEqual([
{ connection_id: 'c1', bank: 'Swedbank', status: 'active', since: '2026-08-01T00:00:00Z' },
{
connection_id: 'c1',
bank: 'Swedbank',
status: 'active',
since: '2026-08-01T00:00:00Z',
last_synced_at: '2026-08-30T05:00:00Z',
consent_expires: '2026-11-01T00:00:00Z',
error_message: null,
},
])
expect(result.instructions).toContain('last_synced_at')
})
it('bank: surfaces the error_message and null sync stamp on a dead connection', async () => {
const { from } = listClient([
{
id: 'c2',
bank_name: 'SEB',
status: 'expired',
created_at: '2026-05-01T00:00:00Z',
last_synced_at: null,
consent_expires: '2026-07-15T00:00:00Z',
error_message: 'Bankkopplingen behöver förnyas.',
},
])
const result = (await bankTool.execute({}, COMPANY_ID, 'user-1', { from } as never)) as Record<string, unknown>
expect(result.connected).toBe(false)
const rows = result.connections as Array<Record<string, unknown>>
expect(rows[0].last_synced_at).toBeNull()
expect(rows[0].consent_expires).toBe('2026-07-15T00:00:00Z')
expect(rows[0].error_message).toBe('Bankkopplingen behöver förnyas.')
})
it('skatteverket: hands out the authorize link when enabled and not connected', async () => {
File diff suppressed because one or more lines are too long