@remit/mcp-server 0.2.1 → 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.
- package/dist/app-entry.d.ts +2 -2
- package/dist/app-entry.js +2 -2
- package/dist/app.d.ts +10 -2
- package/dist/app.js +39 -33
- package/dist/deps.d.ts +2 -0
- package/dist/deps.js +2 -0
- package/dist/main.js +1 -3
- package/package.json +1 -1
package/dist/app-entry.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { CLIENT_IP_HEADER } from "@remit/auth-service/constants";
|
|
2
|
-
export { createMcpApp, type McpAppConfig } from "./app.js";
|
|
2
|
+
export { challenge, createMcpApp, createMcpPages, type McpAppConfig, type McpChallengeError, type McpPagesConfig, type McpResourceConfig, protectedResourceMetadata, } from "./app.js";
|
|
3
3
|
export { AUTH_BASE_PATH, CONNECTED_APPS_API_PATH, CONNECTED_APPS_PATH, CONSENT_PATH, createBetterAuthTokenVerifier, createMcpAuth, DEVICE_APPROVE_PATH, DEVICE_CODE_PATH, DEVICE_DENY_PATH, DEVICE_PATH, JWKS_PATH, LOGIN_PATH, MCP_PATH, type McpAuth, type McpAuthConfig, type McpAuthRoutes, type McpAuthServer, type McpBrowserAuth, type McpBrowserRoutes, type McpIdentity, type McpSessionState, type McpSignInResult, type McpSubject, mcpResource, OAUTH2_PATH_PREFIX, REVOKE_CLIENT_API_PATH, SIGN_IN_PATH, type SignIn, } from "./auth/authorization-server.js";
|
|
4
4
|
export { type McpSqliteDatabase, type McpUserTables, mcpDatabase, } from "./auth/mcp-database.js";
|
|
5
5
|
export { describeScopes, MCP_READ_SCOPE, MCP_RULES_SCOPE, MCP_SCOPES, OFFLINE_ACCESS_SCOPE, } from "./auth/scopes.js";
|
|
6
6
|
export type { TokenVerification, TokenVerifier, } from "./auth/token-verifier.js";
|
|
7
7
|
export { claudeMcpAddCommand, type DeviceLoginIo, type DeviceLoginResult, deviceLogin, } from "./cli/device-login.js";
|
|
8
|
-
export { type FilterToolDeps, type FolderToolDeps, type McpDeps, type McpDepsExtras, mcpDepsOf, } from "./deps.js";
|
|
8
|
+
export { type FilterToolDeps, FOLDER_POLL_INTERVAL_MS, FOLDER_SETTLE_TIMEOUT_MS, type FolderToolDeps, type McpDeps, type McpDepsExtras, mcpDepsOf, } from "./deps.js";
|
|
9
9
|
export { STYLESHEET_PATH } from "./pages/assets.js";
|
|
10
10
|
export { errorPage, pageError, renderPage } from "./pages/render.js";
|
|
11
11
|
export { type ConnectedAppGrant, connectedAppsView, consentView, deviceView, loginView, } from "./pages/views.js";
|
package/dist/app-entry.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { CLIENT_IP_HEADER } from "@remit/auth-service/constants";
|
|
2
|
-
export { createMcpApp } from "./app.js";
|
|
2
|
+
export { challenge, createMcpApp, createMcpPages, protectedResourceMetadata, } from "./app.js";
|
|
3
3
|
export { AUTH_BASE_PATH, CONNECTED_APPS_API_PATH, CONNECTED_APPS_PATH, CONSENT_PATH, createBetterAuthTokenVerifier, createMcpAuth, DEVICE_APPROVE_PATH, DEVICE_CODE_PATH, DEVICE_DENY_PATH, DEVICE_PATH, JWKS_PATH, LOGIN_PATH, MCP_PATH, mcpResource, OAUTH2_PATH_PREFIX, REVOKE_CLIENT_API_PATH, SIGN_IN_PATH, } from "./auth/authorization-server.js";
|
|
4
4
|
export { mcpDatabase, } from "./auth/mcp-database.js";
|
|
5
5
|
export { describeScopes, MCP_READ_SCOPE, MCP_RULES_SCOPE, MCP_SCOPES, OFFLINE_ACCESS_SCOPE, } from "./auth/scopes.js";
|
|
6
6
|
export { claudeMcpAddCommand, deviceLogin, } from "./cli/device-login.js";
|
|
7
|
-
export { mcpDepsOf, } from "./deps.js";
|
|
7
|
+
export { FOLDER_POLL_INTERVAL_MS, FOLDER_SETTLE_TIMEOUT_MS, mcpDepsOf, } from "./deps.js";
|
|
8
8
|
export { STYLESHEET_PATH } from "./pages/assets.js";
|
|
9
9
|
export { errorPage, pageError, renderPage } from "./pages/render.js";
|
|
10
10
|
export { connectedAppsView, consentView, deviceView, loginView, } from "./pages/views.js";
|
package/dist/app.d.ts
CHANGED
|
@@ -2,10 +2,18 @@ import { type McpAuthRoutes } from "./auth/authorization-server.js";
|
|
|
2
2
|
import type { TokenVerifier } from "./auth/token-verifier.js";
|
|
3
3
|
import type { McpDeps } from "./deps.js";
|
|
4
4
|
import { type McpRequestHandler } from "./server.js";
|
|
5
|
-
export interface
|
|
5
|
+
export interface McpResourceConfig {
|
|
6
6
|
origin: string;
|
|
7
|
+
}
|
|
8
|
+
export interface McpPagesConfig extends McpResourceConfig {
|
|
7
9
|
authRoutes: McpAuthRoutes;
|
|
10
|
+
}
|
|
11
|
+
export interface McpAppConfig extends McpPagesConfig {
|
|
8
12
|
verifier: TokenVerifier;
|
|
9
13
|
deps: McpDeps;
|
|
10
14
|
}
|
|
11
|
-
export
|
|
15
|
+
export type McpChallengeError = "unauthorized" | "invalid_token";
|
|
16
|
+
export declare const challenge: ({ origin }: McpResourceConfig, error: McpChallengeError) => Response;
|
|
17
|
+
export declare const protectedResourceMetadata: ({ origin, }: McpResourceConfig) => Response;
|
|
18
|
+
export declare const createMcpPages: ({ origin, authRoutes, }: McpPagesConfig) => McpRequestHandler;
|
|
19
|
+
export declare const createMcpApp: (config: McpAppConfig) => McpRequestHandler;
|
package/dist/app.js
CHANGED
|
@@ -6,6 +6,25 @@ import { errorPage, pageError } from "./pages/render.js";
|
|
|
6
6
|
import { connectedAppsView, consentView, deviceView, loginView, } from "./pages/views.js";
|
|
7
7
|
import { createMcpHandler } from "./server.js";
|
|
8
8
|
const PROTECTED_RESOURCE_METADATA_PATH = "/.well-known/oauth-protected-resource";
|
|
9
|
+
const RESOURCE_METADATA_PATH = `${PROTECTED_RESOURCE_METADATA_PATH}${MCP_PATH}`;
|
|
10
|
+
export const challenge = ({ origin }, error) => new Response(JSON.stringify({ error, resource: mcpResource(origin) }), {
|
|
11
|
+
status: 401,
|
|
12
|
+
headers: {
|
|
13
|
+
"content-type": "application/json",
|
|
14
|
+
"www-authenticate": [
|
|
15
|
+
"Bearer",
|
|
16
|
+
` resource_metadata="${origin}${RESOURCE_METADATA_PATH}",`,
|
|
17
|
+
` scope="${MCP_SCOPES.join(" ")}"`,
|
|
18
|
+
error === "unauthorized" ? "" : `, error="${error}"`,
|
|
19
|
+
].join(""),
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
export const protectedResourceMetadata = ({ origin, }) => Response.json({
|
|
23
|
+
resource: mcpResource(origin),
|
|
24
|
+
authorization_servers: [origin],
|
|
25
|
+
scopes_supported: [...MCP_SCOPES],
|
|
26
|
+
bearer_methods_supported: ["header"],
|
|
27
|
+
});
|
|
9
28
|
const RETURN_PATHS = new Set([
|
|
10
29
|
DEVICE_PATH,
|
|
11
30
|
CONNECTED_APPS_PATH,
|
|
@@ -40,21 +59,7 @@ const redirectWithCookies = (location, from) => {
|
|
|
40
59
|
}
|
|
41
60
|
return new Response(null, { status: 302, headers });
|
|
42
61
|
};
|
|
43
|
-
export const
|
|
44
|
-
const resource = mcpResource(origin);
|
|
45
|
-
const resourceMetadataPath = `${PROTECTED_RESOURCE_METADATA_PATH}${MCP_PATH}`;
|
|
46
|
-
const challenge = (error) => new Response(JSON.stringify({ error: error ?? "unauthorized", resource }), {
|
|
47
|
-
status: 401,
|
|
48
|
-
headers: {
|
|
49
|
-
"content-type": "application/json",
|
|
50
|
-
"www-authenticate": [
|
|
51
|
-
"Bearer",
|
|
52
|
-
` resource_metadata="${origin}${resourceMetadataPath}",`,
|
|
53
|
-
` scope="${MCP_SCOPES.join(" ")}"`,
|
|
54
|
-
error ? `, error="${error}"` : "",
|
|
55
|
-
].join(""),
|
|
56
|
-
},
|
|
57
|
-
});
|
|
62
|
+
export const createMcpPages = ({ origin, authRoutes, }) => {
|
|
58
63
|
const continueFrom = async (response) => {
|
|
59
64
|
if (!response.ok) {
|
|
60
65
|
return errorPage("Connecting failed", await failureOf(response), "Go back to your MCP client and connect remit again.", response.status);
|
|
@@ -222,31 +227,15 @@ export const createMcpApp = ({ origin, authRoutes, verifier, deps, }) => {
|
|
|
222
227
|
return after;
|
|
223
228
|
return connectedAppsView(after, 200, name);
|
|
224
229
|
};
|
|
225
|
-
const serveMcp = async (request) => {
|
|
226
|
-
const bearer = extractBearerToken(request.headers.get("authorization") ?? undefined);
|
|
227
|
-
if (!bearer)
|
|
228
|
-
return challenge();
|
|
229
|
-
const verification = await verifier.verify(bearer);
|
|
230
|
-
if (!verification.ok)
|
|
231
|
-
return challenge("invalid_token");
|
|
232
|
-
return createMcpHandler(verification.principal, deps)(request);
|
|
233
|
-
};
|
|
234
230
|
return async (request) => {
|
|
235
231
|
const { pathname } = new URL(request.url);
|
|
236
232
|
if (pathname === "/.well-known/oauth-authorization-server") {
|
|
237
233
|
return authRoutes.serverMetadata(request);
|
|
238
234
|
}
|
|
239
|
-
if (pathname ===
|
|
235
|
+
if (pathname === RESOURCE_METADATA_PATH ||
|
|
240
236
|
pathname === PROTECTED_RESOURCE_METADATA_PATH) {
|
|
241
|
-
return
|
|
242
|
-
resource,
|
|
243
|
-
authorization_servers: [origin],
|
|
244
|
-
scopes_supported: [...MCP_SCOPES],
|
|
245
|
-
bearer_methods_supported: ["header"],
|
|
246
|
-
});
|
|
237
|
+
return protectedResourceMetadata({ origin });
|
|
247
238
|
}
|
|
248
|
-
if (pathname === MCP_PATH)
|
|
249
|
-
return serveMcp(request);
|
|
250
239
|
if (pathname === LOGIN_PATH && authRoutes.browser.kind === "signIn") {
|
|
251
240
|
return login(request, authRoutes.browser.signIn);
|
|
252
241
|
}
|
|
@@ -259,3 +248,20 @@ export const createMcpApp = ({ origin, authRoutes, verifier, deps, }) => {
|
|
|
259
248
|
return authRoutes.handle(request);
|
|
260
249
|
};
|
|
261
250
|
};
|
|
251
|
+
export const createMcpApp = (config) => {
|
|
252
|
+
const pages = createMcpPages(config);
|
|
253
|
+
const serveMcp = async (request) => {
|
|
254
|
+
const bearer = extractBearerToken(request.headers.get("authorization") ?? undefined);
|
|
255
|
+
if (!bearer)
|
|
256
|
+
return challenge(config, "unauthorized");
|
|
257
|
+
const verification = await config.verifier.verify(bearer);
|
|
258
|
+
if (!verification.ok)
|
|
259
|
+
return challenge(config, "invalid_token");
|
|
260
|
+
return createMcpHandler(verification.principal, config.deps)(request);
|
|
261
|
+
};
|
|
262
|
+
return (request) => {
|
|
263
|
+
if (new URL(request.url).pathname === MCP_PATH)
|
|
264
|
+
return serveMcp(request);
|
|
265
|
+
return pages(request);
|
|
266
|
+
};
|
|
267
|
+
};
|
package/dist/deps.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import type { RemitClient } from "@remit/backend/client";
|
|
|
2
2
|
import type { IAccountRepository, IFilterRepository, IMailboxRepository, IMessageRepository, IOrganizeJobRequestRepository, IThreadMessageRepository, OrganizeJobEvent, QueueProducer } from "@remit/data-ports";
|
|
3
3
|
import type { BodyPartMaterializer, BodySyncCue, MailboxQueueService, MaterializeLogger, OrganizeJobLogger } from "@remit/mailbox-service";
|
|
4
4
|
import type { StorageService } from "@remit/storage-service";
|
|
5
|
+
export declare const FOLDER_SETTLE_TIMEOUT_MS = 20000;
|
|
6
|
+
export declare const FOLDER_POLL_INTERVAL_MS = 500;
|
|
5
7
|
export interface FolderToolDeps {
|
|
6
8
|
mailboxQueue: Pick<MailboxQueueService, "createMailbox" | "renameMailbox" | "dismissMailboxIntent">;
|
|
7
9
|
settleTimeoutMs: number;
|
package/dist/deps.js
CHANGED
package/dist/main.js
CHANGED
|
@@ -9,12 +9,10 @@ import { createBetterAuthTokenVerifier } from "./auth/authorization-server.js";
|
|
|
9
9
|
import { openMcpAuthDatabase } from "./auth/database.js";
|
|
10
10
|
import { createSqliteMcpAuth } from "./auth/node-auth.js";
|
|
11
11
|
import { resolveMcpServerConfig } from "./config.js";
|
|
12
|
-
import { mcpDepsOf } from "./deps.js";
|
|
12
|
+
import { FOLDER_POLL_INTERVAL_MS, FOLDER_SETTLE_TIMEOUT_MS, mcpDepsOf, } from "./deps.js";
|
|
13
13
|
import { ASSETS_PATH_PREFIX, serveAsset } from "./pages/assets.js";
|
|
14
14
|
import { loadPageAssets } from "./pages/load-assets.js";
|
|
15
15
|
installNodeLogger();
|
|
16
|
-
const FOLDER_SETTLE_TIMEOUT_MS = 20_000;
|
|
17
|
-
const FOLDER_POLL_INTERVAL_MS = 500;
|
|
18
16
|
const config = resolveMcpServerConfig();
|
|
19
17
|
const client = await getClient();
|
|
20
18
|
const deps = mcpDepsOf(client, {
|