@dereekb/firebase-server 13.14.0 → 13.16.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/index.cjs.js +46 -38
- package/index.esm.js +47 -39
- package/mailgun/package.json +9 -9
- package/mcp/index.cjs.js +1180 -215
- package/mcp/index.esm.js +1175 -218
- package/mcp/package.json +11 -11
- package/mcp/src/lib/service/index.d.ts +1 -0
- package/mcp/src/lib/service/mcp.server.factory.d.ts +30 -2
- package/mcp/src/lib/service/tools/mcp.tool.batch-execute.d.ts +151 -0
- package/model/index.cjs.js +216 -222
- package/model/index.esm.js +217 -223
- package/model/package.json +9 -9
- package/oidc/index.cjs.js +8 -8
- package/oidc/index.esm.js +8 -8
- package/oidc/package.json +10 -10
- package/package.json +10 -10
- package/src/lib/auth/auth.service.d.ts +23 -3
- package/test/index.cjs.js +3 -3
- package/test/index.esm.js +3 -3
- package/test/package.json +11 -11
- package/twilio/package.json +8 -8
- package/zoho/index.cjs.js +3 -3
- package/zoho/index.esm.js +3 -3
- package/zoho/package.json +9 -9
package/mcp/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dereekb/firebase-server/mcp",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.16.0",
|
|
4
4
|
"peerDependencies": {
|
|
5
|
-
"@dereekb/analytics": "13.
|
|
6
|
-
"@dereekb/date": "13.
|
|
7
|
-
"@dereekb/firebase": "13.
|
|
8
|
-
"@dereekb/firebase-server": "13.
|
|
9
|
-
"@dereekb/firebase-server/oidc": "13.
|
|
10
|
-
"@dereekb/model": "13.
|
|
11
|
-
"@dereekb/nestjs": "13.
|
|
12
|
-
"@dereekb/rxjs": "13.
|
|
13
|
-
"@dereekb/util": "13.
|
|
14
|
-
"@dereekb/zoho": "13.
|
|
5
|
+
"@dereekb/analytics": "13.16.0",
|
|
6
|
+
"@dereekb/date": "13.16.0",
|
|
7
|
+
"@dereekb/firebase": "13.16.0",
|
|
8
|
+
"@dereekb/firebase-server": "13.16.0",
|
|
9
|
+
"@dereekb/firebase-server/oidc": "13.16.0",
|
|
10
|
+
"@dereekb/model": "13.16.0",
|
|
11
|
+
"@dereekb/nestjs": "13.16.0",
|
|
12
|
+
"@dereekb/rxjs": "13.16.0",
|
|
13
|
+
"@dereekb/util": "13.16.0",
|
|
14
|
+
"@dereekb/zoho": "13.16.0",
|
|
15
15
|
"@modelcontextprotocol/sdk": "1.29.0",
|
|
16
16
|
"@nestjs/common": "^11.1.19",
|
|
17
17
|
"@nestjs/core": "^11.1.19",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import { type Request } from 'express';
|
|
3
|
-
import { ModelApiCallModelDispatchService, ModelApiGetService, type FirebaseServerAuthData } from '@dereekb/firebase-server';
|
|
3
|
+
import { ModelApiCallModelDispatchService, ModelApiGetService, FirebaseServerStorageService, type FirebaseServerAuthData } from '@dereekb/firebase-server';
|
|
4
4
|
import { McpModuleConfig, type McpAuthRoleReader } from '../mcp.config';
|
|
5
5
|
import { type McpAnalyticsService } from './analytics/mcp.analytics.handler';
|
|
6
6
|
/**
|
|
@@ -26,6 +26,7 @@ export declare class McpServerFactoryService {
|
|
|
26
26
|
private readonly dispatchService;
|
|
27
27
|
private readonly modelApiGetService?;
|
|
28
28
|
private readonly roleReader?;
|
|
29
|
+
private readonly storageService?;
|
|
29
30
|
private readonly _logger;
|
|
30
31
|
private _cachedTools;
|
|
31
32
|
private _cachedStaticTools;
|
|
@@ -36,7 +37,7 @@ export declare class McpServerFactoryService {
|
|
|
36
37
|
private _loggedSkips;
|
|
37
38
|
private _warnedMissingRoleReader;
|
|
38
39
|
private readonly _analyticsService;
|
|
39
|
-
constructor(mcpConfig: McpModuleConfig, dispatchService: ModelApiCallModelDispatchService, modelApiGetService?: ModelApiGetService | undefined, roleReader?: McpAuthRoleReader | undefined, analyticsService?: McpAnalyticsService);
|
|
40
|
+
constructor(mcpConfig: McpModuleConfig, dispatchService: ModelApiCallModelDispatchService, modelApiGetService?: ModelApiGetService | undefined, roleReader?: McpAuthRoleReader | undefined, analyticsService?: McpAnalyticsService, storageService?: FirebaseServerStorageService | undefined);
|
|
40
41
|
/**
|
|
41
42
|
* Builds a configured MCP server with tool listing + dispatch handlers wired up.
|
|
42
43
|
*
|
|
@@ -89,6 +90,33 @@ export declare class McpServerFactoryService {
|
|
|
89
90
|
* @returns The cached array of static tool definitions, filtered for collisions with generated tools.
|
|
90
91
|
*/
|
|
91
92
|
private _resolveStaticTools;
|
|
93
|
+
/**
|
|
94
|
+
* Builds the per-request `batch-execute` tool, or `undefined` when it should not be offered.
|
|
95
|
+
*
|
|
96
|
+
* Unlike the cached static tools this is rebuilt per request, because it closes over the caller's
|
|
97
|
+
* resolved visible tool set: each batched operation is authorized against exactly the callModel
|
|
98
|
+
* tools this caller may invoke directly. Offered only when a storage service is wired (it reads
|
|
99
|
+
* the uploaded operations file), the caller is authenticated, and the server is not in read-only
|
|
100
|
+
* mode (the tool performs writes).
|
|
101
|
+
*
|
|
102
|
+
* @param ctx - The per-request context (auth, raw request) forwarded to dispatched operations.
|
|
103
|
+
* @param definitionsByName - The caller's visible tool definitions, keyed by name.
|
|
104
|
+
* @returns The batch tool definition, or `undefined` when unavailable for this request.
|
|
105
|
+
*/
|
|
106
|
+
private _resolveBatchTool;
|
|
107
|
+
/**
|
|
108
|
+
* Authorizes a single batched operation against the caller's visible callModel tool coordinates.
|
|
109
|
+
*
|
|
110
|
+
* Re-applies the same gate the `tools/list` filter already enforced: an operation is allowed only
|
|
111
|
+
* when its `(call, modelType, specifier)` coordinate matches a tool this caller can see. This is
|
|
112
|
+
* the critical guard — `dispatchService.dispatch` bypasses the MCP visibility filter, so without
|
|
113
|
+
* this check a batch could reach scope-, role-, or read-only-gated handlers.
|
|
114
|
+
*
|
|
115
|
+
* @param operation - The operation to authorize.
|
|
116
|
+
* @param authorizedCoords - The set of dispatchable coordinate keys visible to this caller.
|
|
117
|
+
* @returns Whether the operation may be dispatched, with a reason when it may not.
|
|
118
|
+
*/
|
|
119
|
+
private _authorizeBatchOperation;
|
|
92
120
|
/**
|
|
93
121
|
* Reads the pre-rendered MCP manifest JSON once, validates its version, and caches the
|
|
94
122
|
* resulting `key → entry` map plus the optional `models` catalog for the process lifetime.
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { type Request } from 'express';
|
|
2
|
+
import { type StorageSlashPath, type StorageBucketId, type OnCallTypedModelParams } from '@dereekb/firebase';
|
|
3
|
+
import { type FirebaseServerStorageService, type FirebaseServerAuthData } from '@dereekb/firebase-server';
|
|
4
|
+
import { type Maybe } from '@dereekb/util';
|
|
5
|
+
import { type McpToolDefinition, type McpToolDispatchTarget } from '../mcp.tool-generator';
|
|
6
|
+
/**
|
|
7
|
+
* Reserved tool name for the built-in `batch-execute` static tool.
|
|
8
|
+
*/
|
|
9
|
+
export declare const BATCH_EXECUTE_TOOL_NAME = "batch-execute";
|
|
10
|
+
/**
|
|
11
|
+
* Synthetic call type used in the tool's dispatch identity (analytics only — the tool re-dispatches
|
|
12
|
+
* to other callModel tools rather than resolving a `batch` call type of its own).
|
|
13
|
+
*/
|
|
14
|
+
export declare const BATCH_EXECUTE_DISPATCH_CALL = "batch";
|
|
15
|
+
/**
|
|
16
|
+
* Synthetic model type used in the tool's dispatch identity. The tool isn't bound to a model type
|
|
17
|
+
* (each operation carries its own), so we use the literal "batch" as the identity. Apps avoiding
|
|
18
|
+
* collision should not register a real model literally named "batch".
|
|
19
|
+
*/
|
|
20
|
+
export declare const BATCH_EXECUTE_DISPATCH_MODEL_TYPE = "batch";
|
|
21
|
+
/**
|
|
22
|
+
* Default per-operation concurrency when the caller does not specify `maxParallel`.
|
|
23
|
+
*/
|
|
24
|
+
export declare const DEFAULT_BATCH_EXECUTE_MAX_PARALLEL = 5;
|
|
25
|
+
/**
|
|
26
|
+
* Hard upper bound on operations accepted in a single batch file, guarding against an
|
|
27
|
+
* accidentally enormous upload exhausting the function's memory/time budget.
|
|
28
|
+
*/
|
|
29
|
+
export declare const MAX_BATCH_EXECUTE_OPERATIONS = 1000;
|
|
30
|
+
/**
|
|
31
|
+
* Maximum bytes read from the operations file. NDJSON of typical CRUD payloads stays well under
|
|
32
|
+
* this; an oversized file is rejected rather than streamed.
|
|
33
|
+
*/
|
|
34
|
+
export declare const MAX_BATCH_EXECUTE_FILE_BYTES: number;
|
|
35
|
+
/**
|
|
36
|
+
* A single operation in the uploaded batch file — the same `(call, modelType, specifier?, data)`
|
|
37
|
+
* shape every other MCP tool ultimately dispatches.
|
|
38
|
+
*/
|
|
39
|
+
export type BatchExecuteOperation = OnCallTypedModelParams;
|
|
40
|
+
/**
|
|
41
|
+
* Result of authorizing one operation against the caller's visible tool set.
|
|
42
|
+
*
|
|
43
|
+
* `allowed: false` carries a human-readable reason so the pre-flight error names exactly which
|
|
44
|
+
* operation is forbidden and why (unknown coordinate vs. hidden-for-this-caller).
|
|
45
|
+
*/
|
|
46
|
+
export type BatchOperationAuthorization = {
|
|
47
|
+
readonly allowed: true;
|
|
48
|
+
} | {
|
|
49
|
+
readonly allowed: false;
|
|
50
|
+
readonly reason: string;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Dispatches one already-authorized operation through the callModel chain.
|
|
54
|
+
*
|
|
55
|
+
* Wired by the server factory to `ModelApiCallModelDispatchService.dispatch`, closing over the
|
|
56
|
+
* request's auth + raw request so each operation runs with the caller's identity and full
|
|
57
|
+
* per-handler param validation.
|
|
58
|
+
*/
|
|
59
|
+
export type BatchExecuteDispatchFn = (operation: OnCallTypedModelParams, auth: Maybe<FirebaseServerAuthData>, rawRequest: Request) => Promise<unknown>;
|
|
60
|
+
/**
|
|
61
|
+
* Constructor dependencies for {@link createBatchExecuteTool}.
|
|
62
|
+
*/
|
|
63
|
+
export interface CreateBatchExecuteToolDeps {
|
|
64
|
+
/**
|
|
65
|
+
* Reads the uploaded operations file from storage.
|
|
66
|
+
*/
|
|
67
|
+
readonly storageService: FirebaseServerStorageService;
|
|
68
|
+
/**
|
|
69
|
+
* Re-dispatches a single operation through the callModel chain.
|
|
70
|
+
*/
|
|
71
|
+
readonly dispatch: BatchExecuteDispatchFn;
|
|
72
|
+
/**
|
|
73
|
+
* Authorizes one operation against the request's visible tool set. Provided by the factory so the
|
|
74
|
+
* check uses the same scope / role / read-only filtering already applied to `tools/list`.
|
|
75
|
+
*/
|
|
76
|
+
readonly authorizeOperation: (operation: OnCallTypedModelParams) => BatchOperationAuthorization;
|
|
77
|
+
/**
|
|
78
|
+
* Overrides the maximum number of operations accepted per batch. Defaults to
|
|
79
|
+
* {@link MAX_BATCH_EXECUTE_OPERATIONS}.
|
|
80
|
+
*/
|
|
81
|
+
readonly maxOperations?: number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Shape of the `batch-execute` tool input.
|
|
85
|
+
*/
|
|
86
|
+
export interface BatchExecuteToolInput {
|
|
87
|
+
readonly uploadPath: StorageSlashPath;
|
|
88
|
+
readonly bucketId?: StorageBucketId;
|
|
89
|
+
readonly format: 'json' | 'ndjson';
|
|
90
|
+
readonly maxParallel: number;
|
|
91
|
+
readonly stopOnError: boolean;
|
|
92
|
+
readonly deleteUploadOnSuccess: boolean;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Per-operation failure entry in the batch summary, carrying the original file index so the caller
|
|
96
|
+
* can map a failure back to the line/element that produced it.
|
|
97
|
+
*/
|
|
98
|
+
export interface BatchExecuteErrorEntry {
|
|
99
|
+
readonly index: number;
|
|
100
|
+
readonly modelType: string;
|
|
101
|
+
readonly call?: string;
|
|
102
|
+
readonly specifier?: string;
|
|
103
|
+
readonly message: string;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Aggregate batch summary returned to the MCP client. Intentionally omits per-operation success
|
|
107
|
+
* payloads — only counts plus the failure list cross the wire, so 100 operations collapse to one
|
|
108
|
+
* compact result instead of 100 result blobs.
|
|
109
|
+
*
|
|
110
|
+
* `successCount + failureCount + skippedCount === total`. `skippedCount` is non-zero only when
|
|
111
|
+
* `stopOnError` halted the run before every operation was attempted.
|
|
112
|
+
*/
|
|
113
|
+
export interface BatchExecuteToolResult {
|
|
114
|
+
readonly total: number;
|
|
115
|
+
readonly successCount: number;
|
|
116
|
+
readonly failureCount: number;
|
|
117
|
+
readonly skippedCount: number;
|
|
118
|
+
readonly errors: ReadonlyArray<BatchExecuteErrorEntry>;
|
|
119
|
+
readonly uploadDeleted: boolean;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Builds the lookup key identifying a callModel dispatch coordinate. The factory indexes the
|
|
123
|
+
* caller's visible callModel tools by this key; the batch handler looks each operation up by the
|
|
124
|
+
* same key, so authorization reuses the exact tool set advertised on `tools/list`.
|
|
125
|
+
*
|
|
126
|
+
* @param dispatch - The `(call, modelType, specifier?)` coordinate to key.
|
|
127
|
+
* @returns A stable string key. Uses a NUL separator so segment values can't collide.
|
|
128
|
+
*/
|
|
129
|
+
export declare function batchOperationCoordKey(dispatch: Pick<McpToolDispatchTarget, 'call' | 'modelType' | 'specifier'>): string;
|
|
130
|
+
/**
|
|
131
|
+
* Builds the built-in `batch-execute` MCP tool definition.
|
|
132
|
+
*
|
|
133
|
+
* The tool ingests an uploaded JSON / NDJSON file of `(call, modelType, specifier?, data)`
|
|
134
|
+
* operations and runs them server-side, returning a single success/failure summary. It exists so an
|
|
135
|
+
* agent can perform a bulk mutation (e.g. "update 200 workers") by *generating* the operations file
|
|
136
|
+
* with a script and uploading it — rather than emitting each payload as tool-call output and paying
|
|
137
|
+
* one model turn per record.
|
|
138
|
+
*
|
|
139
|
+
* Safety model:
|
|
140
|
+
* - Every operation is validated and authorized against the caller's visible tool set *before any
|
|
141
|
+
* dispatch*. A malformed or forbidden operation aborts the whole batch with a pre-flight error and
|
|
142
|
+
* nothing runs — `dispatch` would otherwise bypass the `tools/list` visibility filter.
|
|
143
|
+
* - Runtime failures are best-effort by default (collected into the summary); `stopOnError` halts at
|
|
144
|
+
* the first failure (forcing sequential execution).
|
|
145
|
+
*
|
|
146
|
+
* @param deps - Storage reader, dispatch fn, and per-operation authorizer (typically wired in the
|
|
147
|
+
* server factory to the request's visible tool set).
|
|
148
|
+
* @returns A statically-registered {@link McpToolDefinition} ready to be appended to the MCP server
|
|
149
|
+
* factory's tool registry.
|
|
150
|
+
*/
|
|
151
|
+
export declare function createBatchExecuteTool(deps: CreateBatchExecuteToolDeps): McpToolDefinition;
|