@mindstone/mcp-server-xero 0.1.2 → 0.1.3
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/README.md +12 -5
- package/dist/auth/bridge.js +17 -0
- package/dist/auth/token-grant.js +194 -0
- package/dist/bridge-reader.js +167 -0
- package/dist/clients/xero-client.js +146 -14
- package/dist/clients/xero-scopes.js +8 -0
- package/dist/tools/sign-in.tool.js +82 -0
- package/dist/tools/tool-factory.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,11 +9,11 @@ This package is Mindstone's maintained build of Xero's community Xero MCP server
|
|
|
9
9
|
<!-- BEGIN INSTALL_LINKS: do not edit by hand; regenerated by scripts/gen-install-links.mjs -->
|
|
10
10
|
## One-click install
|
|
11
11
|
|
|
12
|
-
[](cursor://anysphere.cursor-deeplink/mcp/install?name=Xero&config=
|
|
13
|
-
[](vscode:mcp/install?%7B%22name%22%3A%22Xero%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40mindstone%2Fmcp-server-xero%22%5D%2C%22env%22%3A%7B%22XERO_CLIENT_ID%22%3A%22%22%2C%22XERO_CLIENT_SECRET%22%3A%22%22%2C%22XERO_CLIENT_BEARER_TOKEN%22%3A%22%22%7D%7D)
|
|
14
|
-
[](vscode-insiders:mcp/install?%7B%22name%22%3A%22Xero%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40mindstone%2Fmcp-server-xero%22%5D%2C%22env%22%3A%7B%22XERO_CLIENT_ID%22%3A%22%22%2C%22XERO_CLIENT_SECRET%22%3A%22%22%2C%22XERO_CLIENT_BEARER_TOKEN%22%3A%22%22%7D%7D)
|
|
12
|
+
[](cursor://anysphere.cursor-deeplink/mcp/install?name=Xero&config=eyJ0eXBlIjoic3RkaW8iLCJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBtaW5kc3RvbmUvbWNwLXNlcnZlci14ZXJvIl0sImVudiI6eyJYRVJPX0NMSUVOVF9JRCI6IiIsIlhFUk9fQ0xJRU5UX1NFQ1JFVCI6IiIsIlhFUk9fUkVGUkVTSF9UT0tFTiI6IiIsIlhFUk9fQ0xJRU5UX0JFQVJFUl9UT0tFTiI6IiJ9fQ)
|
|
13
|
+
[](vscode:mcp/install?%7B%22name%22%3A%22Xero%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40mindstone%2Fmcp-server-xero%22%5D%2C%22env%22%3A%7B%22XERO_CLIENT_ID%22%3A%22%22%2C%22XERO_CLIENT_SECRET%22%3A%22%22%2C%22XERO_REFRESH_TOKEN%22%3A%22%22%2C%22XERO_CLIENT_BEARER_TOKEN%22%3A%22%22%7D%7D)
|
|
14
|
+
[](vscode-insiders:mcp/install?%7B%22name%22%3A%22Xero%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40mindstone%2Fmcp-server-xero%22%5D%2C%22env%22%3A%7B%22XERO_CLIENT_ID%22%3A%22%22%2C%22XERO_CLIENT_SECRET%22%3A%22%22%2C%22XERO_REFRESH_TOKEN%22%3A%22%22%2C%22XERO_CLIENT_BEARER_TOKEN%22%3A%22%22%7D%7D)
|
|
15
15
|
|
|
16
|
-
After clicking the button, your host will prompt you to fill: `XERO_CLIENT_ID`, `XERO_CLIENT_SECRET`, `XERO_CLIENT_BEARER_TOKEN`.
|
|
16
|
+
After clicking the button, your host will prompt you to fill: `XERO_CLIENT_ID`, `XERO_CLIENT_SECRET`, `XERO_REFRESH_TOKEN`, `XERO_CLIENT_BEARER_TOKEN`.
|
|
17
17
|
|
|
18
18
|
<details>
|
|
19
19
|
<summary>Manual config for Claude Desktop / Claude Code / Goose / Continue.dev (Xero)</summary>
|
|
@@ -30,6 +30,7 @@ After clicking the button, your host will prompt you to fill: `XERO_CLIENT_ID`,
|
|
|
30
30
|
"env": {
|
|
31
31
|
"XERO_CLIENT_ID": "",
|
|
32
32
|
"XERO_CLIENT_SECRET": "",
|
|
33
|
+
"XERO_REFRESH_TOKEN": "",
|
|
33
34
|
"XERO_CLIENT_BEARER_TOKEN": ""
|
|
34
35
|
}
|
|
35
36
|
}
|
|
@@ -74,7 +75,7 @@ NOTE: To use Payroll-specific queries, the region should be either NZ or UK.
|
|
|
74
75
|
|
|
75
76
|
### Authentication
|
|
76
77
|
|
|
77
|
-
There are
|
|
78
|
+
There are 3 modes of authentication supported in the Xero MCP server. When more than one is set, the bearer token wins, then a saved sign-in (`XERO_REFRESH_TOKEN`), then a Custom Connection.
|
|
78
79
|
|
|
79
80
|
#### 1. Custom Connections
|
|
80
81
|
|
|
@@ -129,6 +130,12 @@ In this case, use the following configuration:
|
|
|
129
130
|
|
|
130
131
|
NOTE: The `XERO_CLIENT_BEARER_TOKEN` will take precedence over the `XERO_CLIENT_ID` if defined.
|
|
131
132
|
|
|
133
|
+
#### 3. Sign in with Xero (Web app)
|
|
134
|
+
|
|
135
|
+
A free Xero Web app (up to 5 companies) with the usual "Sign in with Xero" page instead of a Custom Connection. Set `XERO_CLIENT_ID` and `XERO_CLIENT_SECRET` to the Web app's keys and `XERO_REFRESH_TOKEN` to a refresh token from signing in with the scopes in [`XERO_SIGN_IN_SCOPES`](src/clients/xero-scopes.ts) (they include `offline_access`). The server renews the 30-minute access token itself; Xero hands back a new refresh token each time, which the server uses from then on.
|
|
136
|
+
|
|
137
|
+
In Rebel, the `xero_sign_in` tool does all of this: Rebel opens Xero's sign-in page, the person picks a company, and Rebel saves each new refresh token. Outside Rebel there is nowhere to save a renewed refresh token, so it lasts until the server restarts; a Custom Connection or bearer token suits that case better.
|
|
138
|
+
|
|
132
139
|
### Available MCP Commands
|
|
133
140
|
|
|
134
141
|
> **Tool naming:** this connector's tools use unprefixed dash-case names (e.g. `list-invoices`, `create-contact`), inherited from its fork lineage. Sibling connectors use prefixed snake_case names (e.g. `list_quickbooks_invoices`). In multi-server hosts, unprefixed generic names can collide with other servers' tools. Renaming would be a breaking change for existing configurations, so the names are kept as-is; if your host supports namespacing/aliasing, prefer enabling it for this server.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { postToBridge } from "../bridge-reader.js";
|
|
2
|
+
/** Ordinary per-call budget for a bridge request. */
|
|
3
|
+
export const BRIDGE_REQUEST_TIMEOUT_MS = 30_000;
|
|
4
|
+
/**
|
|
5
|
+
* Budget for a bridge call that waits while the person signs in to Xero in
|
|
6
|
+
* their browser. Matches the host's own 5-minute sign-in wait.
|
|
7
|
+
*/
|
|
8
|
+
export const BRIDGE_SIGN_IN_TIMEOUT_MS = 5 * 60 * 1000;
|
|
9
|
+
/** What the vendored reader answers when no host app runs this connector. */
|
|
10
|
+
export const BRIDGE_NOT_AVAILABLE = "Bridge not available";
|
|
11
|
+
/**
|
|
12
|
+
* POST to the host app bridge through the vendored hardened reader
|
|
13
|
+
* (`../bridge-reader.ts`, kept byte-identical to the test-harness copy).
|
|
14
|
+
* Its `error` and `warning` text comes back wrapped in an untrusted-content
|
|
15
|
+
* envelope; network failures and timeouts are thrown.
|
|
16
|
+
*/
|
|
17
|
+
export const bridgeRequest = (urlPath, body, timeoutMs = BRIDGE_REQUEST_TIMEOUT_MS) => postToBridge(urlPath, body, { connector: "xero", timeoutMs });
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Xero's OAuth 2.0 token endpoint, for the two grants this connector makes:
|
|
3
|
+
* client credentials (a Custom Connection) and refresh token (a Web app the
|
|
4
|
+
* person signed in to with "Sign in with Xero").
|
|
5
|
+
*
|
|
6
|
+
* Only the standard OAuth error code from a failed grant is ever used:
|
|
7
|
+
* `error_description` and other fields can echo what was sent.
|
|
8
|
+
*
|
|
9
|
+
* Both requests refuse redirects: fetch would otherwise resend the refresh
|
|
10
|
+
* token (in the body) or the access token (in the header) to wherever a
|
|
11
|
+
* redirect points. A redirect fails as a network error instead.
|
|
12
|
+
*/
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
export const XERO_TOKEN_URL = "https://identity.xero.com/connect/token";
|
|
15
|
+
export const XERO_CONNECTIONS_URL = "https://api.xero.com/connections";
|
|
16
|
+
const TOKEN_REQUEST_TIMEOUT_MS = 30_000;
|
|
17
|
+
/** The OAuth 2.0 error codes (RFC 6749 §5.2). */
|
|
18
|
+
const OAUTH_ERROR_CODES = [
|
|
19
|
+
"invalid_request",
|
|
20
|
+
"invalid_client",
|
|
21
|
+
"invalid_grant",
|
|
22
|
+
"unauthorized_client",
|
|
23
|
+
"unsupported_grant_type",
|
|
24
|
+
"invalid_scope",
|
|
25
|
+
];
|
|
26
|
+
function parseTokenResponse(data) {
|
|
27
|
+
const d = data;
|
|
28
|
+
if (typeof d?.access_token !== "string" || d.access_token.length === 0)
|
|
29
|
+
return null;
|
|
30
|
+
if (typeof d.expires_in !== "number" || !(d.expires_in > 0))
|
|
31
|
+
return null;
|
|
32
|
+
if (d.refresh_token !== undefined && (typeof d.refresh_token !== "string" || d.refresh_token.length === 0)) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
access_token: d.access_token,
|
|
37
|
+
expires_in: d.expires_in,
|
|
38
|
+
token_type: typeof d.token_type === "string" ? d.token_type : undefined,
|
|
39
|
+
refresh_token: d.refresh_token,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async function oauthErrorCode(response) {
|
|
43
|
+
let body;
|
|
44
|
+
try {
|
|
45
|
+
body = await response.json();
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
const error = body?.error;
|
|
51
|
+
return OAUTH_ERROR_CODES.find((code) => code === error);
|
|
52
|
+
}
|
|
53
|
+
/** One refresh-token grant. Holds no state; the caller adopts the result. */
|
|
54
|
+
export async function requestRefreshGrant(keys, refreshToken) {
|
|
55
|
+
const authHeader = "Basic " + Buffer.from(`${keys.clientId}:${keys.clientSecret}`).toString("base64");
|
|
56
|
+
let response;
|
|
57
|
+
try {
|
|
58
|
+
response = await fetch(XERO_TOKEN_URL, {
|
|
59
|
+
method: "POST",
|
|
60
|
+
redirect: "error",
|
|
61
|
+
signal: AbortSignal.timeout(TOKEN_REQUEST_TIMEOUT_MS),
|
|
62
|
+
headers: {
|
|
63
|
+
Authorization: authHeader,
|
|
64
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
65
|
+
Accept: "application/json",
|
|
66
|
+
},
|
|
67
|
+
body: new URLSearchParams({
|
|
68
|
+
grant_type: "refresh_token",
|
|
69
|
+
refresh_token: refreshToken,
|
|
70
|
+
}).toString(),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (error instanceof Error && error.name === "TimeoutError") {
|
|
75
|
+
return { ok: false, failure: { kind: "timeout" } };
|
|
76
|
+
}
|
|
77
|
+
return { ok: false, failure: { kind: "network" } };
|
|
78
|
+
}
|
|
79
|
+
if (!response.ok) {
|
|
80
|
+
return {
|
|
81
|
+
ok: false,
|
|
82
|
+
failure: { kind: "http", status: response.status, code: await oauthErrorCode(response) },
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
let data;
|
|
86
|
+
try {
|
|
87
|
+
data = await response.json();
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return { ok: false, failure: { kind: "malformed", status: response.status } };
|
|
91
|
+
}
|
|
92
|
+
const token = parseTokenResponse(data);
|
|
93
|
+
if (!token) {
|
|
94
|
+
return { ok: false, failure: { kind: "malformed", status: response.status } };
|
|
95
|
+
}
|
|
96
|
+
return { ok: true, token };
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Codes that signing in again cannot fix: the browser sign-in uses the same
|
|
100
|
+
* Client ID and Secret, and a malformed request stays malformed.
|
|
101
|
+
*/
|
|
102
|
+
const NOT_FIXED_BY_SIGNING_IN = [
|
|
103
|
+
"invalid_client",
|
|
104
|
+
"unauthorized_client",
|
|
105
|
+
"invalid_request",
|
|
106
|
+
"unsupported_grant_type",
|
|
107
|
+
];
|
|
108
|
+
/**
|
|
109
|
+
* Did Xero refuse the sign-in itself, so signing in again can fix it? An
|
|
110
|
+
* expired or revoked sign-in (invalid_grant), or a refusal with no code, is.
|
|
111
|
+
* A rate limit, a timeout, a Xero outage or wrong keys is not: opening the
|
|
112
|
+
* browser for those would ask the person to redo a sign-in that cannot help.
|
|
113
|
+
*/
|
|
114
|
+
export function needsNewSignIn(failure) {
|
|
115
|
+
if (failure.kind !== "http")
|
|
116
|
+
return false;
|
|
117
|
+
if (failure.status < 400 || failure.status >= 500)
|
|
118
|
+
return false;
|
|
119
|
+
if (failure.status === 408 || failure.status === 429)
|
|
120
|
+
return false;
|
|
121
|
+
return !(failure.code && NOT_FIXED_BY_SIGNING_IN.includes(failure.code));
|
|
122
|
+
}
|
|
123
|
+
/** The words a person sees when a refresh-token grant fails. */
|
|
124
|
+
export function describeRefreshFailure(failure) {
|
|
125
|
+
switch (failure.kind) {
|
|
126
|
+
case "timeout":
|
|
127
|
+
return "Xero did not answer in time. Please try again.";
|
|
128
|
+
case "network":
|
|
129
|
+
return "Could not reach Xero. Please check your network connection and try again.";
|
|
130
|
+
case "malformed":
|
|
131
|
+
return `Xero sent back an unexpected answer (HTTP ${failure.status}). Please try again.`;
|
|
132
|
+
case "http":
|
|
133
|
+
// A rate limit or outage first, whatever code its body carries.
|
|
134
|
+
if (failure.status === 429) {
|
|
135
|
+
return "Xero is rate limiting sign-in requests. Please try again in a moment.";
|
|
136
|
+
}
|
|
137
|
+
if (failure.status === 408 || failure.status >= 500) {
|
|
138
|
+
return `Xero is having trouble right now (HTTP ${failure.status}). Please try again in a few minutes.`;
|
|
139
|
+
}
|
|
140
|
+
if (failure.code === "invalid_grant") {
|
|
141
|
+
return "Your Xero sign-in has expired or was revoked. Open Xero in Rebel's connector settings and click Connect to sign in again.";
|
|
142
|
+
}
|
|
143
|
+
if (failure.code === "invalid_client" || failure.code === "unauthorized_client") {
|
|
144
|
+
return "Xero did not accept the Client ID and Client Secret. Check them in Rebel's Xero connector settings, then click Connect to sign in again.";
|
|
145
|
+
}
|
|
146
|
+
if (failure.code === "invalid_request" || failure.code === "unsupported_grant_type") {
|
|
147
|
+
return `Xero could not read the sign-in request (HTTP ${failure.status}, ${failure.code}). Please try again; if it keeps happening, update the Xero connector.`;
|
|
148
|
+
}
|
|
149
|
+
return `Xero refused to renew the sign-in (HTTP ${failure.status}${failure.code ? `, ${failure.code}` : ""}). Click Connect on the Xero connector to sign in again.`;
|
|
150
|
+
default: {
|
|
151
|
+
const unreachable = failure;
|
|
152
|
+
return unreachable;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const connectionsSchema = z.array(z.object({ tenantId: z.string().min(1), tenantType: z.string().optional() }));
|
|
157
|
+
/**
|
|
158
|
+
* The first Xero company (tenant) this access token can reach, or "" when none.
|
|
159
|
+
* Organisations come before other tenant kinds, since the Accounting API needs
|
|
160
|
+
* one. Every failure is a fixed message: Xero's body text never reaches it.
|
|
161
|
+
*/
|
|
162
|
+
export async function fetchFirstTenantId(accessToken) {
|
|
163
|
+
let response;
|
|
164
|
+
try {
|
|
165
|
+
response = await fetch(XERO_CONNECTIONS_URL, {
|
|
166
|
+
redirect: "error",
|
|
167
|
+
signal: AbortSignal.timeout(TOKEN_REQUEST_TIMEOUT_MS),
|
|
168
|
+
headers: { Authorization: `Bearer ${accessToken}`, Accept: "application/json" },
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
throw new Error(error instanceof Error && error.name === "TimeoutError"
|
|
173
|
+
? "Xero took too long to list your companies. Please try again."
|
|
174
|
+
: "Could not reach Xero to list your companies. Please try again.");
|
|
175
|
+
}
|
|
176
|
+
if (!response.ok) {
|
|
177
|
+
await response.body?.cancel().catch(() => undefined);
|
|
178
|
+
throw new Error(`Could not list your Xero companies (HTTP ${response.status}).`);
|
|
179
|
+
}
|
|
180
|
+
let data;
|
|
181
|
+
try {
|
|
182
|
+
data = await response.json();
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
throw new Error("Xero answered the company list with something unreadable. Please try again.");
|
|
186
|
+
}
|
|
187
|
+
const parsed = connectionsSchema.safeParse(data);
|
|
188
|
+
if (!parsed.success) {
|
|
189
|
+
throw new Error("Xero answered the company list in an unexpected shape. Please try again.");
|
|
190
|
+
}
|
|
191
|
+
const tenants = parsed.data;
|
|
192
|
+
const organisation = tenants.find((t) => t.tenantType === "ORGANISATION");
|
|
193
|
+
return (organisation ?? tenants[0])?.tenantId ?? "";
|
|
194
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hardened reader for the host app bridge (canonical copy).
|
|
3
|
+
*
|
|
4
|
+
* Connectors cannot import the test-harness at runtime (it is a dev-only
|
|
5
|
+
* `file:` dependency, never published into a connector's `dist/`), so each
|
|
6
|
+
* connector that talks to the bridge carries a VENDORED copy of this file at
|
|
7
|
+
* `connectors/<name>/src/bridge-reader.ts`, byte-identical to this one.
|
|
8
|
+
* `scripts/check-bridge-reader.mjs` fails CI when a copy drifts, and when a
|
|
9
|
+
* connector reads the bridge any other way. Change this file, then copy it to
|
|
10
|
+
* every connector that vendors it, in the same change.
|
|
11
|
+
*
|
|
12
|
+
* The host app sets the state file path when it spawns the server; the model
|
|
13
|
+
* cannot influence it. The read is still hardened, because the file carries the
|
|
14
|
+
* bridge bearer token and its `port` is put into the request URL:
|
|
15
|
+
*
|
|
16
|
+
* - An `lstat` refusal of a symlinked final component, then `O_NOFOLLOW` on the
|
|
17
|
+
* open where the platform defines it. Symlinked ancestors stay allowed (host
|
|
18
|
+
* state dirs can resolve through e.g. /var -> /private/var).
|
|
19
|
+
* - `O_NONBLOCK`, so a FIFO at the path is opened and refused instead of
|
|
20
|
+
* blocking the process waiting for a writer.
|
|
21
|
+
* - Same-descriptor fstat (regular file) and a read through that descriptor of
|
|
22
|
+
* at most 64 KiB (a larger or growing file is refused), plus a realpath inode
|
|
23
|
+
* cross-check that refuses the read when the path no
|
|
24
|
+
* longer names the opened file. Where `O_NOFOLLOW` is unavailable (Windows)
|
|
25
|
+
* this narrows, but cannot rule out, a symlink swap raced between lstat and
|
|
26
|
+
* open.
|
|
27
|
+
* - Strict schema validation of the content. The token must be visible ASCII,
|
|
28
|
+
* so it can never make the `Authorization` header invalid: fetch would quote
|
|
29
|
+
* the whole header value in its error.
|
|
30
|
+
*
|
|
31
|
+
* Any local process able to bind the port can answer a request, and would
|
|
32
|
+
* receive the token and the request body; nothing here can detect that, so it
|
|
33
|
+
* rests on the host app owning the port. The reply is therefore schema-checked,
|
|
34
|
+
* never cast, and its free text is enveloped before it can reach the model. Each refusal logs one fixed stderr line; file content and
|
|
35
|
+
* error messages (which can quote the path) are never logged.
|
|
36
|
+
*/
|
|
37
|
+
import * as fs from 'fs';
|
|
38
|
+
import { z } from 'zod';
|
|
39
|
+
import { wrapUntrusted } from './untrusted-content.js';
|
|
40
|
+
export const MAX_BRIDGE_STATE_BYTES = 64 * 1024;
|
|
41
|
+
const bridgeStateSchema = z.object({
|
|
42
|
+
port: z.number().int().min(1).max(65535),
|
|
43
|
+
token: z.string().regex(/^[\x21-\x7e]+$/),
|
|
44
|
+
});
|
|
45
|
+
const bridgeResponseSchema = z.object({
|
|
46
|
+
success: z.boolean(),
|
|
47
|
+
warning: z.string().optional(),
|
|
48
|
+
error: z.string().optional(),
|
|
49
|
+
});
|
|
50
|
+
/** The state file path: `MCP_HOST_BRIDGE_STATE`, else the legacy `MINDSTONE_REBEL_BRIDGE_STATE`. */
|
|
51
|
+
export function bridgeStatePath(env = process.env) {
|
|
52
|
+
return env.MCP_HOST_BRIDGE_STATE || env.MINDSTONE_REBEL_BRIDGE_STATE || '';
|
|
53
|
+
}
|
|
54
|
+
function refuse(connector, reason) {
|
|
55
|
+
console.error(`[${connector}] bridge state rejected: ${reason}`);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
/** Read and validate the bridge state file; `null` (with one stderr line) when it is unusable. */
|
|
59
|
+
export function readBridgeState(statePath, connector) {
|
|
60
|
+
if (!statePath)
|
|
61
|
+
return null;
|
|
62
|
+
let fd = null;
|
|
63
|
+
try {
|
|
64
|
+
if (fs.lstatSync(statePath).isSymbolicLink()) {
|
|
65
|
+
return refuse(connector, 'state path is a symbolic link');
|
|
66
|
+
}
|
|
67
|
+
fd = fs.openSync(statePath, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0));
|
|
68
|
+
const opened = fs.fstatSync(fd);
|
|
69
|
+
if (!opened.isFile()) {
|
|
70
|
+
return refuse(connector, 'not a regular file');
|
|
71
|
+
}
|
|
72
|
+
const canonical = fs.statSync(fs.realpathSync(statePath));
|
|
73
|
+
if (canonical.dev !== opened.dev || canonical.ino !== opened.ino) {
|
|
74
|
+
return refuse(connector, 'path resolved to a different file than was opened');
|
|
75
|
+
}
|
|
76
|
+
const buffer = Buffer.alloc(MAX_BRIDGE_STATE_BYTES + 1);
|
|
77
|
+
const length = fs.readSync(fd, buffer, 0, buffer.length, 0);
|
|
78
|
+
if (length > MAX_BRIDGE_STATE_BYTES) {
|
|
79
|
+
return refuse(connector, 'state file is too large');
|
|
80
|
+
}
|
|
81
|
+
const raw = buffer.toString('utf8', 0, length);
|
|
82
|
+
let json;
|
|
83
|
+
try {
|
|
84
|
+
json = JSON.parse(raw);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return refuse(connector, 'malformed JSON');
|
|
88
|
+
}
|
|
89
|
+
const parsed = bridgeStateSchema.safeParse(json);
|
|
90
|
+
if (!parsed.success) {
|
|
91
|
+
return refuse(connector, 'content failed schema validation');
|
|
92
|
+
}
|
|
93
|
+
return parsed.data;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// Missing, unreadable, or a symlink refused by O_NOFOLLOW (ELOOP).
|
|
97
|
+
return refuse(connector, 'state file could not be read');
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
if (fd !== null) {
|
|
101
|
+
try {
|
|
102
|
+
fs.closeSync(fd);
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
// A close failure on a read-only descriptor changes nothing.
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* POST to the host app bridge, a loopback HTTP server inside the host app that
|
|
112
|
+
* handles credential management. Network failures (a refused redirect, a
|
|
113
|
+
* timeout, a refused connection) are thrown for the caller to report.
|
|
114
|
+
*/
|
|
115
|
+
export async function postToBridge(urlPath, body, options) {
|
|
116
|
+
const { connector, timeoutMs } = options;
|
|
117
|
+
if (!urlPath.startsWith('/')) {
|
|
118
|
+
// Anything else could change the URL's authority (e.g. `@host`).
|
|
119
|
+
return { success: false, error: 'Bridge request path must start with /' };
|
|
120
|
+
}
|
|
121
|
+
const bridge = readBridgeState(options.statePath ?? bridgeStatePath(), connector);
|
|
122
|
+
if (!bridge) {
|
|
123
|
+
return { success: false, error: 'Bridge not available' };
|
|
124
|
+
}
|
|
125
|
+
const response = await fetch(`http://127.0.0.1:${bridge.port}${urlPath}`, {
|
|
126
|
+
method: 'POST',
|
|
127
|
+
// Never follow a redirect, which would resend the token-bearing body off loopback.
|
|
128
|
+
redirect: 'error',
|
|
129
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
130
|
+
headers: {
|
|
131
|
+
'Content-Type': 'application/json',
|
|
132
|
+
Authorization: `Bearer ${bridge.token}`,
|
|
133
|
+
},
|
|
134
|
+
body: JSON.stringify(body),
|
|
135
|
+
});
|
|
136
|
+
if (response.status === 401 || response.status === 403) {
|
|
137
|
+
// Discarding the body is connection hygiene only: an errored body stream
|
|
138
|
+
// must not replace the unauthorized answer.
|
|
139
|
+
await response.body?.cancel().catch(() => {
|
|
140
|
+
console.error(`[${connector}] bridge reply body could not be discarded`);
|
|
141
|
+
});
|
|
142
|
+
return {
|
|
143
|
+
success: false,
|
|
144
|
+
error: `Bridge returned ${response.status}: unauthorized. Check host app authentication.`,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
let raw;
|
|
148
|
+
try {
|
|
149
|
+
raw = await response.json();
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return { success: false, error: 'Bridge returned a malformed response' };
|
|
153
|
+
}
|
|
154
|
+
const parsed = bridgeResponseSchema.safeParse(raw);
|
|
155
|
+
if (!parsed.success) {
|
|
156
|
+
return { success: false, error: 'Bridge returned an unexpected response shape' };
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
success: parsed.data.success,
|
|
160
|
+
...(parsed.data.warning !== undefined
|
|
161
|
+
? { warning: wrapUntrusted(parsed.data.warning, `${connector}:bridge.warning`) }
|
|
162
|
+
: {}),
|
|
163
|
+
...(parsed.data.error !== undefined
|
|
164
|
+
? { error: wrapUntrusted(parsed.data.error, `${connector}:bridge.error`) }
|
|
165
|
+
: {}),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
@@ -5,15 +5,23 @@ import { formatError } from "../helpers/format-error.js";
|
|
|
5
5
|
import { findMissingScopes, isInvalidScopeError, } from "../helpers/find-missing-scopes.js";
|
|
6
6
|
import { formatMissingScopesMessage, formatTokenRequestError, } from "../helpers/format-token-error.js";
|
|
7
7
|
import { XERO_CUSTOM_CONNECTION_SCOPE } from "./xero-scopes.js";
|
|
8
|
+
import { bridgeRequest } from "../auth/bridge.js";
|
|
9
|
+
import { describeRefreshFailure, fetchFirstTenantId, requestRefreshGrant, } from "../auth/token-grant.js";
|
|
8
10
|
dotenv.config();
|
|
9
11
|
const client_id = process.env.XERO_CLIENT_ID;
|
|
10
12
|
const client_secret = process.env.XERO_CLIENT_SECRET;
|
|
11
13
|
const bearer_token = process.env.XERO_CLIENT_BEARER_TOKEN;
|
|
14
|
+
const refresh_token = process.env.XERO_REFRESH_TOKEN;
|
|
12
15
|
const grant_type = "client_credentials";
|
|
16
|
+
export const xeroAuthMode = bearer_token
|
|
17
|
+
? "bearer"
|
|
18
|
+
: refresh_token && client_id && client_secret
|
|
19
|
+
? "refresh-token"
|
|
20
|
+
: "custom-connection";
|
|
13
21
|
if (!bearer_token && (!client_id || !client_secret)) {
|
|
14
22
|
throw Error("Environment Variables not set - please check your .env file");
|
|
15
23
|
}
|
|
16
|
-
class MCPXeroClient extends XeroClient {
|
|
24
|
+
export class MCPXeroClient extends XeroClient {
|
|
17
25
|
tenantId;
|
|
18
26
|
shortCode;
|
|
19
27
|
constructor(config) {
|
|
@@ -24,9 +32,9 @@ class MCPXeroClient extends XeroClient {
|
|
|
24
32
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
33
|
async updateTenants(fullOrgDetails) {
|
|
26
34
|
await super.updateTenants(fullOrgDetails);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
// The latest list decides: a company this token no longer reaches must not
|
|
36
|
+
// linger from an earlier lookup.
|
|
37
|
+
this.tenantId = this.tenants?.[0]?.tenantId ?? "";
|
|
30
38
|
return this.tenants;
|
|
31
39
|
}
|
|
32
40
|
async getOrganisation() {
|
|
@@ -51,7 +59,32 @@ class MCPXeroClient extends XeroClient {
|
|
|
51
59
|
return this.shortCode;
|
|
52
60
|
}
|
|
53
61
|
}
|
|
54
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Xero refused the client-credentials grant for these keys. A Web app's keys
|
|
64
|
+
* get this (only a Custom Connection may use that grant), so "Sign in with
|
|
65
|
+
* Xero" is the way in.
|
|
66
|
+
*/
|
|
67
|
+
export class XeroClientCredentialsRefusedError extends Error {
|
|
68
|
+
constructor(message) {
|
|
69
|
+
super(message);
|
|
70
|
+
this.name = "XeroClientCredentialsRefusedError";
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Only a 400 or 401 can mean the keys were refused. A rate limit, timeout or
|
|
75
|
+
* outage is a try-again, even if its body carries one of these codes, so it
|
|
76
|
+
* never opens the browser to sign in again.
|
|
77
|
+
*/
|
|
78
|
+
function isClientCredentialsRefused(error) {
|
|
79
|
+
if (!axios.isAxiosError(error))
|
|
80
|
+
return false;
|
|
81
|
+
const status = error.response?.status;
|
|
82
|
+
if (status !== 400 && status !== 401)
|
|
83
|
+
return false;
|
|
84
|
+
const code = error.response?.data?.error;
|
|
85
|
+
return code === "unauthorized_client" || code === "invalid_client";
|
|
86
|
+
}
|
|
87
|
+
export class CustomConnectionsXeroClient extends MCPXeroClient {
|
|
55
88
|
clientId;
|
|
56
89
|
clientSecret;
|
|
57
90
|
tokenObtainedAt = 0;
|
|
@@ -76,6 +109,8 @@ class CustomConnectionsXeroClient extends MCPXeroClient {
|
|
|
76
109
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
77
110
|
Accept: "application/json",
|
|
78
111
|
},
|
|
112
|
+
// Never follow a redirect with the app's keys (see token-grant.ts).
|
|
113
|
+
maxRedirects: 0,
|
|
79
114
|
signal,
|
|
80
115
|
});
|
|
81
116
|
}
|
|
@@ -89,6 +124,7 @@ class CustomConnectionsXeroClient extends MCPXeroClient {
|
|
|
89
124
|
Authorization: `Bearer ${token}`,
|
|
90
125
|
Accept: "application/json",
|
|
91
126
|
},
|
|
127
|
+
maxRedirects: 0,
|
|
92
128
|
});
|
|
93
129
|
if (connectionsResponse.data && connectionsResponse.data.length > 0) {
|
|
94
130
|
this.tenantId = connectionsResponse.data[0].tenantId;
|
|
@@ -101,6 +137,9 @@ class CustomConnectionsXeroClient extends MCPXeroClient {
|
|
|
101
137
|
if (missing)
|
|
102
138
|
throw new Error(formatMissingScopesMessage(missing));
|
|
103
139
|
}
|
|
140
|
+
if (isClientCredentialsRefused(error)) {
|
|
141
|
+
throw new XeroClientCredentialsRefusedError(formatTokenRequestError(error));
|
|
142
|
+
}
|
|
104
143
|
throw new Error(formatTokenRequestError(error));
|
|
105
144
|
}
|
|
106
145
|
}
|
|
@@ -119,6 +158,93 @@ class CustomConnectionsXeroClient extends MCPXeroClient {
|
|
|
119
158
|
});
|
|
120
159
|
}
|
|
121
160
|
}
|
|
161
|
+
/** A refresh-token grant that failed; `failure` says why, in standard OAuth terms. */
|
|
162
|
+
export class XeroRefreshError extends Error {
|
|
163
|
+
failure;
|
|
164
|
+
constructor(failure) {
|
|
165
|
+
super(describeRefreshFailure(failure));
|
|
166
|
+
this.failure = failure;
|
|
167
|
+
this.name = "XeroRefreshError";
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/** Where the host saves a rotated refresh token, so a restart keeps the sign-in. */
|
|
171
|
+
export const UPDATE_REFRESH_TOKEN_PATH = "/bundled/xero/update-refresh-token";
|
|
172
|
+
function persistRotatedRefreshToken(refreshToken) {
|
|
173
|
+
bridgeRequest(UPDATE_REFRESH_TOKEN_PATH, { refreshToken })
|
|
174
|
+
.then((result) => {
|
|
175
|
+
if (!result.success) {
|
|
176
|
+
console.error(`Xero: the renewed sign-in was not saved (${result.error ?? "no reason given"}); it lasts until this connector restarts.`);
|
|
177
|
+
}
|
|
178
|
+
})
|
|
179
|
+
.catch((error) => {
|
|
180
|
+
console.error(`Xero: the renewed sign-in was not saved (${error instanceof Error ? error.name : "unknown error"}); it lasts until this connector restarts.`);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* A Xero Web app the person signed in to. Xero access tokens last 30 minutes
|
|
185
|
+
* and every refresh hands back a new refresh token, so refreshes run one at
|
|
186
|
+
* a time and each new refresh token is adopted at once and sent to the host.
|
|
187
|
+
*/
|
|
188
|
+
export class RefreshTokenXeroClient extends MCPXeroClient {
|
|
189
|
+
static REFRESH_BUFFER_MS = 5 * 60 * 1000;
|
|
190
|
+
keys;
|
|
191
|
+
currentRefreshToken;
|
|
192
|
+
accessToken = "";
|
|
193
|
+
accessExpiresAt = 0;
|
|
194
|
+
inflight = null;
|
|
195
|
+
constructor(keys, refreshToken) {
|
|
196
|
+
super();
|
|
197
|
+
this.keys = keys;
|
|
198
|
+
this.currentRefreshToken = refreshToken;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Ready means a live access token and a resolved company. A caller that
|
|
202
|
+
* arrives while a refresh or company lookup is running waits for it.
|
|
203
|
+
*/
|
|
204
|
+
async authenticate() {
|
|
205
|
+
if (this.inflight)
|
|
206
|
+
return this.inflight;
|
|
207
|
+
if (this.tenantId && !this.accessTokenNeedsRefresh())
|
|
208
|
+
return;
|
|
209
|
+
this.inflight = this.refresh().finally(() => {
|
|
210
|
+
this.inflight = null;
|
|
211
|
+
});
|
|
212
|
+
return this.inflight;
|
|
213
|
+
}
|
|
214
|
+
accessTokenNeedsRefresh() {
|
|
215
|
+
return Date.now() >= this.accessExpiresAt - RefreshTokenXeroClient.REFRESH_BUFFER_MS;
|
|
216
|
+
}
|
|
217
|
+
async refresh() {
|
|
218
|
+
if (this.accessTokenNeedsRefresh()) {
|
|
219
|
+
const result = await requestRefreshGrant(this.keys, this.currentRefreshToken);
|
|
220
|
+
if (!result.ok)
|
|
221
|
+
throw new XeroRefreshError(result.failure);
|
|
222
|
+
const { token } = result;
|
|
223
|
+
const rotated = !!token.refresh_token && token.refresh_token !== this.currentRefreshToken;
|
|
224
|
+
if (token.refresh_token)
|
|
225
|
+
this.currentRefreshToken = token.refresh_token;
|
|
226
|
+
this.setTokenSet({
|
|
227
|
+
access_token: token.access_token,
|
|
228
|
+
expires_in: token.expires_in,
|
|
229
|
+
token_type: token.token_type,
|
|
230
|
+
refresh_token: this.currentRefreshToken,
|
|
231
|
+
});
|
|
232
|
+
this.accessToken = token.access_token;
|
|
233
|
+
this.accessExpiresAt = Date.now() + token.expires_in * 1000;
|
|
234
|
+
if (rotated)
|
|
235
|
+
persistRotatedRefreshToken(this.currentRefreshToken);
|
|
236
|
+
}
|
|
237
|
+
// A failed lookup leaves tenantId empty, so the next call looks again
|
|
238
|
+
// with the same access token (and the refresh token it already adopted).
|
|
239
|
+
if (!this.tenantId) {
|
|
240
|
+
const tenantId = await fetchFirstTenantId(this.accessToken);
|
|
241
|
+
if (!tenantId) {
|
|
242
|
+
throw new Error("Your Xero sign-in has no company connected. Click Connect on the Xero connector and pick a company on Xero's page.");
|
|
243
|
+
}
|
|
244
|
+
this.tenantId = tenantId;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
122
248
|
class BearerTokenXeroClient extends MCPXeroClient {
|
|
123
249
|
bearerToken;
|
|
124
250
|
constructor(config) {
|
|
@@ -132,12 +258,18 @@ class BearerTokenXeroClient extends MCPXeroClient {
|
|
|
132
258
|
await this.updateTenants();
|
|
133
259
|
}
|
|
134
260
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
261
|
+
function createClient() {
|
|
262
|
+
switch (xeroAuthMode) {
|
|
263
|
+
case "bearer":
|
|
264
|
+
return new BearerTokenXeroClient({ bearerToken: bearer_token });
|
|
265
|
+
case "refresh-token":
|
|
266
|
+
return new RefreshTokenXeroClient({ clientId: client_id, clientSecret: client_secret }, refresh_token);
|
|
267
|
+
case "custom-connection":
|
|
268
|
+
return new CustomConnectionsXeroClient({
|
|
269
|
+
clientId: client_id,
|
|
270
|
+
clientSecret: client_secret,
|
|
271
|
+
grantType: grant_type,
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
export const xeroClient = createClient();
|
|
@@ -21,3 +21,11 @@ export const XERO_CUSTOM_CONNECTION_SCOPES = [
|
|
|
21
21
|
];
|
|
22
22
|
export const XERO_CUSTOM_CONNECTION_SCOPE = XERO_CUSTOM_CONNECTION_SCOPES.join(" ");
|
|
23
23
|
export const XERO_CUSTOM_CONNECTION_SCOPE_MESSAGE = XERO_CUSTOM_CONNECTION_SCOPES.join(", ");
|
|
24
|
+
/**
|
|
25
|
+
* What "Sign in with Xero" asks for: the same access as a Custom Connection,
|
|
26
|
+
* plus offline_access so Xero hands back a refresh token.
|
|
27
|
+
*/
|
|
28
|
+
export const XERO_SIGN_IN_SCOPES = [
|
|
29
|
+
"offline_access",
|
|
30
|
+
...XERO_CUSTOM_CONNECTION_SCOPES,
|
|
31
|
+
];
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { BRIDGE_NOT_AVAILABLE, BRIDGE_SIGN_IN_TIMEOUT_MS, bridgeRequest, } from "../auth/bridge.js";
|
|
2
|
+
import { needsNewSignIn } from "../auth/token-grant.js";
|
|
3
|
+
import { XeroClientCredentialsRefusedError, XeroRefreshError, xeroAuthMode, xeroClient, } from "../clients/xero-client.js";
|
|
4
|
+
import { XERO_SIGN_IN_SCOPES } from "../clients/xero-scopes.js";
|
|
5
|
+
import { formatError } from "../helpers/format-error.js";
|
|
6
|
+
export const SIGN_IN_TOOL_NAME = "xero_sign_in";
|
|
7
|
+
/** The host's route that runs "Sign in with Xero" in the person's browser. */
|
|
8
|
+
export const START_AUTH_PATH = "/bundled/xero/start-auth";
|
|
9
|
+
function signedIn(message) {
|
|
10
|
+
return { ok: true, status: "authenticated", message };
|
|
11
|
+
}
|
|
12
|
+
function failed(error) {
|
|
13
|
+
return { ok: false, error };
|
|
14
|
+
}
|
|
15
|
+
async function signInInBrowser() {
|
|
16
|
+
try {
|
|
17
|
+
const result = await bridgeRequest(START_AUTH_PATH, { scopes: [...XERO_SIGN_IN_SCOPES] }, BRIDGE_SIGN_IN_TIMEOUT_MS);
|
|
18
|
+
if (result.success)
|
|
19
|
+
return signedIn("Signed in to Xero.");
|
|
20
|
+
if (result.error === BRIDGE_NOT_AVAILABLE) {
|
|
21
|
+
return failed("Sign in with Xero needs Rebel. Outside Rebel, set XERO_REFRESH_TOKEN, XERO_CLIENT_BEARER_TOKEN or Custom Connection keys instead.");
|
|
22
|
+
}
|
|
23
|
+
return failed(result.error ?? "Sign in with Xero did not finish. Please try again.");
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error instanceof Error && error.name === "TimeoutError") {
|
|
27
|
+
return failed("Sign in with Xero took longer than 5 minutes. Please try again.");
|
|
28
|
+
}
|
|
29
|
+
return failed("Could not reach Rebel to sign in to Xero. Please try again.");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Sign in to Xero with whichever way this connector is set up. */
|
|
33
|
+
export async function signInToXero() {
|
|
34
|
+
if (xeroAuthMode === "bearer") {
|
|
35
|
+
// A bearer token cannot be renewed here, so a refused one is reported, not
|
|
36
|
+
// sent to the browser; xero-node's own error text is not passed on.
|
|
37
|
+
try {
|
|
38
|
+
await xeroClient.authenticate();
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return failed("Xero did not accept the token in XERO_CLIENT_BEARER_TOKEN.");
|
|
42
|
+
}
|
|
43
|
+
return xeroClient.tenantId
|
|
44
|
+
? signedIn("Connected to Xero with your bearer token.")
|
|
45
|
+
: failed("The token in XERO_CLIENT_BEARER_TOKEN reaches no Xero company.");
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
await xeroClient.authenticate();
|
|
49
|
+
return signedIn(xeroAuthMode === "refresh-token"
|
|
50
|
+
? "Already signed in to Xero."
|
|
51
|
+
: "Connected to Xero with your Custom Connection.");
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
// A Web app's keys cannot use a Custom Connection's grant; an expired or
|
|
55
|
+
// revoked sign-in cannot be renewed. Both mean: sign in again. A rate
|
|
56
|
+
// limit or Xero outage gets its own "try again" words instead.
|
|
57
|
+
if (error instanceof XeroClientCredentialsRefusedError)
|
|
58
|
+
return signInInBrowser();
|
|
59
|
+
if (error instanceof XeroRefreshError && needsNewSignIn(error.failure)) {
|
|
60
|
+
return signInInBrowser();
|
|
61
|
+
}
|
|
62
|
+
return failed(error instanceof Error ? error.message : formatError(error));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export function registerSignInTool(server) {
|
|
66
|
+
server.registerTool(SIGN_IN_TOOL_NAME, {
|
|
67
|
+
description: "Sign in to Xero. Takes no parameters; call with {}. Rebel calls this when the person clicks Connect on the Xero connector. With a Xero Web app it opens Xero's sign-in page in the browser; with a Custom Connection it checks the connection works.",
|
|
68
|
+
inputSchema: {},
|
|
69
|
+
annotations: {
|
|
70
|
+
readOnlyHint: false,
|
|
71
|
+
destructiveHint: false,
|
|
72
|
+
idempotentHint: true,
|
|
73
|
+
openWorldHint: true,
|
|
74
|
+
},
|
|
75
|
+
}, async () => {
|
|
76
|
+
const result = await signInToXero();
|
|
77
|
+
return {
|
|
78
|
+
content: [{ type: "text", text: JSON.stringify(result) }],
|
|
79
|
+
...(result.ok ? {} : { isError: true }),
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -3,6 +3,7 @@ import { DeleteTools } from "./delete/index.js";
|
|
|
3
3
|
import { GetTools } from "./get/index.js";
|
|
4
4
|
import { HistoryTools } from "./history/index.js";
|
|
5
5
|
import { ListTools } from "./list/index.js";
|
|
6
|
+
import { registerSignInTool } from "./sign-in.tool.js";
|
|
6
7
|
import { UpdateTools } from "./update/index.js";
|
|
7
8
|
const READ_ONLY_ANNOTATIONS = {
|
|
8
9
|
readOnlyHint: true,
|
|
@@ -15,6 +16,7 @@ const WRITE_ANNOTATIONS = {
|
|
|
15
16
|
openWorldHint: true,
|
|
16
17
|
};
|
|
17
18
|
export function ToolFactory(server) {
|
|
19
|
+
registerSignInTool(server);
|
|
18
20
|
DeleteTools.map((tool) => tool()).forEach((tool) => server.tool(tool.name, tool.description, tool.schema, WRITE_ANNOTATIONS, tool.handler));
|
|
19
21
|
GetTools.map((tool) => tool()).forEach((tool) => server.tool(tool.name, tool.description, tool.schema, READ_ONLY_ANNOTATIONS, tool.handler));
|
|
20
22
|
CreateTools.map((tool) => tool()).forEach((tool) => server.tool(tool.name, tool.description, tool.schema, WRITE_ANNOTATIONS, tool.handler));
|
package/package.json
CHANGED