@hoagsmedia/frugr-mcp 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +3 -3
  2. package/index.mjs +97 -11
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Preferred npm name for the frugr **read-only** MCP stdio bridge.
4
4
 
5
- This package is identical to [`@hoagsmedia/frgur-mcp-server`](https://www.npmjs.com/package/@hoagsmedia/frgur-mcp-server) v0.2.0 — same `index.mjs`, same env vars (`FRGUR_API_TOKEN`, `FRGUR_API_URL`). The legacy `frgur` spelling remains for backward compatibility.
5
+ This package is identical to [`@hoagsmedia/frgur-mcp-server`](https://www.npmjs.com/package/@hoagsmedia/frgur-mcp-server) v0.3.0 — same `index.mjs`, same env vars (`FRGUR_API_TOKEN`, `FRGUR_API_URL`). The legacy `frgur` spelling remains for backward compatibility.
6
6
 
7
7
  Full setup, tool list, and security notes: [mcp-server README on GitHub](https://github.com/hoagsmedia/frugr/blob/main/mcp-server/README.md) or the [`frgur-mcp-server` npm page](https://www.npmjs.com/package/@hoagsmedia/frgur-mcp-server).
8
8
 
@@ -11,9 +11,9 @@ Full setup, tool list, and security notes: [mcp-server README on GitHub](https:/
11
11
  "mcpServers": {
12
12
  "frugr": {
13
13
  "command": "npx",
14
- "args": ["-y", "@hoagsmedia/frugr-mcp@0.2.0"],
14
+ "args": ["-y", "@hoagsmedia/frugr-mcp@0.3.0"],
15
15
  "env": {
16
- "FRGUR_API_URL": "https://app.frgur.com",
16
+ "FRGUR_API_URL": "https://frugr.app",
17
17
  "FRGUR_API_TOKEN": "frgur_pat_your_token_here"
18
18
  }
19
19
  }
package/index.mjs CHANGED
@@ -1,26 +1,31 @@
1
1
  #!/usr/bin/env node
2
- // @hoagsmedia/frgur-mcp-server — a thin, READ-ONLY MCP bridge to your frugr books.
2
+ // @hoagsmedia/frgur-mcp-server — a thin MCP bridge to your frugr books.
3
3
  //
4
4
  // It exposes frugr's books tools over stdio (for Cursor / Claude Desktop /
5
5
  // Claude Code / ChatGPT) and forwards every call to the frugr API using your
6
- // Personal Access Token. The bridge holds no credentials of its own, runs your
7
- // own AI client's model (not frugr's), and can only read it never writes.
6
+ // Personal Access Token. The bridge holds no credentials of its own and runs
7
+ // your own AI client's model (not frugr's). Most tools READ your books; the
8
+ // "propose" tools (incl. receipt import) only ever stage suggestions into
9
+ // frugr's Needs Review queue — nothing writes to your ledger without your
10
+ // approval in the app.
8
11
  //
9
12
  // Config (env):
10
13
  // FRGUR_API_TOKEN required — a token from frugr → Settings → External AI apps
11
- // FRGUR_API_URL optional — your frugr origin (default https://app.frgur.com)
14
+ // FRGUR_API_URL optional — your frugr origin (default https://frugr.app)
12
15
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
13
16
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
14
17
  import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
15
- import { readFileSync } from 'node:fs';
16
- import { dirname, join } from 'node:path';
18
+ import { readFileSync, statSync } from 'node:fs';
19
+ import { readFile } from 'node:fs/promises';
20
+ import { homedir } from 'node:os';
21
+ import { basename, dirname, extname, join, resolve } from 'node:path';
17
22
  import { fileURLToPath } from 'node:url';
18
23
 
19
24
  const PKG = JSON.parse(
20
25
  readFileSync(join(dirname(fileURLToPath(import.meta.url)), 'package.json'), 'utf8')
21
26
  );
22
27
 
23
- const API_URL = (process.env.FRGUR_API_URL ?? 'https://app.frgur.com').replace(/\/+$/, '');
28
+ const API_URL = (process.env.FRGUR_API_URL ?? 'https://frugr.app').replace(/\/+$/, '');
24
29
  const API_TOKEN = process.env.FRGUR_API_TOKEN ?? '';
25
30
  const ENDPOINT = `${API_URL}/api/mcp`;
26
31
 
@@ -57,21 +62,102 @@ async function call(method, params) {
57
62
  return data;
58
63
  }
59
64
 
65
+ // --- Local file bridge for receipt import (v0.3.0) --------------------------
66
+ // Claude Desktop can't turn a chat attachment into base64, but this bridge runs
67
+ // on the user's machine and can read files. `import_receipt_file` is a
68
+ // CLIENT-SIDE tool: it reads the path locally and forwards the bytes to the
69
+ // server's `propose_expense_from_receipt`.
70
+ const RECEIPT_MAX_BYTES = 3 * 1024 * 1024;
71
+ const RECEIPT_MIME_BY_EXT = {
72
+ '.pdf': 'application/pdf',
73
+ '.jpg': 'image/jpeg',
74
+ '.jpeg': 'image/jpeg',
75
+ '.png': 'image/png',
76
+ '.webp': 'image/webp',
77
+ '.gif': 'image/gif',
78
+ '.heic': 'image/heic'
79
+ };
80
+
81
+ export function expandPath(p) {
82
+ const raw = String(p ?? '').trim();
83
+ if (!raw) return '';
84
+ const expanded = raw === '~' ? homedir() : raw.replace(/^~(?=\/|\\)/, homedir());
85
+ return resolve(expanded);
86
+ }
87
+
88
+ export function mimeFromExtension(filePath) {
89
+ return RECEIPT_MIME_BY_EXT[extname(filePath).toLowerCase()] ?? null;
90
+ }
91
+
92
+ const IMPORT_RECEIPT_TOOL = {
93
+ name: 'import_receipt_file',
94
+ description:
95
+ 'Import a receipt from a file on THIS computer (e.g. ~/Downloads/receipt.pdf). Reads the ' +
96
+ 'file locally and proposes it to frugr, which files it in the Needs Review queue for your ' +
97
+ 'approval. Max 3 MB; PDF, JPEG, PNG, WebP, GIF, or HEIC.',
98
+ inputSchema: {
99
+ type: 'object',
100
+ properties: {
101
+ filePath: {
102
+ type: 'string',
103
+ description: 'Absolute or ~-relative path to the receipt file on this machine.'
104
+ }
105
+ },
106
+ required: ['filePath']
107
+ }
108
+ };
109
+
110
+ async function importReceiptFile(args) {
111
+ const filePath = expandPath(args?.filePath);
112
+ if (!filePath) return { error: 'filePath is required.' };
113
+
114
+ let stat;
115
+ try {
116
+ stat = statSync(filePath);
117
+ } catch {
118
+ return { error: `No file found at ${filePath}.` };
119
+ }
120
+ if (!stat.isFile()) return { error: `${filePath} is not a file.` };
121
+ if (stat.size > RECEIPT_MAX_BYTES) {
122
+ return {
123
+ error: `That file is larger than the 3 MB limit (${Math.round(stat.size / 1024)} KB).`
124
+ };
125
+ }
126
+
127
+ const mimeType = mimeFromExtension(filePath);
128
+ if (!mimeType) {
129
+ return { error: 'Unsupported file type. Use a PDF, JPEG, PNG, WebP, GIF, or HEIC receipt.' };
130
+ }
131
+
132
+ const data = await readFile(filePath);
133
+ return call('tools/call', {
134
+ name: 'propose_expense_from_receipt',
135
+ arguments: { filename: basename(filePath), mimeType, dataBase64: data.toString('base64') }
136
+ });
137
+ }
138
+
60
139
  const server = new Server(
61
140
  { name: 'frgur-books', version: PKG.version },
62
141
  { capabilities: { tools: {} } }
63
142
  );
64
143
 
65
144
  // Tool list comes straight from frugr, so adding a tool server-side surfaces it
66
- // to every client with no package update.
145
+ // to every client with no package update. The local file bridge is appended
146
+ // only when the server actually offers receipt import (keeps old servers safe).
67
147
  server.setRequestHandler(ListToolsRequestSchema, async () => {
68
148
  const { tools } = await call('tools/list');
69
- return { tools: tools ?? [] };
149
+ const list = tools ?? [];
150
+ const hasReceiptImport = list.some((t) => t.name === 'propose_expense_from_receipt');
151
+ return { tools: hasReceiptImport ? [...list, IMPORT_RECEIPT_TOOL] : list };
70
152
  });
71
153
 
72
154
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
73
155
  const { name, arguments: args } = request.params;
74
- const result = await call('tools/call', { name, arguments: args ?? {} });
156
+ // Intercept the client-side file tool before forwarding.
157
+ const result =
158
+ name === 'import_receipt_file'
159
+ ? await importReceiptFile(args ?? {})
160
+ : await call('tools/call', { name, arguments: args ?? {} });
75
161
  // frugr already returns an MCP CallTool result ({ content, isError }); pass it
76
162
  // through, falling back to stringifying anything unexpected.
77
163
  return {
@@ -81,4 +167,4 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
81
167
  });
82
168
 
83
169
  await server.connect(new StdioServerTransport());
84
- logErr(`connected to ${API_URL} — read-only books tools available.`);
170
+ logErr(`connected to ${API_URL} — books tools available (reads + review-queue proposals).`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hoagsmedia/frugr-mcp",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Read-only MCP bridge to your frugr books (12 tools). Preferred npm name — alias of @hoagsmedia/frgur-mcp-server.",
5
5
  "type": "module",
6
6
  "bin": {