@decocms/runtime 1.0.0-alpha.17 → 1.0.0-alpha.19
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 +35 -3
package/package.json
CHANGED
package/src/tools.ts
CHANGED
|
@@ -145,12 +145,20 @@ 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?: (
|
|
159
|
+
env: Env & DefaultEnv<TSchema>,
|
|
160
|
+
cb: OnChangeCallback<TSchema>,
|
|
161
|
+
) => Promise<void>;
|
|
154
162
|
state?: TSchema;
|
|
155
163
|
scopes?: string[];
|
|
156
164
|
};
|
|
@@ -182,9 +190,10 @@ export interface AppContext<TEnv extends DefaultEnv = DefaultEnv> {
|
|
|
182
190
|
req?: Request;
|
|
183
191
|
}
|
|
184
192
|
|
|
185
|
-
const
|
|
193
|
+
const configurationToolsFor = <TSchema extends z.ZodTypeAny = never>({
|
|
186
194
|
state: schema,
|
|
187
195
|
scopes,
|
|
196
|
+
onChange,
|
|
188
197
|
}: CreateMCPServerOptions<
|
|
189
198
|
unknown,
|
|
190
199
|
TSchema
|
|
@@ -193,7 +202,30 @@ const decoChatOAuthToolsFor = <TSchema extends z.ZodTypeAny = never>({
|
|
|
193
202
|
? zodToJsonSchema(schema)
|
|
194
203
|
: { type: "object", properties: {} };
|
|
195
204
|
return [
|
|
196
|
-
|
|
205
|
+
...(onChange
|
|
206
|
+
? [
|
|
207
|
+
createTool({
|
|
208
|
+
id: "ON_MCP_CONFIGURATION",
|
|
209
|
+
description: "MCP Configuration On Change",
|
|
210
|
+
inputSchema: z.object({
|
|
211
|
+
state: schema ?? z.unknown(),
|
|
212
|
+
scopes: z
|
|
213
|
+
.array(z.string())
|
|
214
|
+
.describe(
|
|
215
|
+
"Array of scopes in format 'KEY::SCOPE' (e.g., 'GMAIL::GetCurrentUser')",
|
|
216
|
+
),
|
|
217
|
+
}),
|
|
218
|
+
outputSchema: z.object({}),
|
|
219
|
+
execute: async (input) => {
|
|
220
|
+
await onChange(input.runtimeContext.env, {
|
|
221
|
+
state: input.context.state,
|
|
222
|
+
scopes: input.context.scopes,
|
|
223
|
+
});
|
|
224
|
+
return Promise.resolve({});
|
|
225
|
+
},
|
|
226
|
+
}),
|
|
227
|
+
]
|
|
228
|
+
: []),
|
|
197
229
|
createTool({
|
|
198
230
|
id: "MCP_CONFIGURATION",
|
|
199
231
|
description: "MCP Configuration",
|
|
@@ -256,7 +288,7 @@ export const createMCPServer = <
|
|
|
256
288
|
};
|
|
257
289
|
const tools = await toolsFn(bindings);
|
|
258
290
|
|
|
259
|
-
tools.push(...
|
|
291
|
+
tools.push(...configurationToolsFor<TSchema>(options.configuration));
|
|
260
292
|
|
|
261
293
|
for (const tool of tools) {
|
|
262
294
|
server.registerTool(
|