@decocms/runtime 1.0.0-alpha.17 → 1.0.0-alpha.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/tools.ts +32 -3
package/package.json
CHANGED
package/src/tools.ts
CHANGED
|
@@ -145,12 +145,17 @@ export function isStreamableTool(
|
|
|
145
145
|
return tool && "streamable" in tool && tool.streamable === true;
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
export interface OnChangeCallback<TSchema extends z.ZodTypeAny = never> {
|
|
149
|
+
state: z.infer<TSchema>;
|
|
150
|
+
scopes: string[];
|
|
151
|
+
}
|
|
148
152
|
export interface CreateMCPServerOptions<
|
|
149
153
|
Env = unknown,
|
|
150
154
|
TSchema extends z.ZodTypeAny = never,
|
|
151
155
|
> {
|
|
152
156
|
before?: (env: Env & DefaultEnv<TSchema>) => Promise<void> | void;
|
|
153
157
|
configuration?: {
|
|
158
|
+
onChange?: (cb: OnChangeCallback<TSchema>) => Promise<void>;
|
|
154
159
|
state?: TSchema;
|
|
155
160
|
scopes?: string[];
|
|
156
161
|
};
|
|
@@ -182,9 +187,10 @@ export interface AppContext<TEnv extends DefaultEnv = DefaultEnv> {
|
|
|
182
187
|
req?: Request;
|
|
183
188
|
}
|
|
184
189
|
|
|
185
|
-
const
|
|
190
|
+
const configurationToolsFor = <TSchema extends z.ZodTypeAny = never>({
|
|
186
191
|
state: schema,
|
|
187
192
|
scopes,
|
|
193
|
+
onChange,
|
|
188
194
|
}: CreateMCPServerOptions<
|
|
189
195
|
unknown,
|
|
190
196
|
TSchema
|
|
@@ -193,7 +199,30 @@ const decoChatOAuthToolsFor = <TSchema extends z.ZodTypeAny = never>({
|
|
|
193
199
|
? zodToJsonSchema(schema)
|
|
194
200
|
: { type: "object", properties: {} };
|
|
195
201
|
return [
|
|
196
|
-
|
|
202
|
+
...(onChange
|
|
203
|
+
? [
|
|
204
|
+
createTool({
|
|
205
|
+
id: "ON_MCP_CONFIGURATION",
|
|
206
|
+
description: "MCP Configuration On Change",
|
|
207
|
+
inputSchema: z.object({
|
|
208
|
+
state: schema ?? z.unknown(),
|
|
209
|
+
scopes: z
|
|
210
|
+
.array(z.string())
|
|
211
|
+
.describe(
|
|
212
|
+
"Array of scopes in format 'KEY::SCOPE' (e.g., 'GMAIL::GetCurrentUser')",
|
|
213
|
+
),
|
|
214
|
+
}),
|
|
215
|
+
outputSchema: z.object({}),
|
|
216
|
+
execute: async (input) => {
|
|
217
|
+
await onChange({
|
|
218
|
+
state: input.context.state,
|
|
219
|
+
scopes: input.context.scopes,
|
|
220
|
+
});
|
|
221
|
+
return Promise.resolve({});
|
|
222
|
+
},
|
|
223
|
+
}),
|
|
224
|
+
]
|
|
225
|
+
: []),
|
|
197
226
|
createTool({
|
|
198
227
|
id: "MCP_CONFIGURATION",
|
|
199
228
|
description: "MCP Configuration",
|
|
@@ -256,7 +285,7 @@ export const createMCPServer = <
|
|
|
256
285
|
};
|
|
257
286
|
const tools = await toolsFn(bindings);
|
|
258
287
|
|
|
259
|
-
tools.push(...
|
|
288
|
+
tools.push(...configurationToolsFor<TSchema>(options.configuration));
|
|
260
289
|
|
|
261
290
|
for (const tool of tools) {
|
|
262
291
|
server.registerTool(
|