@expensebot/mcp-server-auth 0.6.8 → 0.6.9
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.
- package/package.json +1 -1
- package/src/client.js +32 -1
- package/src/index.js +4 -1
- package/src/test.js +17 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expensebot/mcp-server-auth",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9",
|
|
4
4
|
"mcpName": "io.github.TotesMagotes/mcp-server-auth",
|
|
5
5
|
"description": "Authenticated MCP server for ExpenseBot — lets Claude Desktop, Cursor, and other AI assistants search your expenses, create reports, and analyze spending using your actual ExpenseBot data.",
|
|
6
6
|
"bin": {
|
package/src/client.js
CHANGED
|
@@ -7,6 +7,32 @@ const DEFAULT_BASE = "https://www.expensebot.ai";
|
|
|
7
7
|
const POLL_INTERVAL_MS = 3000;
|
|
8
8
|
const POLL_TIMEOUT_MS = 60000;
|
|
9
9
|
|
|
10
|
+
async function readStructuredHttpError(res) {
|
|
11
|
+
const text = await res.text().catch(() => "");
|
|
12
|
+
let body = null;
|
|
13
|
+
try {
|
|
14
|
+
body = text ? JSON.parse(text) : null;
|
|
15
|
+
} catch (_) {}
|
|
16
|
+
const nested = body?.error;
|
|
17
|
+
const message =
|
|
18
|
+
(typeof nested === "string" && nested) ||
|
|
19
|
+
nested?.message ||
|
|
20
|
+
body?.message ||
|
|
21
|
+
`API error ${res.status}`;
|
|
22
|
+
const details = {};
|
|
23
|
+
if (Array.isArray(body?.rejected)) details.rejected = body.rejected;
|
|
24
|
+
if (Array.isArray(body?.accepted)) details.accepted = body.accepted;
|
|
25
|
+
return {
|
|
26
|
+
success: false,
|
|
27
|
+
error: {
|
|
28
|
+
code: body?.code || nested?.code || `http_${res.status}`,
|
|
29
|
+
message,
|
|
30
|
+
...(nested?.hint ? { hint: nested.hint } : {}),
|
|
31
|
+
...(Object.keys(details).length ? { details } : {}),
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
10
36
|
export class ExpenseBotClient {
|
|
11
37
|
constructor(token, baseUrl) {
|
|
12
38
|
this.token = token;
|
|
@@ -20,7 +46,7 @@ export class ExpenseBotClient {
|
|
|
20
46
|
headers: {
|
|
21
47
|
Authorization: `Bearer ${this.token}`,
|
|
22
48
|
"Content-Type": "application/json",
|
|
23
|
-
"User-Agent": "expensebot-mcp-auth/0.6.
|
|
49
|
+
"User-Agent": "expensebot-mcp-auth/0.6.9",
|
|
24
50
|
"X-ExpenseBot-MCP-Transport": "stdio",
|
|
25
51
|
...options.headers,
|
|
26
52
|
},
|
|
@@ -39,6 +65,9 @@ export class ExpenseBotClient {
|
|
|
39
65
|
);
|
|
40
66
|
}
|
|
41
67
|
if (!res.ok) {
|
|
68
|
+
if (path === "/api/mcp/execute") {
|
|
69
|
+
return readStructuredHttpError(res);
|
|
70
|
+
}
|
|
42
71
|
const text = await res.text().catch(() => "");
|
|
43
72
|
throw new Error(`API error ${res.status}: ${text.substring(0, 200)}`);
|
|
44
73
|
}
|
|
@@ -98,3 +127,5 @@ export class ExpenseBotClient {
|
|
|
98
127
|
};
|
|
99
128
|
}
|
|
100
129
|
}
|
|
130
|
+
|
|
131
|
+
export { readStructuredHttpError };
|
package/src/index.js
CHANGED
|
@@ -1859,6 +1859,9 @@ function formatResult(result) {
|
|
|
1859
1859
|
if (err && typeof err === "object" && err.message) {
|
|
1860
1860
|
errText = `Error (${err.code || "unknown"}): ${err.message}`;
|
|
1861
1861
|
if (err.hint) errText += `\n\nHint: ${err.hint}`;
|
|
1862
|
+
if (err.details) {
|
|
1863
|
+
errText += `\n\nDetails:\n${JSON.stringify(err.details, null, 2)}`;
|
|
1864
|
+
}
|
|
1862
1865
|
} else if (typeof err === "string") {
|
|
1863
1866
|
errText = `Error: ${err}`;
|
|
1864
1867
|
} else {
|
|
@@ -1907,7 +1910,7 @@ function formatResult(result) {
|
|
|
1907
1910
|
|
|
1908
1911
|
async function main() {
|
|
1909
1912
|
const server = new Server(
|
|
1910
|
-
{ name: "expensebot-auth", version: "0.6.
|
|
1913
|
+
{ name: "expensebot-auth", version: "0.6.9" },
|
|
1911
1914
|
{ capabilities: { tools: {} }, instructions: SERVER_INSTRUCTIONS }
|
|
1912
1915
|
);
|
|
1913
1916
|
|
package/src/test.js
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
import { spawn } from "node:child_process";
|
|
18
18
|
import { fileURLToPath } from "node:url";
|
|
19
19
|
import path from "node:path";
|
|
20
|
+
import { readStructuredHttpError } from "./client.js";
|
|
20
21
|
|
|
21
22
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
22
23
|
const SERVER_PATH = path.join(__dirname, "index.js");
|
|
@@ -163,6 +164,22 @@ function check(label, ok, details = "") {
|
|
|
163
164
|
|
|
164
165
|
(async () => {
|
|
165
166
|
console.log("=== mcp-server-auth smoke test ===\n");
|
|
167
|
+
const structuredFailure = await readStructuredHttpError(
|
|
168
|
+
new Response(
|
|
169
|
+
JSON.stringify({
|
|
170
|
+
code: "upload_validation_failed",
|
|
171
|
+
error: "One file could not be accepted.",
|
|
172
|
+
rejected: [{ id: "2", code: "upload_unreadable", retryable: true }],
|
|
173
|
+
}),
|
|
174
|
+
{ status: 502, headers: { "Content-Type": "application/json" } }
|
|
175
|
+
)
|
|
176
|
+
);
|
|
177
|
+
check(
|
|
178
|
+
"structured upload failures preserve each concise per-file reason",
|
|
179
|
+
structuredFailure.error.code === "upload_validation_failed" &&
|
|
180
|
+
structuredFailure.error.details.rejected[0].code === "upload_unreadable" &&
|
|
181
|
+
structuredFailure.error.details.rejected[0].id === "2"
|
|
182
|
+
);
|
|
166
183
|
const responses = await runServer();
|
|
167
184
|
const byId = new Map(
|
|
168
185
|
responses.filter((r) => r.id != null).map((r) => [r.id, r])
|