@decocms/runtime 0.28.1 → 1.0.0-alpha-candy.2
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 +12 -78
- package/scripts/generate-json-schema.ts +24 -0
- package/src/asset-server/dev-server-proxy.ts +16 -0
- package/src/asset-server/index.ts +44 -0
- package/src/bindings/README.md +1 -1
- package/src/bindings/binder.ts +2 -5
- package/src/bindings/channels.ts +1 -1
- package/src/bindings/index.ts +0 -33
- package/src/bindings/language-model/utils.ts +0 -91
- package/src/bindings.ts +30 -108
- package/src/client.ts +1 -145
- package/src/index.ts +46 -175
- package/src/mcp.ts +8 -165
- package/src/proxy.ts +3 -62
- package/src/state.ts +1 -30
- package/src/tools.ts +336 -0
- package/src/wrangler.ts +5 -5
- package/tsconfig.json +8 -0
- package/dist/admin.d.ts +0 -5
- package/dist/admin.js +0 -21
- package/dist/admin.js.map +0 -1
- package/dist/bindings/deconfig/index.d.ts +0 -12
- package/dist/bindings/deconfig/index.js +0 -10
- package/dist/bindings/deconfig/index.js.map +0 -1
- package/dist/bindings/index.d.ts +0 -2315
- package/dist/bindings/index.js +0 -156
- package/dist/bindings/index.js.map +0 -1
- package/dist/chunk-3AWMDSOH.js +0 -96
- package/dist/chunk-3AWMDSOH.js.map +0 -1
- package/dist/chunk-4XSQKJLU.js +0 -105
- package/dist/chunk-4XSQKJLU.js.map +0 -1
- package/dist/chunk-5EYZ2LVM.js +0 -158
- package/dist/chunk-5EYZ2LVM.js.map +0 -1
- package/dist/chunk-7ITSLORK.js +0 -128
- package/dist/chunk-7ITSLORK.js.map +0 -1
- package/dist/chunk-I7BWSAN6.js +0 -49
- package/dist/chunk-I7BWSAN6.js.map +0 -1
- package/dist/chunk-L4OT2YDO.js +0 -27
- package/dist/chunk-L4OT2YDO.js.map +0 -1
- package/dist/chunk-SHQSNOFL.js +0 -769
- package/dist/chunk-SHQSNOFL.js.map +0 -1
- package/dist/chunk-UHR3BLMF.js +0 -92
- package/dist/chunk-UHR3BLMF.js.map +0 -1
- package/dist/chunk-UIJGM3NV.js +0 -518
- package/dist/chunk-UIJGM3NV.js.map +0 -1
- package/dist/chunk-ZPUT6RN6.js +0 -32
- package/dist/chunk-ZPUT6RN6.js.map +0 -1
- package/dist/client.d.ts +0 -28
- package/dist/client.js +0 -5
- package/dist/client.js.map +0 -1
- package/dist/d1-store.d.ts +0 -9
- package/dist/d1-store.js +0 -4
- package/dist/d1-store.js.map +0 -1
- package/dist/drizzle.d.ts +0 -49
- package/dist/drizzle.js +0 -121
- package/dist/drizzle.js.map +0 -1
- package/dist/index-LOfgE9a_.d.ts +0 -471
- package/dist/index-xKtm7A7B.d.ts +0 -530
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -637
- package/dist/index.js.map +0 -1
- package/dist/mastra.d.ts +0 -10
- package/dist/mastra.js +0 -6
- package/dist/mastra.js.map +0 -1
- package/dist/mcp-87iLaW9V.d.ts +0 -105
- package/dist/mcp-client.d.ts +0 -232
- package/dist/mcp-client.js +0 -4
- package/dist/mcp-client.js.map +0 -1
- package/dist/proxy.d.ts +0 -11
- package/dist/proxy.js +0 -5
- package/dist/proxy.js.map +0 -1
- package/dist/resources.d.ts +0 -362
- package/dist/resources.js +0 -4
- package/dist/resources.js.map +0 -1
- package/dist/views.d.ts +0 -72
- package/dist/views.js +0 -4
- package/dist/views.js.map +0 -1
- package/src/admin.ts +0 -16
- package/src/auth.ts +0 -233
- package/src/bindings/deconfig/helpers.ts +0 -107
- package/src/bindings/deconfig/index.ts +0 -1
- package/src/bindings/deconfig/resources.ts +0 -659
- package/src/bindings/deconfig/types.ts +0 -106
- package/src/bindings/language-model/ai-sdk.ts +0 -87
- package/src/bindings/language-model/index.ts +0 -4
- package/src/bindings/resources/bindings.ts +0 -99
- package/src/bindings/resources/helpers.ts +0 -95
- package/src/bindings/resources/schemas.ts +0 -265
- package/src/bindings/views.ts +0 -14
- package/src/cf-imports.ts +0 -1
- package/src/d1-store.ts +0 -34
- package/src/deprecated.ts +0 -59
- package/src/drizzle.ts +0 -201
- package/src/mastra.ts +0 -898
- package/src/resources.ts +0 -168
- package/src/views.ts +0 -26
- package/src/workflow.ts +0 -193
package/src/proxy.ts
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
/* oxlint-disable no-explicit-any */
|
|
2
|
-
import type { ToolExecutionContext as _ToolExecutionContext } from "@mastra/core";
|
|
3
2
|
import { convertJsonSchemaToZod } from "zod-from-json-schema";
|
|
4
3
|
import { MCPConnection } from "./connection.ts";
|
|
5
4
|
import { createServerClient } from "./mcp-client.ts";
|
|
6
5
|
import type { CreateStubAPIOptions } from "./mcp.ts";
|
|
7
|
-
import { WELL_KNOWN_API_HOSTNAMES } from "./well-known.ts";
|
|
8
|
-
|
|
9
|
-
const getWorkspace = (workspace?: string) => {
|
|
10
|
-
if (workspace && workspace.length > 0 && !workspace.includes("/")) {
|
|
11
|
-
return `/shared/${workspace}`;
|
|
12
|
-
}
|
|
13
|
-
return workspace ?? "";
|
|
14
|
-
};
|
|
15
6
|
|
|
16
7
|
const safeParse = (content: string) => {
|
|
17
8
|
try {
|
|
@@ -33,44 +24,13 @@ const toolsMap = new Map<
|
|
|
33
24
|
>
|
|
34
25
|
>();
|
|
35
26
|
|
|
36
|
-
/**
|
|
37
|
-
* Determines if a given URL supports tool names in the path.
|
|
38
|
-
* Our APIs (api.decocms.com, api.deco.chat, localhost) support /tool/${toolName} routing.
|
|
39
|
-
* Third-party APIs typically don't support this pattern.
|
|
40
|
-
*/
|
|
41
|
-
function supportsToolNameInPath(url: string): boolean {
|
|
42
|
-
try {
|
|
43
|
-
// Our main APIs that support /tool/${toolName} routing
|
|
44
|
-
return WELL_KNOWN_API_HOSTNAMES.includes(new URL(url).hostname);
|
|
45
|
-
} catch {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
27
|
/**
|
|
51
28
|
* The base fetcher used to fetch the MCP from API.
|
|
52
29
|
*/
|
|
53
30
|
export function createMCPClientProxy<T extends Record<string, unknown>>(
|
|
54
|
-
options
|
|
31
|
+
options: CreateStubAPIOptions,
|
|
55
32
|
): T {
|
|
56
|
-
|
|
57
|
-
// [DEPRECATED] Passing a function as 'connection' is deprecated and will be removed in a future release.
|
|
58
|
-
// Please provide a connection object instead.
|
|
59
|
-
throw new Error(
|
|
60
|
-
"Deprecation Notice: Passing a function as 'connection' is deprecated and will be removed in a future release. Please provide a connection object instead.",
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const mcpPath = options?.mcpPath ?? "/mcp";
|
|
65
|
-
|
|
66
|
-
const connection: MCPConnection = options?.connection || {
|
|
67
|
-
type: "HTTP",
|
|
68
|
-
token: options?.token,
|
|
69
|
-
url: new URL(
|
|
70
|
-
`${getWorkspace(options?.workspace)}${mcpPath}`,
|
|
71
|
-
options?.decoCmsApiUrl ?? `https://api.decocms.com`,
|
|
72
|
-
).href,
|
|
73
|
-
};
|
|
33
|
+
const connection: MCPConnection = options.connection;
|
|
74
34
|
|
|
75
35
|
return new Proxy<T>({} as T, {
|
|
76
36
|
get(_, name) {
|
|
@@ -89,28 +49,9 @@ export function createMCPClientProxy<T extends Record<string, unknown>>(
|
|
|
89
49
|
// Create a connection with the tool name in the URL path for better logging
|
|
90
50
|
// Only modify connections that have a URL property (HTTP, SSE, Websocket)
|
|
91
51
|
// Use automatic detection based on URL, with optional override
|
|
92
|
-
let toolConnection = connection;
|
|
93
|
-
const shouldAddToolName =
|
|
94
|
-
options?.supportsToolName ??
|
|
95
|
-
("url" in connection &&
|
|
96
|
-
typeof connection.url === "string" &&
|
|
97
|
-
supportsToolNameInPath(connection.url));
|
|
98
|
-
|
|
99
|
-
if (
|
|
100
|
-
shouldAddToolName &&
|
|
101
|
-
"url" in connection &&
|
|
102
|
-
typeof connection.url === "string"
|
|
103
|
-
) {
|
|
104
|
-
toolConnection = {
|
|
105
|
-
...connection,
|
|
106
|
-
url: connection.url.endsWith("/")
|
|
107
|
-
? `${connection.url}tool/${String(name)}`
|
|
108
|
-
: `${connection.url}/tool/${String(name)}`,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
52
|
|
|
112
53
|
const { client, callStreamableTool } = await createServerClient(
|
|
113
|
-
{ connection
|
|
54
|
+
{ connection },
|
|
114
55
|
undefined,
|
|
115
56
|
extraHeaders,
|
|
116
57
|
);
|
package/src/state.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
import {
|
|
3
|
-
import type { AppContext } from "./mastra.ts";
|
|
4
|
-
import { createTool } from "./mastra.ts";
|
|
2
|
+
import type { AppContext } from "./tools.ts";
|
|
5
3
|
|
|
6
4
|
const asyncLocalStorage = new AsyncLocalStorage<AppContext | undefined>();
|
|
7
5
|
|
|
@@ -15,30 +13,3 @@ export const State = {
|
|
|
15
13
|
...args: TArgs
|
|
16
14
|
): R => asyncLocalStorage.run(ctx, f, ...args),
|
|
17
15
|
};
|
|
18
|
-
|
|
19
|
-
export interface ValidationPayload {
|
|
20
|
-
state: unknown;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const createStateValidationTool = (stateSchema?: z.ZodTypeAny) => {
|
|
24
|
-
return createTool({
|
|
25
|
-
id: "DECO_CHAT_STATE_VALIDATION",
|
|
26
|
-
description: "Validate the state of the OAuth flow",
|
|
27
|
-
inputSchema: z.object({
|
|
28
|
-
state: z.unknown(),
|
|
29
|
-
}),
|
|
30
|
-
outputSchema: z.object({
|
|
31
|
-
valid: z.boolean(),
|
|
32
|
-
}),
|
|
33
|
-
execute: (ctx) => {
|
|
34
|
-
if (!stateSchema) {
|
|
35
|
-
return Promise.resolve({ valid: true });
|
|
36
|
-
}
|
|
37
|
-
const parsed = stateSchema.safeParse(ctx.context.state);
|
|
38
|
-
return Promise.resolve({
|
|
39
|
-
valid: parsed.success,
|
|
40
|
-
reason: parsed.error?.message,
|
|
41
|
-
});
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
};
|
package/src/tools.ts
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
/* oxlint-disable no-explicit-any */
|
|
2
|
+
/* oxlint-disable ban-types */
|
|
3
|
+
import { HttpServerTransport } from "@deco/mcp/http";
|
|
4
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
7
|
+
import type { DefaultEnv } from "./index.ts";
|
|
8
|
+
import { State } from "./state.ts";
|
|
9
|
+
|
|
10
|
+
export const createRuntimeContext = (prev?: AppContext) => {
|
|
11
|
+
const store = State.getStore();
|
|
12
|
+
if (!store) {
|
|
13
|
+
if (prev) {
|
|
14
|
+
return prev;
|
|
15
|
+
}
|
|
16
|
+
throw new Error("Missing context, did you forget to call State.bind?");
|
|
17
|
+
}
|
|
18
|
+
return store;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export interface ToolExecutionContext<
|
|
22
|
+
TSchemaIn extends z.ZodTypeAny = z.ZodTypeAny,
|
|
23
|
+
> {
|
|
24
|
+
context: z.infer<TSchemaIn>;
|
|
25
|
+
runtimeContext: AppContext;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Tool interface with generic schema types for type-safe tool creation.
|
|
30
|
+
*/
|
|
31
|
+
export interface Tool<
|
|
32
|
+
TSchemaIn extends z.ZodTypeAny = z.ZodTypeAny,
|
|
33
|
+
TSchemaOut extends z.ZodTypeAny | undefined = undefined,
|
|
34
|
+
> {
|
|
35
|
+
id: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
inputSchema: TSchemaIn;
|
|
38
|
+
outputSchema?: TSchemaOut;
|
|
39
|
+
execute(
|
|
40
|
+
context: ToolExecutionContext<TSchemaIn>,
|
|
41
|
+
): TSchemaOut extends z.ZodSchema
|
|
42
|
+
? Promise<z.infer<TSchemaOut>>
|
|
43
|
+
: Promise<unknown>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Streamable tool interface for tools that return Response streams.
|
|
48
|
+
*/
|
|
49
|
+
export interface StreamableTool<TSchemaIn extends z.ZodSchema = z.ZodSchema> {
|
|
50
|
+
id: string;
|
|
51
|
+
inputSchema: TSchemaIn;
|
|
52
|
+
streamable?: true;
|
|
53
|
+
description?: string;
|
|
54
|
+
execute(input: ToolExecutionContext<TSchemaIn>): Promise<Response>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* CreatedTool is a permissive type that any Tool or StreamableTool can be assigned to.
|
|
59
|
+
* Uses a structural type with relaxed execute signature to allow tools with any schema.
|
|
60
|
+
*/
|
|
61
|
+
export type CreatedTool = {
|
|
62
|
+
id: string;
|
|
63
|
+
description?: string;
|
|
64
|
+
inputSchema: z.ZodTypeAny;
|
|
65
|
+
outputSchema?: z.ZodTypeAny;
|
|
66
|
+
streamable?: true;
|
|
67
|
+
// Use a permissive execute signature - accepts any context shape
|
|
68
|
+
execute(context: { context: unknown; runtimeContext: AppContext }): Promise<unknown>;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* creates a private tool that always ensure for athentication before being executed
|
|
73
|
+
*/
|
|
74
|
+
export function createPrivateTool<
|
|
75
|
+
TSchemaIn extends z.ZodSchema = z.ZodSchema,
|
|
76
|
+
TSchemaOut extends z.ZodSchema | undefined = undefined,
|
|
77
|
+
>(opts: Tool<TSchemaIn, TSchemaOut>): Tool<TSchemaIn, TSchemaOut> {
|
|
78
|
+
const execute = opts.execute;
|
|
79
|
+
if (typeof execute === "function") {
|
|
80
|
+
opts.execute = (input: ToolExecutionContext<TSchemaIn>) => {
|
|
81
|
+
const env = input.runtimeContext.env;
|
|
82
|
+
if (env) {
|
|
83
|
+
env.DECO_REQUEST_CONTEXT.ensureAuthenticated();
|
|
84
|
+
}
|
|
85
|
+
return execute(input);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return createTool(opts);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function createStreamableTool<
|
|
92
|
+
TSchemaIn extends z.ZodSchema = z.ZodSchema,
|
|
93
|
+
>(streamableTool: StreamableTool<TSchemaIn>): StreamableTool<TSchemaIn> {
|
|
94
|
+
return {
|
|
95
|
+
...streamableTool,
|
|
96
|
+
execute: (input: ToolExecutionContext<TSchemaIn>) => {
|
|
97
|
+
const env = input.runtimeContext.env;
|
|
98
|
+
if (env) {
|
|
99
|
+
env.DECO_REQUEST_CONTEXT.ensureAuthenticated();
|
|
100
|
+
}
|
|
101
|
+
return streamableTool.execute({
|
|
102
|
+
...input,
|
|
103
|
+
runtimeContext: createRuntimeContext(input.runtimeContext),
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function createTool<
|
|
110
|
+
TSchemaIn extends z.ZodSchema = z.ZodSchema,
|
|
111
|
+
TSchemaOut extends z.ZodSchema | undefined = undefined,
|
|
112
|
+
>(opts: Tool<TSchemaIn, TSchemaOut>): Tool<TSchemaIn, TSchemaOut> {
|
|
113
|
+
return {
|
|
114
|
+
...opts,
|
|
115
|
+
execute: (input: ToolExecutionContext<TSchemaIn>) => {
|
|
116
|
+
return opts.execute({
|
|
117
|
+
...input,
|
|
118
|
+
runtimeContext: createRuntimeContext(input.runtimeContext),
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface ViewExport {
|
|
125
|
+
title: string;
|
|
126
|
+
icon: string;
|
|
127
|
+
url: string;
|
|
128
|
+
tools?: string[];
|
|
129
|
+
rules?: string[];
|
|
130
|
+
installBehavior?: "none" | "open" | "autoPin";
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface Integration {
|
|
134
|
+
id: string;
|
|
135
|
+
appId: string;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function isStreamableTool(
|
|
139
|
+
tool: CreatedTool,
|
|
140
|
+
): tool is StreamableTool & CreatedTool {
|
|
141
|
+
return tool && "streamable" in tool && tool.streamable === true;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface CreateMCPServerOptions<
|
|
145
|
+
Env = unknown,
|
|
146
|
+
TSchema extends z.ZodTypeAny = never,
|
|
147
|
+
> {
|
|
148
|
+
before?: (env: Env & DefaultEnv<TSchema>) => Promise<void> | void;
|
|
149
|
+
configuration?: {
|
|
150
|
+
state?: TSchema;
|
|
151
|
+
scopes?: string[];
|
|
152
|
+
};
|
|
153
|
+
tools?:
|
|
154
|
+
| Array<
|
|
155
|
+
(
|
|
156
|
+
env: Env & DefaultEnv<TSchema>,
|
|
157
|
+
) =>
|
|
158
|
+
| Promise<CreatedTool>
|
|
159
|
+
| CreatedTool
|
|
160
|
+
| CreatedTool[]
|
|
161
|
+
| Promise<CreatedTool[]>
|
|
162
|
+
>
|
|
163
|
+
| ((
|
|
164
|
+
env: Env & DefaultEnv<TSchema>,
|
|
165
|
+
) => CreatedTool[] | Promise<CreatedTool[]>);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export type Fetch<TEnv = unknown> = (
|
|
169
|
+
req: Request,
|
|
170
|
+
env: TEnv,
|
|
171
|
+
ctx: ExecutionContext,
|
|
172
|
+
) => Promise<Response> | Response;
|
|
173
|
+
|
|
174
|
+
export interface AppContext<TEnv = unknown> {
|
|
175
|
+
env: TEnv;
|
|
176
|
+
ctx: { waitUntil: (promise: Promise<unknown>) => void };
|
|
177
|
+
req?: Request;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const decoChatOAuthToolsFor = <TSchema extends z.ZodTypeAny = never>({
|
|
181
|
+
state: schema,
|
|
182
|
+
scopes,
|
|
183
|
+
}: CreateMCPServerOptions<unknown, TSchema>["configuration"] = {}): CreatedTool[] => {
|
|
184
|
+
const jsonSchema = schema
|
|
185
|
+
? zodToJsonSchema(schema)
|
|
186
|
+
: { type: "object", properties: {} };
|
|
187
|
+
return [
|
|
188
|
+
// MESH API support
|
|
189
|
+
createTool({
|
|
190
|
+
id: "MCP_CONFIGURATION",
|
|
191
|
+
description: "MCP Configuration",
|
|
192
|
+
inputSchema: z.object({}),
|
|
193
|
+
outputSchema: z.object({
|
|
194
|
+
stateSchema: z.unknown(),
|
|
195
|
+
scopes: z.array(z.string()).optional(),
|
|
196
|
+
}),
|
|
197
|
+
execute: () => {
|
|
198
|
+
return Promise.resolve({
|
|
199
|
+
stateSchema: jsonSchema,
|
|
200
|
+
scopes,
|
|
201
|
+
});
|
|
202
|
+
},
|
|
203
|
+
}),
|
|
204
|
+
];
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
type CallTool = (opts: {
|
|
208
|
+
toolCallId: string;
|
|
209
|
+
toolCallInput: unknown;
|
|
210
|
+
}) => Promise<unknown>;
|
|
211
|
+
|
|
212
|
+
export type MCPServer<TEnv = unknown, TSchema extends z.ZodTypeAny = never> = {
|
|
213
|
+
fetch: Fetch<TEnv & DefaultEnv<TSchema>>;
|
|
214
|
+
callTool: CallTool;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
export const createMCPServer = <
|
|
218
|
+
TEnv = unknown,
|
|
219
|
+
TSchema extends z.ZodTypeAny = never,
|
|
220
|
+
>(
|
|
221
|
+
options: CreateMCPServerOptions<TEnv, TSchema>,
|
|
222
|
+
): MCPServer<TEnv, TSchema> => {
|
|
223
|
+
const createServer = async (bindings: TEnv & DefaultEnv<TSchema>) => {
|
|
224
|
+
await options.before?.(bindings);
|
|
225
|
+
|
|
226
|
+
const server = new McpServer(
|
|
227
|
+
{ name: "@deco/mcp-api", version: "1.0.0" },
|
|
228
|
+
{ capabilities: { tools: {} } },
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
const toolsFn =
|
|
232
|
+
typeof options.tools === "function"
|
|
233
|
+
? options.tools
|
|
234
|
+
: async (bindings: TEnv & DefaultEnv<TSchema>) => {
|
|
235
|
+
if (typeof options.tools === "function") {
|
|
236
|
+
return await options.tools(bindings);
|
|
237
|
+
}
|
|
238
|
+
return await Promise.all(
|
|
239
|
+
options.tools?.flatMap(async (tool) => {
|
|
240
|
+
const toolResult = tool(bindings);
|
|
241
|
+
const awaited = await toolResult;
|
|
242
|
+
if (Array.isArray(awaited)) {
|
|
243
|
+
return awaited;
|
|
244
|
+
}
|
|
245
|
+
return [awaited];
|
|
246
|
+
}) ?? [],
|
|
247
|
+
).then((t) => t.flat());
|
|
248
|
+
};
|
|
249
|
+
const tools = await toolsFn(bindings);
|
|
250
|
+
|
|
251
|
+
tools.push(...decoChatOAuthToolsFor<TSchema>(options.configuration));
|
|
252
|
+
|
|
253
|
+
for (const tool of tools) {
|
|
254
|
+
server.registerTool(
|
|
255
|
+
tool.id,
|
|
256
|
+
{
|
|
257
|
+
_meta: {
|
|
258
|
+
streamable: isStreamableTool(tool),
|
|
259
|
+
},
|
|
260
|
+
description: tool.description,
|
|
261
|
+
inputSchema:
|
|
262
|
+
tool.inputSchema && "shape" in tool.inputSchema
|
|
263
|
+
? (tool.inputSchema.shape as z.ZodRawShape)
|
|
264
|
+
: z.object({}).shape,
|
|
265
|
+
outputSchema: isStreamableTool(tool)
|
|
266
|
+
? z.object({ bytes: z.record(z.string(), z.number()) }).shape
|
|
267
|
+
: tool.outputSchema &&
|
|
268
|
+
typeof tool.outputSchema === "object" &&
|
|
269
|
+
"shape" in tool.outputSchema
|
|
270
|
+
? (tool.outputSchema.shape as z.ZodRawShape)
|
|
271
|
+
: z.object({}).shape,
|
|
272
|
+
},
|
|
273
|
+
async (args) => {
|
|
274
|
+
let result = await tool.execute({
|
|
275
|
+
context: args,
|
|
276
|
+
runtimeContext: createRuntimeContext(),
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
if (isStreamableTool(tool) && result instanceof Response) {
|
|
280
|
+
result = { bytes: await result.bytes() };
|
|
281
|
+
}
|
|
282
|
+
return {
|
|
283
|
+
structuredContent: result,
|
|
284
|
+
content: [
|
|
285
|
+
{
|
|
286
|
+
type: "text",
|
|
287
|
+
text: JSON.stringify(result),
|
|
288
|
+
},
|
|
289
|
+
],
|
|
290
|
+
};
|
|
291
|
+
},
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return { server, tools };
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
const fetch = async (
|
|
299
|
+
req: Request,
|
|
300
|
+
env: TEnv & DefaultEnv<TSchema>,
|
|
301
|
+
_ctx: ExecutionContext,
|
|
302
|
+
) => {
|
|
303
|
+
const { server } = await createServer(env);
|
|
304
|
+
const transport = new HttpServerTransport();
|
|
305
|
+
|
|
306
|
+
await server.connect(transport);
|
|
307
|
+
|
|
308
|
+
return await transport.handleMessage(req);
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
const callTool: CallTool = async ({ toolCallId, toolCallInput }) => {
|
|
312
|
+
const currentState = State.getStore();
|
|
313
|
+
if (!currentState) {
|
|
314
|
+
throw new Error("Missing state, did you forget to call State.bind?");
|
|
315
|
+
}
|
|
316
|
+
const env = currentState?.env;
|
|
317
|
+
const { tools } = await createServer(env);
|
|
318
|
+
const tool = tools.find((t) => t.id === toolCallId);
|
|
319
|
+
const execute = tool?.execute;
|
|
320
|
+
if (!execute) {
|
|
321
|
+
throw new Error(
|
|
322
|
+
`Tool ${toolCallId} not found or does not have an execute function`,
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return execute({
|
|
327
|
+
context: toolCallInput,
|
|
328
|
+
runtimeContext: createRuntimeContext(),
|
|
329
|
+
});
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
return {
|
|
333
|
+
fetch,
|
|
334
|
+
callTool,
|
|
335
|
+
};
|
|
336
|
+
};
|
package/src/wrangler.ts
CHANGED
|
@@ -2,20 +2,20 @@ export interface BindingBase {
|
|
|
2
2
|
name: string;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
export interface
|
|
5
|
+
export interface MCPConnectionBinding extends BindingBase {
|
|
6
6
|
type: "mcp";
|
|
7
7
|
/**
|
|
8
8
|
* If not provided, will return a function that takes the integration id and return the binding implementation..
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
connection_id: string;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export interface
|
|
13
|
+
export interface MCPAppBinding extends BindingBase {
|
|
14
14
|
type: "mcp";
|
|
15
15
|
/**
|
|
16
16
|
* The name of the integration to bind.
|
|
17
17
|
*/
|
|
18
|
-
|
|
18
|
+
app_name: string;
|
|
19
19
|
}
|
|
20
20
|
export interface ContractClause {
|
|
21
21
|
id: string;
|
|
@@ -36,7 +36,7 @@ export interface ContractBinding extends BindingBase {
|
|
|
36
36
|
contract: Contract;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export type MCPBinding =
|
|
39
|
+
export type MCPBinding = MCPConnectionBinding | MCPAppBinding;
|
|
40
40
|
|
|
41
41
|
export type Binding = MCPBinding | ContractBinding;
|
|
42
42
|
|
package/tsconfig.json
ADDED
package/dist/admin.d.ts
DELETED
package/dist/admin.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import './chunk-I7BWSAN6.js';
|
|
2
|
-
import { createChannel } from 'bidc';
|
|
3
|
-
|
|
4
|
-
var requestMissingScopes = ({ scopes }) => {
|
|
5
|
-
try {
|
|
6
|
-
const channel = createChannel();
|
|
7
|
-
channel.send({
|
|
8
|
-
type: "request_missing_scopes",
|
|
9
|
-
payload: {
|
|
10
|
-
scopes
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
channel.cleanup();
|
|
14
|
-
} catch (error) {
|
|
15
|
-
console.error("Failed to request missing scopes", error);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export { requestMissingScopes };
|
|
20
|
-
//# sourceMappingURL=admin.js.map
|
|
21
|
-
//# sourceMappingURL=admin.js.map
|
package/dist/admin.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/admin.ts"],"names":[],"mappings":";;;AAEO,IAAM,oBAAA,GAAuB,CAAC,EAAE,MAAA,EAAO,KAA4B;AACxE,EAAA,IAAI;AACF,IAAA,MAAM,UAAU,aAAA,EAAc;AAC9B,IAAA,OAAA,CAAQ,IAAA,CAAK;AAAA,MACX,IAAA,EAAM,wBAAA;AAAA,MACN,OAAA,EAAS;AAAA,QACP;AAAA;AACF,KACD,CAAA;AACD,IAAA,OAAA,CAAQ,OAAA,EAAQ;AAAA,EAClB,SAAS,KAAA,EAAO;AACd,IAAA,OAAA,CAAQ,KAAA,CAAM,oCAAoC,KAAK,CAAA;AAAA,EACzD;AACF","file":"admin.js","sourcesContent":["import { createChannel } from \"bidc\";\n\nexport const requestMissingScopes = ({ scopes }: { scopes: string[] }) => {\n try {\n const channel = createChannel();\n channel.send({\n type: \"request_missing_scopes\",\n payload: {\n scopes,\n },\n });\n channel.cleanup();\n } catch (error) {\n console.error(\"Failed to request missing scopes\", error);\n }\n};\n"]}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export { D as DeconfigClient, i as DeconfigResource, b as DeconfigResourceOptions, E as EnhancedResourcesTools, N as NotFoundError, h as RESOURCE_WATCH_BASE_PATHNAME, R as ResourcesBinding, d as ResourcesTools, U as UserInputError, W as WatchOptions, a as createDeconfigResource } from '../../index-xKtm7A7B.js';
|
|
2
|
-
import '@mastra/core';
|
|
3
|
-
import '../../index-LOfgE9a_.js';
|
|
4
|
-
import '@cloudflare/workers-types';
|
|
5
|
-
import 'zod/v3';
|
|
6
|
-
import '@mastra/core/di';
|
|
7
|
-
import '@mastra/core/workflows';
|
|
8
|
-
import '../../resources.js';
|
|
9
|
-
import '../../mcp-87iLaW9V.js';
|
|
10
|
-
import '@decocms/bindings/connection';
|
|
11
|
-
import '@decocms/bindings';
|
|
12
|
-
import 'zod';
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { DeconfigResource, NotFoundError, RESOURCE_WATCH_BASE_PATHNAME, UserInputError, createDeconfigResource } from '../../chunk-SHQSNOFL.js';
|
|
2
|
-
import '../../chunk-5EYZ2LVM.js';
|
|
3
|
-
import '../../chunk-3AWMDSOH.js';
|
|
4
|
-
import '../../chunk-UHR3BLMF.js';
|
|
5
|
-
import '../../chunk-UIJGM3NV.js';
|
|
6
|
-
import '../../chunk-L4OT2YDO.js';
|
|
7
|
-
import '../../chunk-7ITSLORK.js';
|
|
8
|
-
import '../../chunk-I7BWSAN6.js';
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
|
10
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|