@beeper/desktop-mcp 4.2.3 → 4.7.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/LICENSE +1 -1
- package/README.md +18 -199
- package/auth.d.mts +6 -0
- package/auth.d.mts.map +1 -0
- package/auth.d.ts +6 -0
- package/auth.d.ts.map +1 -0
- package/auth.js +37 -0
- package/auth.js.map +1 -0
- package/auth.mjs +32 -0
- package/auth.mjs.map +1 -0
- package/code-tool-types.d.mts +7 -7
- package/code-tool-types.d.mts.map +1 -1
- package/code-tool-types.d.ts +7 -7
- package/code-tool-types.d.ts.map +1 -1
- package/code-tool-worker.d.mts.map +1 -1
- package/code-tool-worker.d.ts.map +1 -1
- package/code-tool-worker.js +103 -19
- package/code-tool-worker.js.map +1 -1
- package/code-tool-worker.mjs +103 -19
- package/code-tool-worker.mjs.map +1 -1
- package/code-tool.d.mts +12 -3
- package/code-tool.d.mts.map +1 -1
- package/code-tool.d.ts +12 -3
- package/code-tool.d.ts.map +1 -1
- package/code-tool.js +276 -95
- package/code-tool.js.map +1 -1
- package/code-tool.mjs +273 -95
- package/code-tool.mjs.map +1 -1
- package/docs-search-tool.d.mts +22 -9
- package/docs-search-tool.d.mts.map +1 -1
- package/docs-search-tool.d.ts +22 -9
- package/docs-search-tool.d.ts.map +1 -1
- package/docs-search-tool.js +37 -6
- package/docs-search-tool.js.map +1 -1
- package/docs-search-tool.mjs +37 -6
- package/docs-search-tool.mjs.map +1 -1
- package/http.d.mts +6 -9
- package/http.d.mts.map +1 -1
- package/http.d.ts +6 -9
- package/http.d.ts.map +1 -1
- package/http.js +81 -47
- package/http.js.map +1 -1
- package/http.mjs +80 -43
- package/http.mjs.map +1 -1
- package/index.js +19 -50
- package/index.js.map +1 -1
- package/index.mjs +19 -50
- package/index.mjs.map +1 -1
- package/instructions.d.mts +2 -0
- package/instructions.d.mts.map +1 -0
- package/instructions.d.ts +2 -0
- package/instructions.d.ts.map +1 -0
- package/instructions.js +48 -0
- package/instructions.js.map +1 -0
- package/instructions.mjs +45 -0
- package/instructions.mjs.map +1 -0
- package/logger.d.mts +7 -0
- package/logger.d.mts.map +1 -0
- package/logger.d.ts +7 -0
- package/logger.d.ts.map +1 -0
- package/logger.js +29 -0
- package/logger.js.map +1 -0
- package/logger.mjs +22 -0
- package/logger.mjs.map +1 -0
- package/methods.d.mts +10 -0
- package/methods.d.mts.map +1 -0
- package/methods.d.ts +10 -0
- package/methods.d.ts.map +1 -0
- package/methods.js +203 -0
- package/methods.js.map +1 -0
- package/methods.mjs +199 -0
- package/methods.mjs.map +1 -0
- package/options.d.mts +9 -9
- package/options.d.mts.map +1 -1
- package/options.d.ts +9 -9
- package/options.d.ts.map +1 -1
- package/options.js +54 -359
- package/options.js.map +1 -1
- package/options.mjs +54 -359
- package/options.mjs.map +1 -1
- package/package.json +68 -72
- package/server.d.mts +10 -16
- package/server.d.mts.map +1 -1
- package/server.d.ts +10 -16
- package/server.d.ts.map +1 -1
- package/server.js +82 -101
- package/server.js.map +1 -1
- package/server.mjs +81 -96
- package/server.mjs.map +1 -1
- package/src/auth.ts +42 -0
- package/src/code-tool-types.ts +8 -5
- package/src/code-tool-worker.ts +118 -34
- package/src/code-tool.ts +359 -118
- package/src/docs-search-tool.ts +59 -7
- package/src/http.ts +99 -50
- package/src/index.ts +22 -63
- package/src/instructions.ts +67 -0
- package/src/logger.ts +28 -0
- package/src/methods.ts +224 -0
- package/src/options.ts +72 -384
- package/src/server.ts +94 -117
- package/src/stdio.ts +6 -5
- package/src/{tools/types.ts → types.ts} +25 -5
- package/src/util.ts +25 -0
- package/stdio.d.mts +1 -1
- package/stdio.d.mts.map +1 -1
- package/stdio.d.ts +1 -1
- package/stdio.d.ts.map +1 -1
- package/stdio.js +5 -4
- package/stdio.js.map +1 -1
- package/stdio.mjs +5 -4
- package/stdio.mjs.map +1 -1
- package/{tools/types.d.mts → types.d.mts} +10 -2
- package/types.d.mts.map +1 -0
- package/{tools/types.d.ts → types.d.ts} +10 -2
- package/types.d.ts.map +1 -0
- package/{tools/types.js → types.js} +12 -0
- package/types.js.map +1 -0
- package/{tools/types.mjs → types.mjs} +11 -0
- package/types.mjs.map +1 -0
- package/util.d.mts +4 -0
- package/util.d.mts.map +1 -0
- package/util.d.ts +4 -0
- package/util.d.ts.map +1 -0
- package/util.js +30 -0
- package/util.js.map +1 -0
- package/util.mjs +24 -0
- package/util.mjs.map +1 -0
- package/compat.d.mts +0 -58
- package/compat.d.mts.map +0 -1
- package/compat.d.ts +0 -58
- package/compat.d.ts.map +0 -1
- package/compat.js +0 -387
- package/compat.js.map +0 -1
- package/compat.mjs +0 -378
- package/compat.mjs.map +0 -1
- package/dynamic-tools.d.mts +0 -12
- package/dynamic-tools.d.mts.map +0 -1
- package/dynamic-tools.d.ts +0 -12
- package/dynamic-tools.d.ts.map +0 -1
- package/dynamic-tools.js +0 -135
- package/dynamic-tools.js.map +0 -1
- package/dynamic-tools.mjs +0 -132
- package/dynamic-tools.mjs.map +0 -1
- package/filtering.d.mts +0 -2
- package/filtering.d.mts.map +0 -1
- package/filtering.d.ts +0 -2
- package/filtering.d.ts.map +0 -1
- package/filtering.js +0 -20
- package/filtering.js.map +0 -1
- package/filtering.mjs +0 -13
- package/filtering.mjs.map +0 -1
- package/handlers/get-accounts.d.mts +0 -3
- package/handlers/get-accounts.d.mts.map +0 -1
- package/handlers/get-accounts.d.ts +0 -3
- package/handlers/get-accounts.d.ts.map +0 -1
- package/handlers/get-accounts.js +0 -32
- package/handlers/get-accounts.js.map +0 -1
- package/handlers/get-accounts.mjs +0 -28
- package/handlers/get-accounts.mjs.map +0 -1
- package/handlers/get-chat.d.mts +0 -3
- package/handlers/get-chat.d.mts.map +0 -1
- package/handlers/get-chat.d.ts +0 -3
- package/handlers/get-chat.d.ts.map +0 -1
- package/handlers/get-chat.js +0 -20
- package/handlers/get-chat.js.map +0 -1
- package/handlers/get-chat.mjs +0 -16
- package/handlers/get-chat.mjs.map +0 -1
- package/handlers/index.d.mts +0 -3
- package/handlers/index.d.mts.map +0 -1
- package/handlers/index.d.ts +0 -3
- package/handlers/index.d.ts.map +0 -1
- package/handlers/index.js +0 -30
- package/handlers/index.js.map +0 -1
- package/handlers/index.mjs +0 -27
- package/handlers/index.mjs.map +0 -1
- package/handlers/list-chats.d.mts +0 -3
- package/handlers/list-chats.d.mts.map +0 -1
- package/handlers/list-chats.d.ts +0 -3
- package/handlers/list-chats.d.ts.map +0 -1
- package/handlers/list-chats.js +0 -46
- package/handlers/list-chats.js.map +0 -1
- package/handlers/list-chats.mjs +0 -42
- package/handlers/list-chats.mjs.map +0 -1
- package/handlers/list-messages.d.mts +0 -3
- package/handlers/list-messages.d.mts.map +0 -1
- package/handlers/list-messages.d.ts +0 -3
- package/handlers/list-messages.d.ts.map +0 -1
- package/handlers/list-messages.js +0 -34
- package/handlers/list-messages.js.map +0 -1
- package/handlers/list-messages.mjs +0 -30
- package/handlers/list-messages.mjs.map +0 -1
- package/handlers/open-app.d.mts +0 -3
- package/handlers/open-app.d.mts.map +0 -1
- package/handlers/open-app.d.ts +0 -3
- package/handlers/open-app.d.ts.map +0 -1
- package/handlers/open-app.js +0 -26
- package/handlers/open-app.js.map +0 -1
- package/handlers/open-app.mjs +0 -22
- package/handlers/open-app.mjs.map +0 -1
- package/handlers/search-chats.d.mts +0 -3
- package/handlers/search-chats.d.mts.map +0 -1
- package/handlers/search-chats.d.ts +0 -3
- package/handlers/search-chats.d.ts.map +0 -1
- package/handlers/search-chats.js +0 -38
- package/handlers/search-chats.js.map +0 -1
- package/handlers/search-chats.mjs +0 -34
- package/handlers/search-chats.mjs.map +0 -1
- package/handlers/search-messages.d.mts +0 -3
- package/handlers/search-messages.d.mts.map +0 -1
- package/handlers/search-messages.d.ts +0 -3
- package/handlers/search-messages.d.ts.map +0 -1
- package/handlers/search-messages.js +0 -11
- package/handlers/search-messages.js.map +0 -1
- package/handlers/search-messages.mjs +0 -7
- package/handlers/search-messages.mjs.map +0 -1
- package/handlers/search.d.mts +0 -3
- package/handlers/search.d.mts.map +0 -1
- package/handlers/search.d.ts +0 -3
- package/handlers/search.d.ts.map +0 -1
- package/handlers/search.js +0 -29
- package/handlers/search.js.map +0 -1
- package/handlers/search.mjs +0 -25
- package/handlers/search.mjs.map +0 -1
- package/handlers/send-message.d.mts +0 -3
- package/handlers/send-message.d.mts.map +0 -1
- package/handlers/send-message.d.ts +0 -3
- package/handlers/send-message.d.ts.map +0 -1
- package/handlers/send-message.js +0 -20
- package/handlers/send-message.js.map +0 -1
- package/handlers/send-message.mjs +0 -16
- package/handlers/send-message.mjs.map +0 -1
- package/handlers/utils.d.mts +0 -29
- package/handlers/utils.d.mts.map +0 -1
- package/handlers/utils.d.ts +0 -29
- package/handlers/utils.d.ts.map +0 -1
- package/handlers/utils.js +0 -296
- package/handlers/utils.js.map +0 -1
- package/handlers/utils.mjs +0 -282
- package/handlers/utils.mjs.map +0 -1
- package/headers.d.mts +0 -4
- package/headers.d.mts.map +0 -1
- package/headers.d.ts +0 -4
- package/headers.d.ts.map +0 -1
- package/headers.js +0 -22
- package/headers.js.map +0 -1
- package/headers.mjs +0 -18
- package/headers.mjs.map +0 -1
- package/src/compat.ts +0 -483
- package/src/dynamic-tools.ts +0 -159
- package/src/filtering.ts +0 -14
- package/src/handlers/get-accounts.ts +0 -28
- package/src/handlers/get-chat.ts +0 -18
- package/src/handlers/index.ts +0 -29
- package/src/handlers/list-chats.ts +0 -47
- package/src/handlers/list-messages.ts +0 -33
- package/src/handlers/open-app.ts +0 -20
- package/src/handlers/search-chats.ts +0 -39
- package/src/handlers/search-messages.ts +0 -8
- package/src/handlers/search.ts +0 -24
- package/src/handlers/send-message.ts +0 -17
- package/src/handlers/utils.ts +0 -381
- package/src/headers.ts +0 -23
- package/src/tools/accounts/get-accounts.ts +0 -34
- package/src/tools/chats/archive-chat.ts +0 -43
- package/src/tools/chats/get-chat.ts +0 -45
- package/src/tools/chats/reminders/clear-chat-reminder.ts +0 -41
- package/src/tools/chats/reminders/set-chat-reminder.ts +0 -54
- package/src/tools/chats/search-chats.ts +0 -104
- package/src/tools/index.ts +0 -92
- package/src/tools/messages/list-messages.ts +0 -51
- package/src/tools/messages/search-messages.ts +0 -123
- package/src/tools/messages/send-message.ts +0 -47
- package/src/tools/top-level/focus-app.ts +0 -52
- package/src/tools/top-level/search.ts +0 -41
- package/src/tools.ts +0 -1
- package/tools/accounts/get-accounts.d.mts +0 -45
- package/tools/accounts/get-accounts.d.mts.map +0 -1
- package/tools/accounts/get-accounts.d.ts +0 -45
- package/tools/accounts/get-accounts.d.ts.map +0 -1
- package/tools/accounts/get-accounts.js +0 -31
- package/tools/accounts/get-accounts.js.map +0 -1
- package/tools/accounts/get-accounts.mjs +0 -27
- package/tools/accounts/get-accounts.mjs.map +0 -1
- package/tools/chats/archive-chat.d.mts +0 -45
- package/tools/chats/archive-chat.d.mts.map +0 -1
- package/tools/chats/archive-chat.d.ts +0 -45
- package/tools/chats/archive-chat.d.ts.map +0 -1
- package/tools/chats/archive-chat.js +0 -40
- package/tools/chats/archive-chat.js.map +0 -1
- package/tools/chats/archive-chat.mjs +0 -36
- package/tools/chats/archive-chat.mjs.map +0 -1
- package/tools/chats/get-chat.d.mts +0 -45
- package/tools/chats/get-chat.d.mts.map +0 -1
- package/tools/chats/get-chat.d.ts +0 -45
- package/tools/chats/get-chat.d.ts.map +0 -1
- package/tools/chats/get-chat.js +0 -41
- package/tools/chats/get-chat.js.map +0 -1
- package/tools/chats/get-chat.mjs +0 -37
- package/tools/chats/get-chat.mjs.map +0 -1
- package/tools/chats/reminders/clear-chat-reminder.d.mts +0 -45
- package/tools/chats/reminders/clear-chat-reminder.d.mts.map +0 -1
- package/tools/chats/reminders/clear-chat-reminder.d.ts +0 -45
- package/tools/chats/reminders/clear-chat-reminder.d.ts.map +0 -1
- package/tools/chats/reminders/clear-chat-reminder.js +0 -38
- package/tools/chats/reminders/clear-chat-reminder.js.map +0 -1
- package/tools/chats/reminders/clear-chat-reminder.mjs +0 -34
- package/tools/chats/reminders/clear-chat-reminder.mjs.map +0 -1
- package/tools/chats/reminders/set-chat-reminder.d.mts +0 -45
- package/tools/chats/reminders/set-chat-reminder.d.mts.map +0 -1
- package/tools/chats/reminders/set-chat-reminder.d.ts +0 -45
- package/tools/chats/reminders/set-chat-reminder.d.ts.map +0 -1
- package/tools/chats/reminders/set-chat-reminder.js +0 -51
- package/tools/chats/reminders/set-chat-reminder.js.map +0 -1
- package/tools/chats/reminders/set-chat-reminder.mjs +0 -47
- package/tools/chats/reminders/set-chat-reminder.mjs.map +0 -1
- package/tools/chats/search-chats.d.mts +0 -45
- package/tools/chats/search-chats.d.mts.map +0 -1
- package/tools/chats/search-chats.d.ts +0 -45
- package/tools/chats/search-chats.d.ts.map +0 -1
- package/tools/chats/search-chats.js +0 -92
- package/tools/chats/search-chats.js.map +0 -1
- package/tools/chats/search-chats.mjs +0 -88
- package/tools/chats/search-chats.mjs.map +0 -1
- package/tools/index.d.mts +0 -10
- package/tools/index.d.mts.map +0 -1
- package/tools/index.d.ts +0 -10
- package/tools/index.d.ts.map +0 -1
- package/tools/index.js +0 -76
- package/tools/index.js.map +0 -1
- package/tools/index.mjs +0 -69
- package/tools/index.mjs.map +0 -1
- package/tools/messages/list-messages.d.mts +0 -45
- package/tools/messages/list-messages.d.mts.map +0 -1
- package/tools/messages/list-messages.d.ts +0 -45
- package/tools/messages/list-messages.d.ts.map +0 -1
- package/tools/messages/list-messages.js +0 -47
- package/tools/messages/list-messages.js.map +0 -1
- package/tools/messages/list-messages.mjs +0 -43
- package/tools/messages/list-messages.mjs.map +0 -1
- package/tools/messages/search-messages.d.mts +0 -45
- package/tools/messages/search-messages.d.mts.map +0 -1
- package/tools/messages/search-messages.d.ts +0 -45
- package/tools/messages/search-messages.d.ts.map +0 -1
- package/tools/messages/search-messages.js +0 -110
- package/tools/messages/search-messages.js.map +0 -1
- package/tools/messages/search-messages.mjs +0 -106
- package/tools/messages/search-messages.mjs.map +0 -1
- package/tools/messages/send-message.d.mts +0 -45
- package/tools/messages/send-message.d.mts.map +0 -1
- package/tools/messages/send-message.d.ts +0 -45
- package/tools/messages/send-message.d.ts.map +0 -1
- package/tools/messages/send-message.js +0 -43
- package/tools/messages/send-message.js.map +0 -1
- package/tools/messages/send-message.mjs +0 -39
- package/tools/messages/send-message.mjs.map +0 -1
- package/tools/top-level/focus-app.d.mts +0 -45
- package/tools/top-level/focus-app.d.mts.map +0 -1
- package/tools/top-level/focus-app.d.ts +0 -45
- package/tools/top-level/focus-app.d.ts.map +0 -1
- package/tools/top-level/focus-app.js +0 -47
- package/tools/top-level/focus-app.js.map +0 -1
- package/tools/top-level/focus-app.mjs +0 -43
- package/tools/top-level/focus-app.mjs.map +0 -1
- package/tools/top-level/search.d.mts +0 -45
- package/tools/top-level/search.d.mts.map +0 -1
- package/tools/top-level/search.d.ts +0 -45
- package/tools/top-level/search.d.ts.map +0 -1
- package/tools/top-level/search.js +0 -37
- package/tools/top-level/search.js.map +0 -1
- package/tools/top-level/search.mjs +0 -33
- package/tools/top-level/search.mjs.map +0 -1
- package/tools/types.d.mts.map +0 -1
- package/tools/types.d.ts.map +0 -1
- package/tools/types.js.map +0 -1
- package/tools/types.mjs.map +0 -1
- package/tools.d.mts +0 -2
- package/tools.d.mts.map +0 -1
- package/tools.d.ts +0 -2
- package/tools.d.ts.map +0 -1
- package/tools.js +0 -18
- package/tools.js.map +0 -1
- package/tools.mjs +0 -2
- package/tools.mjs.map +0 -1
package/src/http.ts
CHANGED
|
@@ -2,22 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
|
|
4
4
|
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
5
|
-
|
|
5
|
+
import { ClientOptions } from '@beeper/desktop-api';
|
|
6
6
|
import cors from 'cors';
|
|
7
7
|
import express from 'express';
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
8
|
+
import pino from 'pino';
|
|
9
|
+
import pinoHttp from 'pino-http';
|
|
10
|
+
import { getStainlessApiKey, parseClientAuthHeaders } from './auth';
|
|
11
|
+
import { getLogger } from './logger';
|
|
12
|
+
import { McpOptions } from './options';
|
|
13
|
+
import { initMcpServer, newMcpServer } from './server';
|
|
12
14
|
|
|
13
15
|
const oauthResourceIdentifier = (req: express.Request): string => {
|
|
14
16
|
const protocol = req.headers['x-forwarded-proto'] ?? req.protocol;
|
|
15
17
|
return `${protocol}://${req.get('host')}/`;
|
|
16
18
|
};
|
|
17
19
|
|
|
18
|
-
const newServer = ({
|
|
20
|
+
const newServer = async ({
|
|
19
21
|
clientOptions,
|
|
20
|
-
mcpOptions
|
|
22
|
+
mcpOptions,
|
|
21
23
|
req,
|
|
22
24
|
res,
|
|
23
25
|
}: {
|
|
@@ -25,34 +27,18 @@ const newServer = ({
|
|
|
25
27
|
mcpOptions: McpOptions;
|
|
26
28
|
req: express.Request;
|
|
27
29
|
res: express.Response;
|
|
28
|
-
}): McpServer | null => {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
}): Promise<McpServer | null> => {
|
|
31
|
+
const stainlessApiKey = getStainlessApiKey(req, mcpOptions);
|
|
32
|
+
const server = await newMcpServer(stainlessApiKey);
|
|
33
|
+
|
|
34
|
+
// parseClientAuthHeaders throws if the Authorization header uses an unsupported
|
|
35
|
+
// scheme, or (when the second arg is true) if the header is missing entirely.
|
|
36
|
+
// On error, we return 401 with WWW-Authenticate pointing to the OAuth metadata
|
|
37
|
+
// endpoint so clients know how to authenticate (RFC 9728).
|
|
38
|
+
let authOptions: Partial<ClientOptions>;
|
|
32
39
|
try {
|
|
33
|
-
|
|
40
|
+
authOptions = parseClientAuthHeaders(req, false);
|
|
34
41
|
} catch (error) {
|
|
35
|
-
res.status(400).json({
|
|
36
|
-
jsonrpc: '2.0',
|
|
37
|
-
error: {
|
|
38
|
-
code: -32000,
|
|
39
|
-
message: `Invalid request: ${fromError(error)}`,
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
const authOptions = parseAuthHeaders(req);
|
|
47
|
-
initMcpServer({
|
|
48
|
-
server: server,
|
|
49
|
-
clientOptions: {
|
|
50
|
-
...clientOptions,
|
|
51
|
-
...authOptions,
|
|
52
|
-
},
|
|
53
|
-
mcpOptions,
|
|
54
|
-
});
|
|
55
|
-
} catch {
|
|
56
42
|
const resourceIdentifier = oauthResourceIdentifier(req);
|
|
57
43
|
res.set(
|
|
58
44
|
'WWW-Authenticate',
|
|
@@ -62,30 +48,37 @@ const newServer = ({
|
|
|
62
48
|
jsonrpc: '2.0',
|
|
63
49
|
error: {
|
|
64
50
|
code: -32000,
|
|
65
|
-
message:
|
|
51
|
+
message: `Unauthorized: ${error instanceof Error ? error.message : error}`,
|
|
66
52
|
},
|
|
67
53
|
});
|
|
68
54
|
return null;
|
|
69
55
|
}
|
|
70
56
|
|
|
57
|
+
await initMcpServer({
|
|
58
|
+
server: server,
|
|
59
|
+
mcpOptions: mcpOptions,
|
|
60
|
+
clientOptions: {
|
|
61
|
+
...clientOptions,
|
|
62
|
+
...authOptions,
|
|
63
|
+
},
|
|
64
|
+
stainlessApiKey: stainlessApiKey,
|
|
65
|
+
});
|
|
66
|
+
|
|
71
67
|
return server;
|
|
72
68
|
};
|
|
73
69
|
|
|
74
|
-
|
|
70
|
+
const post =
|
|
75
71
|
(options: { clientOptions: ClientOptions; mcpOptions: McpOptions }) =>
|
|
76
72
|
async (req: express.Request, res: express.Response) => {
|
|
77
|
-
const server = newServer({ ...options, req, res });
|
|
73
|
+
const server = await newServer({ ...options, req, res });
|
|
78
74
|
// If we return null, we already set the authorization error.
|
|
79
75
|
if (server === null) return;
|
|
80
|
-
const transport = new StreamableHTTPServerTransport(
|
|
81
|
-
|
|
82
|
-
sessionIdGenerator: undefined,
|
|
83
|
-
});
|
|
84
|
-
await server.connect(transport);
|
|
76
|
+
const transport = new StreamableHTTPServerTransport();
|
|
77
|
+
await server.connect(transport as any);
|
|
85
78
|
await transport.handleRequest(req, res, req.body);
|
|
86
79
|
};
|
|
87
80
|
|
|
88
|
-
|
|
81
|
+
const get = async (req: express.Request, res: express.Response) => {
|
|
89
82
|
res.status(405).json({
|
|
90
83
|
jsonrpc: '2.0',
|
|
91
84
|
error: {
|
|
@@ -95,7 +88,7 @@ export const get = async (req: express.Request, res: express.Response) => {
|
|
|
95
88
|
});
|
|
96
89
|
};
|
|
97
90
|
|
|
98
|
-
|
|
91
|
+
const del = async (req: express.Request, res: express.Response) => {
|
|
99
92
|
res.status(405).json({
|
|
100
93
|
jsonrpc: '2.0',
|
|
101
94
|
error: {
|
|
@@ -115,18 +108,66 @@ const oauthMetadata = (req: express.Request, res: express.Response) => {
|
|
|
115
108
|
});
|
|
116
109
|
};
|
|
117
110
|
|
|
111
|
+
const redactHeaders = (headers: Record<string, any>) => {
|
|
112
|
+
const hiddenHeaders = /auth|cookie|key|token/i;
|
|
113
|
+
const filtered = { ...headers };
|
|
114
|
+
Object.keys(filtered).forEach((key) => {
|
|
115
|
+
if (hiddenHeaders.test(key)) {
|
|
116
|
+
filtered[key] = '[REDACTED]';
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
return filtered;
|
|
120
|
+
};
|
|
121
|
+
|
|
118
122
|
export const streamableHTTPApp = ({
|
|
119
123
|
clientOptions = {},
|
|
120
|
-
mcpOptions
|
|
124
|
+
mcpOptions,
|
|
121
125
|
}: {
|
|
122
126
|
clientOptions?: ClientOptions;
|
|
123
|
-
mcpOptions
|
|
127
|
+
mcpOptions: McpOptions;
|
|
124
128
|
}): express.Express => {
|
|
125
129
|
const app = express();
|
|
126
130
|
app.set('query parser', 'extended');
|
|
127
131
|
app.use(express.json());
|
|
132
|
+
app.use(
|
|
133
|
+
pinoHttp({
|
|
134
|
+
logger: getLogger(),
|
|
135
|
+
customLogLevel: (req, res) => {
|
|
136
|
+
if (res.statusCode >= 500) {
|
|
137
|
+
return 'error';
|
|
138
|
+
} else if (res.statusCode >= 400) {
|
|
139
|
+
return 'warn';
|
|
140
|
+
}
|
|
141
|
+
return 'info';
|
|
142
|
+
},
|
|
143
|
+
customSuccessMessage: function (req, res) {
|
|
144
|
+
return `Request ${req.method} to ${req.url} completed with status ${res.statusCode}`;
|
|
145
|
+
},
|
|
146
|
+
customErrorMessage: function (req, res, err) {
|
|
147
|
+
return `Request ${req.method} to ${req.url} errored with status ${res.statusCode}`;
|
|
148
|
+
},
|
|
149
|
+
serializers: {
|
|
150
|
+
req: pino.stdSerializers.wrapRequestSerializer((req) => {
|
|
151
|
+
return {
|
|
152
|
+
...req,
|
|
153
|
+
headers: redactHeaders(req.raw.headers),
|
|
154
|
+
};
|
|
155
|
+
}),
|
|
156
|
+
res: pino.stdSerializers.wrapResponseSerializer((res) => {
|
|
157
|
+
return {
|
|
158
|
+
...res,
|
|
159
|
+
headers: redactHeaders(res.headers),
|
|
160
|
+
};
|
|
161
|
+
}),
|
|
162
|
+
},
|
|
163
|
+
}),
|
|
164
|
+
);
|
|
128
165
|
|
|
129
166
|
app.get('/.well-known/oauth-protected-resource', cors(), oauthMetadata);
|
|
167
|
+
|
|
168
|
+
app.get('/health', async (req: express.Request, res: express.Response) => {
|
|
169
|
+
res.status(200).send('OK');
|
|
170
|
+
});
|
|
130
171
|
app.get('/', get);
|
|
131
172
|
app.post('/', post({ clientOptions, mcpOptions }));
|
|
132
173
|
app.delete('/', del);
|
|
@@ -134,16 +175,24 @@ export const streamableHTTPApp = ({
|
|
|
134
175
|
return app;
|
|
135
176
|
};
|
|
136
177
|
|
|
137
|
-
export const launchStreamableHTTPServer = async (
|
|
138
|
-
|
|
178
|
+
export const launchStreamableHTTPServer = async ({
|
|
179
|
+
mcpOptions,
|
|
180
|
+
port,
|
|
181
|
+
}: {
|
|
182
|
+
mcpOptions: McpOptions;
|
|
183
|
+
port: number | string | undefined;
|
|
184
|
+
}) => {
|
|
185
|
+
const app = streamableHTTPApp({ mcpOptions });
|
|
139
186
|
const server = app.listen(port);
|
|
140
187
|
const address = server.address();
|
|
141
188
|
|
|
189
|
+
const logger = getLogger();
|
|
190
|
+
|
|
142
191
|
if (typeof address === 'string') {
|
|
143
|
-
|
|
192
|
+
logger.info(`MCP Server running on streamable HTTP at ${address}`);
|
|
144
193
|
} else if (address !== null) {
|
|
145
|
-
|
|
194
|
+
logger.info(`MCP Server running on streamable HTTP on port ${address.port}`);
|
|
146
195
|
} else {
|
|
147
|
-
|
|
196
|
+
logger.info(`MCP Server running on streamable HTTP on port ${port}`);
|
|
148
197
|
}
|
|
149
198
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { selectTools } from './server';
|
|
4
|
-
import { Endpoint, endpoints } from './tools';
|
|
5
4
|
import { McpOptions, parseCLIOptions } from './options';
|
|
6
5
|
import { launchStdioServer } from './stdio';
|
|
7
6
|
import { launchStreamableHTTPServer } from './http';
|
|
7
|
+
import type { McpTool } from './types';
|
|
8
|
+
import { configureLogger, getLogger } from './logger';
|
|
8
9
|
|
|
9
10
|
async function main() {
|
|
10
11
|
const options = parseOptionsOrError();
|
|
12
|
+
configureLogger({
|
|
13
|
+
level: options.debug ? 'debug' : 'info',
|
|
14
|
+
pretty: options.logFormat === 'pretty',
|
|
15
|
+
});
|
|
11
16
|
|
|
12
|
-
|
|
13
|
-
listAllTools();
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const selectedTools = await selectToolsOrError(endpoints, options);
|
|
17
|
+
const selectedTools = await selectToolsOrError(options);
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
selectedTools.
|
|
19
|
+
getLogger().info(
|
|
20
|
+
{ tools: selectedTools.map((e) => e.tool.name) },
|
|
21
|
+
`MCP Server starting with ${selectedTools.length} tools`,
|
|
22
22
|
);
|
|
23
23
|
|
|
24
24
|
switch (options.transport) {
|
|
@@ -26,14 +26,18 @@ async function main() {
|
|
|
26
26
|
await launchStdioServer(options);
|
|
27
27
|
break;
|
|
28
28
|
case 'http':
|
|
29
|
-
await launchStreamableHTTPServer(
|
|
29
|
+
await launchStreamableHTTPServer({
|
|
30
|
+
mcpOptions: options,
|
|
31
|
+
port: options.socket ?? options.port,
|
|
32
|
+
});
|
|
30
33
|
break;
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
if (require.main === module) {
|
|
35
38
|
main().catch((error) => {
|
|
36
|
-
|
|
39
|
+
// Logger might not be initialized yet
|
|
40
|
+
console.error('Fatal error in main()', error);
|
|
37
41
|
process.exit(1);
|
|
38
42
|
});
|
|
39
43
|
}
|
|
@@ -42,67 +46,22 @@ function parseOptionsOrError() {
|
|
|
42
46
|
try {
|
|
43
47
|
return parseCLIOptions();
|
|
44
48
|
} catch (error) {
|
|
45
|
-
|
|
49
|
+
// Logger is initialized after options, so use console.error here
|
|
50
|
+
console.error('Error parsing options', error);
|
|
46
51
|
process.exit(1);
|
|
47
52
|
}
|
|
48
53
|
}
|
|
49
54
|
|
|
50
|
-
async function selectToolsOrError(
|
|
55
|
+
async function selectToolsOrError(options: McpOptions): Promise<McpTool[]> {
|
|
51
56
|
try {
|
|
52
|
-
const includedTools =
|
|
57
|
+
const includedTools = selectTools(options);
|
|
53
58
|
if (includedTools.length === 0) {
|
|
54
|
-
|
|
59
|
+
getLogger().error('No tools match the provided filters');
|
|
55
60
|
process.exit(1);
|
|
56
61
|
}
|
|
57
62
|
return includedTools;
|
|
58
63
|
} catch (error) {
|
|
59
|
-
|
|
60
|
-
console.error('Error filtering tools:', error.message);
|
|
61
|
-
} else {
|
|
62
|
-
console.error('Error filtering tools:', error);
|
|
63
|
-
}
|
|
64
|
+
getLogger().error({ error }, 'Error filtering tools');
|
|
64
65
|
process.exit(1);
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
|
-
|
|
68
|
-
function listAllTools() {
|
|
69
|
-
if (endpoints.length === 0) {
|
|
70
|
-
console.log('No tools available.');
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
console.log('Available tools:\n');
|
|
74
|
-
|
|
75
|
-
// Group endpoints by resource
|
|
76
|
-
const resourceGroups = new Map<string, typeof endpoints>();
|
|
77
|
-
|
|
78
|
-
for (const endpoint of endpoints) {
|
|
79
|
-
const resource = endpoint.metadata.resource;
|
|
80
|
-
if (!resourceGroups.has(resource)) {
|
|
81
|
-
resourceGroups.set(resource, []);
|
|
82
|
-
}
|
|
83
|
-
resourceGroups.get(resource)!.push(endpoint);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Sort resources alphabetically
|
|
87
|
-
const sortedResources = Array.from(resourceGroups.keys()).sort();
|
|
88
|
-
|
|
89
|
-
// Display hierarchically by resource
|
|
90
|
-
for (const resource of sortedResources) {
|
|
91
|
-
console.log(`Resource: ${resource}`);
|
|
92
|
-
|
|
93
|
-
const resourceEndpoints = resourceGroups.get(resource)!;
|
|
94
|
-
// Sort endpoints by tool name
|
|
95
|
-
resourceEndpoints.sort((a, b) => a.tool.name.localeCompare(b.tool.name));
|
|
96
|
-
|
|
97
|
-
for (const endpoint of resourceEndpoints) {
|
|
98
|
-
const {
|
|
99
|
-
tool,
|
|
100
|
-
metadata: { operation, tags },
|
|
101
|
-
} = endpoint;
|
|
102
|
-
|
|
103
|
-
console.log(` - ${tool.name} (${operation}) ${tags.length > 0 ? `tags: ${tags.join(', ')}` : ''}`);
|
|
104
|
-
console.log(` Description: ${tool.description}`);
|
|
105
|
-
}
|
|
106
|
-
console.log('');
|
|
107
|
-
}
|
|
108
|
-
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { readEnv } from './util';
|
|
4
|
+
import { getLogger } from './logger';
|
|
5
|
+
|
|
6
|
+
const INSTRUCTIONS_CACHE_TTL_MS = 15 * 60 * 1000; // 15 minutes
|
|
7
|
+
|
|
8
|
+
interface InstructionsCacheEntry {
|
|
9
|
+
fetchedInstructions: string;
|
|
10
|
+
fetchedAt: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const instructionsCache = new Map<string, InstructionsCacheEntry>();
|
|
14
|
+
|
|
15
|
+
// Periodically evict stale entries so the cache doesn't grow unboundedly.
|
|
16
|
+
const _cacheCleanupInterval = setInterval(() => {
|
|
17
|
+
const now = Date.now();
|
|
18
|
+
for (const [key, entry] of instructionsCache) {
|
|
19
|
+
if (now - entry.fetchedAt > INSTRUCTIONS_CACHE_TTL_MS) {
|
|
20
|
+
instructionsCache.delete(key);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}, INSTRUCTIONS_CACHE_TTL_MS);
|
|
24
|
+
|
|
25
|
+
// Don't keep the process alive just for cleanup.
|
|
26
|
+
_cacheCleanupInterval.unref();
|
|
27
|
+
|
|
28
|
+
export async function getInstructions(stainlessApiKey: string | undefined): Promise<string> {
|
|
29
|
+
const cacheKey = stainlessApiKey ?? '';
|
|
30
|
+
const cached = instructionsCache.get(cacheKey);
|
|
31
|
+
|
|
32
|
+
if (cached && Date.now() - cached.fetchedAt <= INSTRUCTIONS_CACHE_TTL_MS) {
|
|
33
|
+
return cached.fetchedInstructions;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const fetchedInstructions = await fetchLatestInstructions(stainlessApiKey);
|
|
37
|
+
instructionsCache.set(cacheKey, { fetchedInstructions, fetchedAt: Date.now() });
|
|
38
|
+
return fetchedInstructions;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function fetchLatestInstructions(stainlessApiKey: string | undefined): Promise<string> {
|
|
42
|
+
// Setting the stainless API key is optional, but may be required
|
|
43
|
+
// to authenticate requests to the Stainless API.
|
|
44
|
+
const response = await fetch(
|
|
45
|
+
readEnv('CODE_MODE_INSTRUCTIONS_URL') ??
|
|
46
|
+
'https://api.stainless.com/api/ai/instructions/beeper-desktop-api',
|
|
47
|
+
{
|
|
48
|
+
method: 'GET',
|
|
49
|
+
headers: { ...(stainlessApiKey && { Authorization: stainlessApiKey }) },
|
|
50
|
+
},
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
let instructions: string | undefined;
|
|
54
|
+
if (!response.ok) {
|
|
55
|
+
getLogger().warn(
|
|
56
|
+
'Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...',
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
instructions =
|
|
60
|
+
'\n This is the beeper-desktop-api MCP server.\n\n Available tools:\n - search_docs: Search SDK documentation to find the right methods and parameters.\n - execute: Run TypeScript code against a pre-authenticated SDK client. Define an async run(client) function.\n\n Workflow:\n - If unsure about the API, call search_docs first.\n - Write complete solutions in a single execute call when possible. For large datasets, use API filters to narrow results or paginate within a single execute block.\n - If execute returns an error, read the error and fix your code rather than retrying the same approach.\n - Variables do not persist between execute calls. Return or log all data you need.\n - Individual HTTP requests to the API have a 30-second timeout. If a request times out, try a smaller query or add filters.\n - Code execution has a total timeout of approximately 5 minutes. If your code times out, simplify it or break it into smaller steps.\n ';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
instructions ??= ((await response.json()) as { instructions: string }).instructions;
|
|
64
|
+
|
|
65
|
+
instructions += `\nAccess to all chats and messages across networks using Beeper Desktop. Can be used to find, get, send, and manage messages and chats.`;
|
|
66
|
+
return instructions;
|
|
67
|
+
}
|
package/src/logger.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { pino, type Level, type Logger } from 'pino';
|
|
4
|
+
import pretty from 'pino-pretty';
|
|
5
|
+
|
|
6
|
+
let _logger: Logger | undefined;
|
|
7
|
+
|
|
8
|
+
export function configureLogger({ level, pretty: usePretty }: { level: Level; pretty: boolean }): void {
|
|
9
|
+
_logger = pino(
|
|
10
|
+
{
|
|
11
|
+
level,
|
|
12
|
+
timestamp: pino.stdTimeFunctions.isoTime,
|
|
13
|
+
formatters: {
|
|
14
|
+
level(label) {
|
|
15
|
+
return { level: label };
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
usePretty ? pretty({ colorize: true, levelFirst: true, destination: 2 }) : process.stderr,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getLogger(): Logger {
|
|
24
|
+
if (!_logger) {
|
|
25
|
+
throw new Error('Logger has not been configured. Call configureLogger() before using the logger.');
|
|
26
|
+
}
|
|
27
|
+
return _logger;
|
|
28
|
+
}
|
package/src/methods.ts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { McpOptions } from './options';
|
|
4
|
+
|
|
5
|
+
export type SdkMethod = {
|
|
6
|
+
clientCallName: string;
|
|
7
|
+
fullyQualifiedName: string;
|
|
8
|
+
httpMethod?: 'get' | 'post' | 'put' | 'patch' | 'delete' | 'query';
|
|
9
|
+
httpPath?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const sdkMethods: SdkMethod[] = [
|
|
13
|
+
{
|
|
14
|
+
clientCallName: 'client.focus',
|
|
15
|
+
fullyQualifiedName: 'focus',
|
|
16
|
+
httpMethod: 'post',
|
|
17
|
+
httpPath: '/v1/focus',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
clientCallName: 'client.search',
|
|
21
|
+
fullyQualifiedName: 'search',
|
|
22
|
+
httpMethod: 'get',
|
|
23
|
+
httpPath: '/v1/search',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
clientCallName: 'client.accounts.list',
|
|
27
|
+
fullyQualifiedName: 'accounts.list',
|
|
28
|
+
httpMethod: 'get',
|
|
29
|
+
httpPath: '/v1/accounts',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
clientCallName: 'client.accounts.contacts.list',
|
|
33
|
+
fullyQualifiedName: 'accounts.contacts.list',
|
|
34
|
+
httpMethod: 'get',
|
|
35
|
+
httpPath: '/v1/accounts/{accountID}/contacts/list',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
clientCallName: 'client.accounts.contacts.search',
|
|
39
|
+
fullyQualifiedName: 'accounts.contacts.search',
|
|
40
|
+
httpMethod: 'get',
|
|
41
|
+
httpPath: '/v1/accounts/{accountID}/contacts',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
clientCallName: 'client.chats.create',
|
|
45
|
+
fullyQualifiedName: 'chats.create',
|
|
46
|
+
httpMethod: 'post',
|
|
47
|
+
httpPath: '/v1/chats',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
clientCallName: 'client.chats.retrieve',
|
|
51
|
+
fullyQualifiedName: 'chats.retrieve',
|
|
52
|
+
httpMethod: 'get',
|
|
53
|
+
httpPath: '/v1/chats/{chatID}',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
clientCallName: 'client.chats.list',
|
|
57
|
+
fullyQualifiedName: 'chats.list',
|
|
58
|
+
httpMethod: 'get',
|
|
59
|
+
httpPath: '/v1/chats',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
clientCallName: 'client.chats.archive',
|
|
63
|
+
fullyQualifiedName: 'chats.archive',
|
|
64
|
+
httpMethod: 'post',
|
|
65
|
+
httpPath: '/v1/chats/{chatID}/archive',
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
clientCallName: 'client.chats.search',
|
|
69
|
+
fullyQualifiedName: 'chats.search',
|
|
70
|
+
httpMethod: 'get',
|
|
71
|
+
httpPath: '/v1/chats/search',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
clientCallName: 'client.chats.reminders.create',
|
|
75
|
+
fullyQualifiedName: 'chats.reminders.create',
|
|
76
|
+
httpMethod: 'post',
|
|
77
|
+
httpPath: '/v1/chats/{chatID}/reminders',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
clientCallName: 'client.chats.reminders.delete',
|
|
81
|
+
fullyQualifiedName: 'chats.reminders.delete',
|
|
82
|
+
httpMethod: 'delete',
|
|
83
|
+
httpPath: '/v1/chats/{chatID}/reminders',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
clientCallName: 'client.chats.messages.reactions.delete',
|
|
87
|
+
fullyQualifiedName: 'chats.messages.reactions.delete',
|
|
88
|
+
httpMethod: 'delete',
|
|
89
|
+
httpPath: '/v1/chats/{chatID}/messages/{messageID}/reactions',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
clientCallName: 'client.chats.messages.reactions.add',
|
|
93
|
+
fullyQualifiedName: 'chats.messages.reactions.add',
|
|
94
|
+
httpMethod: 'post',
|
|
95
|
+
httpPath: '/v1/chats/{chatID}/messages/{messageID}/reactions',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
clientCallName: 'client.messages.update',
|
|
99
|
+
fullyQualifiedName: 'messages.update',
|
|
100
|
+
httpMethod: 'put',
|
|
101
|
+
httpPath: '/v1/chats/{chatID}/messages/{messageID}',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
clientCallName: 'client.messages.list',
|
|
105
|
+
fullyQualifiedName: 'messages.list',
|
|
106
|
+
httpMethod: 'get',
|
|
107
|
+
httpPath: '/v1/chats/{chatID}/messages',
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
clientCallName: 'client.messages.search',
|
|
111
|
+
fullyQualifiedName: 'messages.search',
|
|
112
|
+
httpMethod: 'get',
|
|
113
|
+
httpPath: '/v1/messages/search',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
clientCallName: 'client.messages.send',
|
|
117
|
+
fullyQualifiedName: 'messages.send',
|
|
118
|
+
httpMethod: 'post',
|
|
119
|
+
httpPath: '/v1/chats/{chatID}/messages',
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
clientCallName: 'client.assets.download',
|
|
123
|
+
fullyQualifiedName: 'assets.download',
|
|
124
|
+
httpMethod: 'post',
|
|
125
|
+
httpPath: '/v1/assets/download',
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
clientCallName: 'client.assets.serve',
|
|
129
|
+
fullyQualifiedName: 'assets.serve',
|
|
130
|
+
httpMethod: 'get',
|
|
131
|
+
httpPath: '/v1/assets/serve',
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
clientCallName: 'client.assets.upload',
|
|
135
|
+
fullyQualifiedName: 'assets.upload',
|
|
136
|
+
httpMethod: 'post',
|
|
137
|
+
httpPath: '/v1/assets/upload',
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
clientCallName: 'client.assets.uploadBase64',
|
|
141
|
+
fullyQualifiedName: 'assets.uploadBase64',
|
|
142
|
+
httpMethod: 'post',
|
|
143
|
+
httpPath: '/v1/assets/upload/base64',
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
clientCallName: 'client.info.retrieve',
|
|
147
|
+
fullyQualifiedName: 'info.retrieve',
|
|
148
|
+
httpMethod: 'get',
|
|
149
|
+
httpPath: '/v1/info',
|
|
150
|
+
},
|
|
151
|
+
];
|
|
152
|
+
|
|
153
|
+
function allowedMethodsForCodeTool(options: McpOptions | undefined): SdkMethod[] | undefined {
|
|
154
|
+
if (!options) {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let allowedMethods: SdkMethod[];
|
|
159
|
+
|
|
160
|
+
if (options.codeAllowHttpGets || options.codeAllowedMethods) {
|
|
161
|
+
// Start with nothing allowed and then add into it from options
|
|
162
|
+
let allowedMethodsSet = new Set<SdkMethod>();
|
|
163
|
+
|
|
164
|
+
if (options.codeAllowHttpGets) {
|
|
165
|
+
// Add all methods that map to an HTTP GET
|
|
166
|
+
sdkMethods
|
|
167
|
+
.filter((method) => method.httpMethod === 'get')
|
|
168
|
+
.forEach((method) => allowedMethodsSet.add(method));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (options.codeAllowedMethods) {
|
|
172
|
+
// Add all methods that match any of the allowed regexps
|
|
173
|
+
const allowedRegexps = options.codeAllowedMethods.map((pattern) => {
|
|
174
|
+
try {
|
|
175
|
+
return new RegExp(pattern);
|
|
176
|
+
} catch (e) {
|
|
177
|
+
throw new Error(
|
|
178
|
+
`Invalid regex pattern for allowed method: "${pattern}": ${e instanceof Error ? e.message : e}`,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
sdkMethods
|
|
184
|
+
.filter((method) => allowedRegexps.some((regexp) => regexp.test(method.fullyQualifiedName)))
|
|
185
|
+
.forEach((method) => allowedMethodsSet.add(method));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
allowedMethods = Array.from(allowedMethodsSet);
|
|
189
|
+
} else {
|
|
190
|
+
// Start with everything allowed
|
|
191
|
+
allowedMethods = [...sdkMethods];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (options.codeBlockedMethods) {
|
|
195
|
+
// Filter down based on blocked regexps
|
|
196
|
+
const blockedRegexps = options.codeBlockedMethods.map((pattern) => {
|
|
197
|
+
try {
|
|
198
|
+
return new RegExp(pattern);
|
|
199
|
+
} catch (e) {
|
|
200
|
+
throw new Error(
|
|
201
|
+
`Invalid regex pattern for blocked method: "${pattern}": ${e instanceof Error ? e.message : e}`,
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
allowedMethods = allowedMethods.filter(
|
|
207
|
+
(method) => !blockedRegexps.some((regexp) => regexp.test(method.fullyQualifiedName)),
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return allowedMethods;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function blockedMethodsForCodeTool(options: McpOptions | undefined): SdkMethod[] | undefined {
|
|
215
|
+
const allowedMethods = allowedMethodsForCodeTool(options);
|
|
216
|
+
if (!allowedMethods) {
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const allowedSet = new Set(allowedMethods.map((method) => method.fullyQualifiedName));
|
|
221
|
+
|
|
222
|
+
// Return any methods that are not explicitly allowed
|
|
223
|
+
return sdkMethods.filter((method) => !allowedSet.has(method.fullyQualifiedName));
|
|
224
|
+
}
|