@continuumdao/continuum-node-sdk 1.2.3 → 1.2.5
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/dist/api/management-key.d.ts +2 -0
- package/dist/api/management-key.d.ts.map +1 -1
- package/dist/api/management-key.js +23 -4
- package/dist/api/management-key.js.map +1 -1
- package/dist/config/keys.d.ts +6 -1
- package/dist/config/keys.d.ts.map +1 -1
- package/dist/config/keys.js +28 -9
- package/dist/config/keys.js.map +1 -1
- package/dist/config/paths.d.ts +5 -1
- package/dist/config/paths.d.ts.map +1 -1
- package/dist/config/paths.js +8 -2
- package/dist/config/paths.js.map +1 -1
- package/dist/core/keygen.d.ts +1 -1
- package/dist/core/keygen.d.ts.map +1 -1
- package/dist/core/keygen.js +2 -2
- package/dist/core/keygen.js.map +1 -1
- package/dist/core/management-signer.d.ts +9 -8
- package/dist/core/management-signer.d.ts.map +1 -1
- package/dist/core/management-signer.js +150 -92
- package/dist/core/management-signer.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/normalize.js +2 -2
- package/dist/internal/normalize.js.map +1 -1
- package/dist/mcp/defi/catalog-adapter.d.ts +19 -0
- package/dist/mcp/defi/catalog-adapter.d.ts.map +1 -0
- package/dist/mcp/defi/catalog-adapter.js +66 -0
- package/dist/mcp/defi/catalog-adapter.js.map +1 -0
- package/dist/mcp/defi/context.d.ts +21 -0
- package/dist/mcp/defi/context.d.ts.map +1 -0
- package/dist/mcp/defi/context.js +42 -0
- package/dist/mcp/defi/context.js.map +1 -0
- package/dist/mcp/defi/discovery.d.ts +5 -0
- package/dist/mcp/defi/discovery.d.ts.map +1 -0
- package/dist/mcp/defi/discovery.js +243 -0
- package/dist/mcp/defi/discovery.js.map +1 -0
- package/dist/mcp/defi/handler.d.ts +109 -0
- package/dist/mcp/defi/handler.d.ts.map +1 -0
- package/dist/mcp/defi/handler.js +113 -0
- package/dist/mcp/defi/handler.js.map +1 -0
- package/dist/mcp/defi/import-map.d.ts +4 -0
- package/dist/mcp/defi/import-map.d.ts.map +1 -0
- package/dist/mcp/defi/import-map.js +15 -0
- package/dist/mcp/defi/import-map.js.map +1 -0
- package/dist/mcp/defi/index.d.ts +5 -0
- package/dist/mcp/defi/index.d.ts.map +1 -0
- package/dist/mcp/defi/index.js +5 -0
- package/dist/mcp/defi/index.js.map +1 -0
- package/dist/mcp/defi/input-adapter.d.ts +20 -0
- package/dist/mcp/defi/input-adapter.d.ts.map +1 -0
- package/dist/mcp/defi/input-adapter.js +123 -0
- package/dist/mcp/defi/input-adapter.js.map +1 -0
- package/dist/mcp/defi/register-protocol-tools.d.ts +7 -0
- package/dist/mcp/defi/register-protocol-tools.d.ts.map +1 -0
- package/dist/mcp/defi/register-protocol-tools.js +46 -0
- package/dist/mcp/defi/register-protocol-tools.js.map +1 -0
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/keygen.js +1 -1
- package/dist/mcp/keygen.js.map +1 -1
- package/dist/mcp/management-signer.d.ts.map +1 -1
- package/dist/mcp/management-signer.js +7 -4
- package/dist/mcp/management-signer.js.map +1 -1
- package/dist/mcp/register.d.ts +3 -2
- package/dist/mcp/register.d.ts.map +1 -1
- package/dist/mcp/register.js +38 -3
- package/dist/mcp/register.js.map +1 -1
- package/dist/mcp/server/config-from-env.d.ts +6 -0
- package/dist/mcp/server/config-from-env.d.ts.map +1 -0
- package/dist/mcp/server/config-from-env.js +29 -0
- package/dist/mcp/server/config-from-env.js.map +1 -0
- package/dist/mcp/server/http-transport.d.ts +12 -0
- package/dist/mcp/server/http-transport.d.ts.map +1 -0
- package/dist/mcp/server/http-transport.js +146 -0
- package/dist/mcp/server/http-transport.js.map +1 -0
- package/dist/mcp/server/index.d.ts +2 -0
- package/dist/mcp/server/index.d.ts.map +1 -0
- package/dist/mcp/server/index.js +12 -0
- package/dist/mcp/server/index.js.map +1 -0
- package/package.json +9 -2
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type McpToolDefinition } from '@continuumdao/ctm-mpc-defi/agent';
|
|
2
|
+
export type ProtocolSupportAdvisor = {
|
|
3
|
+
tokenFilter?: string;
|
|
4
|
+
supportedChainIds(): Promise<number[]>;
|
|
5
|
+
supportedTokens(chainId: number, options?: {
|
|
6
|
+
rpcUrl?: string;
|
|
7
|
+
}): Promise<{
|
|
8
|
+
tokens: Array<Record<string, unknown>>;
|
|
9
|
+
nativeWrapped?: string;
|
|
10
|
+
notes?: string;
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
13
|
+
/** Tools that return data directly (quote/swap prep) rather than { requestId } via multiSign POST. */
|
|
14
|
+
export declare const MCP_NON_SUBMIT_TOOL_NAMES: Set<string>;
|
|
15
|
+
export declare function getToolsForProtocol(protocolId: string): readonly McpToolDefinition[];
|
|
16
|
+
/** SKILL.md is not bundled in ctm-mpc-defi 0.2.x; reserved for a future defi release. */
|
|
17
|
+
export declare function getProtocolSkill(_protocolId: string): string | undefined;
|
|
18
|
+
export declare function getProtocolSupportAdvisor(protocolId: string): ProtocolSupportAdvisor | undefined;
|
|
19
|
+
//# sourceMappingURL=catalog-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog-adapter.d.ts","sourceRoot":"","sources":["../../../src/mcp/defi/catalog-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,iBAAiB,EACtB,MAAM,kCAAkC,CAAC;AAS1C,MAAM,MAAM,sBAAsB,GAAG;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACvC,eAAe,CACd,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAC,GACzB,OAAO,CAAC;QACV,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QACvC,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,KAAK,CAAC,EAAE,MAAM,CAAC;KACf,CAAC,CAAC;CACH,CAAC;AAWF,sGAAsG;AACtG,eAAO,MAAM,yBAAyB,aAErC,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,iBAAiB,EAAE,CAEpF;AAED,yFAAyF;AACzF,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAExE;AAED,wBAAgB,yBAAyB,CACxC,UAAU,EAAE,MAAM,GAChB,sBAAsB,GAAG,SAAS,CA6CpC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { getMcpToolDefinitions, getProtocolModules, } from '@continuumdao/ctm-mpc-defi/agent';
|
|
2
|
+
/** Common EVM chain IDs probed via ProtocolModule.isChainSupported. */
|
|
3
|
+
const CANDIDATE_EVM_CHAIN_IDS = [
|
|
4
|
+
1, 5, 10, 56, 137, 480, 130, 196, 324, 480, 1868, 4217, 7777777, 81457,
|
|
5
|
+
8453, 84531, 84532, 10143, 42161, 421613, 43114, 42220, 44787, 59144,
|
|
6
|
+
11155111, 420, 80001,
|
|
7
|
+
];
|
|
8
|
+
function isNonSubmitTool(tool) {
|
|
9
|
+
const props = tool.outputSchema.properties;
|
|
10
|
+
return !(props &&
|
|
11
|
+
'bodyForSign' in props &&
|
|
12
|
+
'messageToSign' in props);
|
|
13
|
+
}
|
|
14
|
+
/** Tools that return data directly (quote/swap prep) rather than { requestId } via multiSign POST. */
|
|
15
|
+
export const MCP_NON_SUBMIT_TOOL_NAMES = new Set(getMcpToolDefinitions().filter(isNonSubmitTool).map(tool => tool.name));
|
|
16
|
+
export function getToolsForProtocol(protocolId) {
|
|
17
|
+
return getMcpToolDefinitions().filter(tool => tool.protocolId === protocolId);
|
|
18
|
+
}
|
|
19
|
+
/** SKILL.md is not bundled in ctm-mpc-defi 0.2.x; reserved for a future defi release. */
|
|
20
|
+
export function getProtocolSkill(_protocolId) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
export function getProtocolSupportAdvisor(protocolId) {
|
|
24
|
+
const mod = getProtocolModules().find(p => p.id === protocolId);
|
|
25
|
+
if (!mod) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
tokenFilter: mod.chainCategory,
|
|
30
|
+
async supportedChainIds() {
|
|
31
|
+
if (mod.chainCategory !== 'evm') {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
const chainIds = [];
|
|
35
|
+
for (const chainId of CANDIDATE_EVM_CHAIN_IDS) {
|
|
36
|
+
if (await mod.isChainSupported({
|
|
37
|
+
chainCategory: 'evm',
|
|
38
|
+
chainId,
|
|
39
|
+
})) {
|
|
40
|
+
chainIds.push(chainId);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return [...new Set(chainIds)].sort((a, b) => a - b);
|
|
44
|
+
},
|
|
45
|
+
async supportedTokens(chainId, options) {
|
|
46
|
+
const rpcUrl = options?.rpcUrl?.trim();
|
|
47
|
+
const chainOk = await mod.isChainSupported({
|
|
48
|
+
chainCategory: mod.chainCategory,
|
|
49
|
+
chainId,
|
|
50
|
+
});
|
|
51
|
+
if (!chainOk) {
|
|
52
|
+
return {
|
|
53
|
+
tokens: [],
|
|
54
|
+
notes: `${protocolId} does not support chain ${chainId}.`,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
tokens: [],
|
|
59
|
+
notes: rpcUrl
|
|
60
|
+
? `On-chain token discovery for ${protocolId} is not implemented in the vendored defi catalog. Use get_token_registry or protocol tool inputs.`
|
|
61
|
+
: `Configure chain ${chainId} in get_chain_registry (rpcGateway) before token discovery. Token lists are not bundled for ${protocolId}.`,
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=catalog-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog-adapter.js","sourceRoot":"","sources":["../../../src/mcp/defi/catalog-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,qBAAqB,EACrB,kBAAkB,GAElB,MAAM,kCAAkC,CAAC;AAE1C,uEAAuE;AACvE,MAAM,uBAAuB,GAAG;IAC/B,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK;IACtE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK;IACpE,QAAQ,EAAE,GAAG,EAAE,KAAK;CACX,CAAC;AAeX,SAAS,eAAe,CAAC,IAAuB;IAC/C,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC;IAC3C,OAAO,CAAC,CACP,KAAK;QACL,aAAa,IAAI,KAAK;QACtB,eAAe,IAAI,KAAK,CACxB,CAAC;AACH,CAAC;AAED,sGAAsG;AACtG,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,GAAG,CAC/C,qBAAqB,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CACtE,CAAC;AAEF,MAAM,UAAU,mBAAmB,CAAC,UAAkB;IACrD,OAAO,qBAAqB,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;AAC/E,CAAC;AAED,yFAAyF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GAAG,UAAU,2BAA2B,OAAO,GAAG;iBACzD,CAAC;YACH,CAAC;YACD,OAAO;gBACN,MAAM,EAAE,EAAE;gBACV,KAAK,EAAE,MAAM;oBACZ,CAAC,CAAC,gCAAgC,UAAU,mGAAmG;oBAC/I,CAAC,CAAC,mBAAmB,OAAO,+FAA+F,UAAU,GAAG;aACzI,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { McpToolDefinition } from '@continuumdao/ctm-mpc-defi/agent';
|
|
2
|
+
export type DefiProtocolContextOptions = {
|
|
3
|
+
/** Protocol ids loaded in this MCP session. */
|
|
4
|
+
loadedProtocols?: Iterable<string>;
|
|
5
|
+
};
|
|
6
|
+
export declare class DefiProtocolContext {
|
|
7
|
+
private readonly loadedProtocols;
|
|
8
|
+
private readonly protocolToolNames;
|
|
9
|
+
constructor(options?: DefiProtocolContextOptions);
|
|
10
|
+
isLoaded(protocolId: string): boolean;
|
|
11
|
+
getLoadedProtocols(): string[];
|
|
12
|
+
markLoaded(protocolId: string, toolNames: readonly string[]): void;
|
|
13
|
+
markUnloaded(protocolId: string): string[];
|
|
14
|
+
getToolNames(protocolId: string): string[];
|
|
15
|
+
allLoadedToolNames(): string[];
|
|
16
|
+
assertToolCallable(tool: McpToolDefinition): void;
|
|
17
|
+
}
|
|
18
|
+
export type CreateContinuumMcpServerOptions = {
|
|
19
|
+
defiContext?: DefiProtocolContext;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/mcp/defi/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AAExE,MAAM,MAAM,0BAA0B,GAAG;IACxC,+CAA+C;IAC/C,eAAe,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;CACnC,CAAC;AAEF,qBAAa,mBAAmB;IAC/B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAqB;IACrD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAkC;gBAExD,OAAO,GAAE,0BAA+B;IAMpD,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAIrC,kBAAkB,IAAI,MAAM,EAAE;IAI9B,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;IAKlE,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE;IAO1C,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE;IAI1C,kBAAkB,IAAI,MAAM,EAAE;IAQ9B,kBAAkB,CAAC,IAAI,EAAE,iBAAiB,GAAG,IAAI;CAOjD;AAED,MAAM,MAAM,+BAA+B,GAAG;IAC7C,WAAW,CAAC,EAAE,mBAAmB,CAAC;CAClC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export class DefiProtocolContext {
|
|
2
|
+
loadedProtocols = new Set();
|
|
3
|
+
protocolToolNames = new Map();
|
|
4
|
+
constructor(options = {}) {
|
|
5
|
+
for (const id of options.loadedProtocols ?? []) {
|
|
6
|
+
this.loadedProtocols.add(id);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
isLoaded(protocolId) {
|
|
10
|
+
return this.loadedProtocols.has(protocolId);
|
|
11
|
+
}
|
|
12
|
+
getLoadedProtocols() {
|
|
13
|
+
return [...this.loadedProtocols].sort();
|
|
14
|
+
}
|
|
15
|
+
markLoaded(protocolId, toolNames) {
|
|
16
|
+
this.loadedProtocols.add(protocolId);
|
|
17
|
+
this.protocolToolNames.set(protocolId, new Set(toolNames));
|
|
18
|
+
}
|
|
19
|
+
markUnloaded(protocolId) {
|
|
20
|
+
this.loadedProtocols.delete(protocolId);
|
|
21
|
+
const names = [...(this.protocolToolNames.get(protocolId) ?? [])];
|
|
22
|
+
this.protocolToolNames.delete(protocolId);
|
|
23
|
+
return names;
|
|
24
|
+
}
|
|
25
|
+
getToolNames(protocolId) {
|
|
26
|
+
return [...(this.protocolToolNames.get(protocolId) ?? [])];
|
|
27
|
+
}
|
|
28
|
+
allLoadedToolNames() {
|
|
29
|
+
const out = new Set();
|
|
30
|
+
for (const names of this.protocolToolNames.values()) {
|
|
31
|
+
for (const n of names)
|
|
32
|
+
out.add(n);
|
|
33
|
+
}
|
|
34
|
+
return [...out].sort();
|
|
35
|
+
}
|
|
36
|
+
assertToolCallable(tool) {
|
|
37
|
+
if (!this.isLoaded(tool.protocolId)) {
|
|
38
|
+
throw new Error(`Protocol "${tool.protocolId}" is not loaded. Call load_defi_protocol first.`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/mcp/defi/context.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,mBAAmB;IACd,eAAe,GAAG,IAAI,GAAG,EAAU,CAAC;IACpC,iBAAiB,GAAG,IAAI,GAAG,EAAuB,CAAC;IAEpE,YAAY,UAAsC,EAAE;QACnD,KAAK,MAAM,EAAE,IAAI,OAAO,CAAC,eAAe,IAAI,EAAE,EAAE,CAAC;YAChD,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC9B,CAAC;IACF,CAAC;IAED,QAAQ,CAAC,UAAkB;QAC1B,OAAO,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC7C,CAAC;IAED,kBAAkB;QACjB,OAAO,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,CAAC,IAAI,EAAE,CAAC;IACzC,CAAC;IAED,UAAU,CAAC,UAAkB,EAAE,SAA4B;QAC1D,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,UAAU,CAA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type { DefiProtocolContext } from './context.js';
|
|
4
|
+
export declare function registerDefiDiscoveryTools(server: McpServer, config: NodeSdkConfig, defiContext: DefiProtocolContext): void;
|
|
5
|
+
//# sourceMappingURL=discovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../../src/mcp/defi/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,yCAAyC,CAAC;AAQvE,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAC;AAE1D,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,cAAc,CAAC;AAatD,wBAAgB,0BAA0B,CACzC,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,aAAa,EACrB,WAAW,EAAE,mBAAmB,GAC9B,IAAI,CAyQN"}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { getProtocolSkill, getProtocolSupportAdvisor, getToolsForProtocol, } from './catalog-adapter.js';
|
|
2
|
+
import { getProtocolModules } from '@continuumdao/ctm-mpc-defi/agent';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { resolveChainRegistryEntry } from '../../core/registry/networks.js';
|
|
5
|
+
import { markProtocolLoaded } from './register-protocol-tools.js';
|
|
6
|
+
const protocolIdSchema = z.object({
|
|
7
|
+
protocolId: z.string().min(1),
|
|
8
|
+
});
|
|
9
|
+
const protocolChainSchema = z.object({
|
|
10
|
+
protocolId: z.string().min(1),
|
|
11
|
+
chainId: z.number().int().positive(),
|
|
12
|
+
rpcUrl: z.string().optional(),
|
|
13
|
+
});
|
|
14
|
+
export function registerDefiDiscoveryTools(server, config, defiContext) {
|
|
15
|
+
server.registerTool('list_defi_protocols', {
|
|
16
|
+
description: 'List DeFi protocols available for load_defi_protocol, grouped by chain category.',
|
|
17
|
+
inputSchema: z.object({}).strict(),
|
|
18
|
+
outputSchema: z
|
|
19
|
+
.object({
|
|
20
|
+
protocols: z.array(z.object({
|
|
21
|
+
protocolId: z.string(),
|
|
22
|
+
chainCategory: z.string(),
|
|
23
|
+
loaded: z.boolean(),
|
|
24
|
+
actionCount: z.number(),
|
|
25
|
+
toolCount: z.number(),
|
|
26
|
+
})),
|
|
27
|
+
})
|
|
28
|
+
.strict(),
|
|
29
|
+
}, async () => {
|
|
30
|
+
const protocols = getProtocolModules().map(p => ({
|
|
31
|
+
protocolId: p.id,
|
|
32
|
+
chainCategory: p.chainCategory,
|
|
33
|
+
loaded: defiContext.isLoaded(p.id),
|
|
34
|
+
actionCount: p.actions.length,
|
|
35
|
+
toolCount: getToolsForProtocol(p.id).length,
|
|
36
|
+
}));
|
|
37
|
+
return {
|
|
38
|
+
content: [{ type: 'text', text: JSON.stringify({ protocols }) }],
|
|
39
|
+
structuredContent: { protocols },
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
server.registerTool('load_defi_protocol', {
|
|
43
|
+
description: 'Load MCP tools and advisory context for a DeFi protocol (e.g. aave-v4). Idempotent.',
|
|
44
|
+
inputSchema: protocolIdSchema,
|
|
45
|
+
outputSchema: z
|
|
46
|
+
.object({
|
|
47
|
+
loaded: z.boolean(),
|
|
48
|
+
protocolId: z.string(),
|
|
49
|
+
toolNames: z.array(z.string()),
|
|
50
|
+
tokenFilter: z.string().optional(),
|
|
51
|
+
advisoryTools: z.array(z.string()),
|
|
52
|
+
skillPreview: z.string().optional(),
|
|
53
|
+
})
|
|
54
|
+
.strict(),
|
|
55
|
+
}, async ({ protocolId }) => {
|
|
56
|
+
const mod = getProtocolModules().find(p => p.id === protocolId);
|
|
57
|
+
if (!mod) {
|
|
58
|
+
return {
|
|
59
|
+
content: [{ type: 'text', text: `Unknown protocol: ${protocolId}` }],
|
|
60
|
+
isError: true,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (defiContext.isLoaded(protocolId)) {
|
|
64
|
+
const advisor = getProtocolSupportAdvisor(protocolId);
|
|
65
|
+
const payload = {
|
|
66
|
+
loaded: true,
|
|
67
|
+
protocolId,
|
|
68
|
+
toolNames: defiContext.getToolNames(protocolId),
|
|
69
|
+
tokenFilter: advisor?.tokenFilter,
|
|
70
|
+
advisoryTools: [
|
|
71
|
+
'get_defi_protocol_supported_chains',
|
|
72
|
+
'get_defi_protocol_supported_tokens',
|
|
73
|
+
'get_defi_protocol_skill',
|
|
74
|
+
],
|
|
75
|
+
skillPreview: getProtocolSkill(protocolId)?.slice(0, 500),
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
content: [{ type: 'text', text: JSON.stringify(payload) }],
|
|
79
|
+
structuredContent: payload,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const toolNames = markProtocolLoaded(defiContext, protocolId);
|
|
83
|
+
const advisor = getProtocolSupportAdvisor(protocolId);
|
|
84
|
+
const payload = {
|
|
85
|
+
loaded: true,
|
|
86
|
+
protocolId,
|
|
87
|
+
toolNames,
|
|
88
|
+
tokenFilter: advisor?.tokenFilter,
|
|
89
|
+
advisoryTools: [
|
|
90
|
+
'get_defi_protocol_supported_chains',
|
|
91
|
+
'get_defi_protocol_supported_tokens',
|
|
92
|
+
'get_defi_protocol_skill',
|
|
93
|
+
],
|
|
94
|
+
skillPreview: getProtocolSkill(protocolId)?.slice(0, 500),
|
|
95
|
+
};
|
|
96
|
+
void server.server.sendToolListChanged?.().catch(() => undefined);
|
|
97
|
+
return {
|
|
98
|
+
content: [{ type: 'text', text: JSON.stringify(payload) }],
|
|
99
|
+
structuredContent: payload,
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
server.registerTool('unload_defi_protocol', {
|
|
103
|
+
description: 'Unload DeFi protocol context. Protocol tools remain registered but return errors until reloaded (soft unload).',
|
|
104
|
+
inputSchema: protocolIdSchema,
|
|
105
|
+
outputSchema: z
|
|
106
|
+
.object({
|
|
107
|
+
unloaded: z.boolean(),
|
|
108
|
+
protocolId: z.string(),
|
|
109
|
+
removedToolNames: z.array(z.string()),
|
|
110
|
+
remainingLoaded: z.array(z.string()),
|
|
111
|
+
})
|
|
112
|
+
.strict(),
|
|
113
|
+
}, async ({ protocolId }) => {
|
|
114
|
+
if (!defiContext.isLoaded(protocolId)) {
|
|
115
|
+
return {
|
|
116
|
+
content: [
|
|
117
|
+
{
|
|
118
|
+
type: 'text',
|
|
119
|
+
text: JSON.stringify({
|
|
120
|
+
unloaded: false,
|
|
121
|
+
protocolId,
|
|
122
|
+
removedToolNames: [],
|
|
123
|
+
remainingLoaded: defiContext.getLoadedProtocols(),
|
|
124
|
+
}),
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
structuredContent: {
|
|
128
|
+
unloaded: false,
|
|
129
|
+
protocolId,
|
|
130
|
+
removedToolNames: [],
|
|
131
|
+
remainingLoaded: defiContext.getLoadedProtocols(),
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
const removedToolNames = defiContext.markUnloaded(protocolId);
|
|
136
|
+
const payload = {
|
|
137
|
+
unloaded: true,
|
|
138
|
+
protocolId,
|
|
139
|
+
removedToolNames,
|
|
140
|
+
remainingLoaded: defiContext.getLoadedProtocols(),
|
|
141
|
+
};
|
|
142
|
+
return {
|
|
143
|
+
content: [{ type: 'text', text: JSON.stringify(payload) }],
|
|
144
|
+
structuredContent: payload,
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
server.registerTool('get_defi_protocol_skill', {
|
|
148
|
+
description: 'Return SKILL.md markdown for a DeFi protocol.',
|
|
149
|
+
inputSchema: protocolIdSchema,
|
|
150
|
+
outputSchema: z.object({ protocolId: z.string(), skill: z.string() }).strict(),
|
|
151
|
+
}, async ({ protocolId }) => {
|
|
152
|
+
const skill = getProtocolSkill(protocolId);
|
|
153
|
+
if (!skill) {
|
|
154
|
+
return {
|
|
155
|
+
content: [
|
|
156
|
+
{ type: 'text', text: `No SKILL.md for protocol: ${protocolId}` },
|
|
157
|
+
],
|
|
158
|
+
isError: true,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
const payload = { protocolId, skill };
|
|
162
|
+
return {
|
|
163
|
+
content: [{ type: 'text', text: skill }],
|
|
164
|
+
structuredContent: payload,
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
server.registerTool('get_defi_protocol_supported_chains', {
|
|
168
|
+
description: 'Layer B: chain IDs supported by a DeFi protocol. Intersect with get_chain_registry.',
|
|
169
|
+
inputSchema: protocolIdSchema,
|
|
170
|
+
outputSchema: z
|
|
171
|
+
.object({
|
|
172
|
+
protocolId: z.string(),
|
|
173
|
+
chainIds: z.array(z.number()),
|
|
174
|
+
tokenFilter: z.string().optional(),
|
|
175
|
+
})
|
|
176
|
+
.strict(),
|
|
177
|
+
}, async ({ protocolId }) => {
|
|
178
|
+
const advisor = getProtocolSupportAdvisor(protocolId);
|
|
179
|
+
if (!advisor) {
|
|
180
|
+
return {
|
|
181
|
+
content: [
|
|
182
|
+
{ type: 'text', text: `No support advisor for: ${protocolId}` },
|
|
183
|
+
],
|
|
184
|
+
isError: true,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const chainIds = await advisor.supportedChainIds();
|
|
188
|
+
const payload = {
|
|
189
|
+
protocolId,
|
|
190
|
+
chainIds,
|
|
191
|
+
tokenFilter: advisor.tokenFilter,
|
|
192
|
+
};
|
|
193
|
+
return {
|
|
194
|
+
content: [{ type: 'text', text: JSON.stringify(payload) }],
|
|
195
|
+
structuredContent: payload,
|
|
196
|
+
};
|
|
197
|
+
});
|
|
198
|
+
server.registerTool('get_defi_protocol_supported_tokens', {
|
|
199
|
+
description: 'Layer C: tokens supported by a protocol on a chain. Optional rpcUrl overrides chain registry lookup.',
|
|
200
|
+
inputSchema: protocolChainSchema,
|
|
201
|
+
outputSchema: z
|
|
202
|
+
.object({
|
|
203
|
+
protocolId: z.string(),
|
|
204
|
+
chainId: z.number(),
|
|
205
|
+
tokens: z.array(z.record(z.string(), z.unknown())),
|
|
206
|
+
nativeWrapped: z.string().optional(),
|
|
207
|
+
notes: z.string().optional(),
|
|
208
|
+
})
|
|
209
|
+
.strict(),
|
|
210
|
+
}, async ({ protocolId, chainId, rpcUrl }) => {
|
|
211
|
+
const advisor = getProtocolSupportAdvisor(protocolId);
|
|
212
|
+
if (!advisor) {
|
|
213
|
+
return {
|
|
214
|
+
content: [
|
|
215
|
+
{ type: 'text', text: `No support advisor for: ${protocolId}` },
|
|
216
|
+
],
|
|
217
|
+
isError: true,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
let resolvedRpc = rpcUrl?.trim();
|
|
221
|
+
if (!resolvedRpc) {
|
|
222
|
+
const chain = await resolveChainRegistryEntry(config, chainId);
|
|
223
|
+
if (chain.ok) {
|
|
224
|
+
resolvedRpc = String(chain.data.rpcGateway ?? '').trim() || undefined;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
const result = await advisor.supportedTokens(chainId, {
|
|
228
|
+
rpcUrl: resolvedRpc,
|
|
229
|
+
});
|
|
230
|
+
const payload = {
|
|
231
|
+
protocolId,
|
|
232
|
+
chainId,
|
|
233
|
+
tokens: result.tokens,
|
|
234
|
+
nativeWrapped: result.nativeWrapped,
|
|
235
|
+
notes: result.notes,
|
|
236
|
+
};
|
|
237
|
+
return {
|
|
238
|
+
content: [{ type: 'text', text: JSON.stringify(payload) }],
|
|
239
|
+
structuredContent: payload,
|
|
240
|
+
};
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=discovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../../src/mcp/defi/discovery.ts"],"names":[],"mappings":"AACA,OAAO,EACN,gBAAgB,EAChB,yBAAyB,EACzB,mBAAmB,GACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAC,kBAAkB,EAAC,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAC,yB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|
1
|
+
import type { McpToolDefinition } from '@continuumdao/ctm-mpc-defi/agent';
|
|
2
|
+
import type { NodeSdkConfig } from '../../config/schema.js';
|
|
3
|
+
import type { DefiProtocolContext } from './context.js';
|
|
4
|
+
export declare function executeDefiMcpTool(config: NodeSdkConfig, defiContext: DefiProtocolContext, tool: McpToolDefinition, rawInput: unknown): Promise<{
|
|
5
|
+
[x: string]: unknown;
|
|
6
|
+
content: ({
|
|
7
|
+
type: "text";
|
|
8
|
+
text: string;
|
|
9
|
+
annotations?: {
|
|
10
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
11
|
+
priority?: number | undefined;
|
|
12
|
+
lastModified?: string | undefined;
|
|
13
|
+
} | undefined;
|
|
14
|
+
_meta?: {
|
|
15
|
+
[x: string]: unknown;
|
|
16
|
+
} | undefined;
|
|
17
|
+
} | {
|
|
18
|
+
type: "image";
|
|
19
|
+
data: string;
|
|
20
|
+
mimeType: string;
|
|
21
|
+
annotations?: {
|
|
22
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
23
|
+
priority?: number | undefined;
|
|
24
|
+
lastModified?: string | undefined;
|
|
25
|
+
} | undefined;
|
|
26
|
+
_meta?: {
|
|
27
|
+
[x: string]: unknown;
|
|
28
|
+
} | undefined;
|
|
29
|
+
} | {
|
|
30
|
+
type: "audio";
|
|
31
|
+
data: string;
|
|
32
|
+
mimeType: string;
|
|
33
|
+
annotations?: {
|
|
34
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
35
|
+
priority?: number | undefined;
|
|
36
|
+
lastModified?: string | undefined;
|
|
37
|
+
} | undefined;
|
|
38
|
+
_meta?: {
|
|
39
|
+
[x: string]: unknown;
|
|
40
|
+
} | undefined;
|
|
41
|
+
} | {
|
|
42
|
+
uri: string;
|
|
43
|
+
name: string;
|
|
44
|
+
type: "resource_link";
|
|
45
|
+
description?: string | undefined;
|
|
46
|
+
mimeType?: string | undefined;
|
|
47
|
+
size?: number | undefined;
|
|
48
|
+
annotations?: {
|
|
49
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
50
|
+
priority?: number | undefined;
|
|
51
|
+
lastModified?: string | undefined;
|
|
52
|
+
} | undefined;
|
|
53
|
+
_meta?: {
|
|
54
|
+
[x: string]: unknown;
|
|
55
|
+
} | undefined;
|
|
56
|
+
icons?: {
|
|
57
|
+
src: string;
|
|
58
|
+
mimeType?: string | undefined;
|
|
59
|
+
sizes?: string[] | undefined;
|
|
60
|
+
theme?: "light" | "dark" | undefined;
|
|
61
|
+
}[] | undefined;
|
|
62
|
+
title?: string | undefined;
|
|
63
|
+
} | {
|
|
64
|
+
type: "resource";
|
|
65
|
+
resource: {
|
|
66
|
+
uri: string;
|
|
67
|
+
text: string;
|
|
68
|
+
mimeType?: string | undefined;
|
|
69
|
+
_meta?: {
|
|
70
|
+
[x: string]: unknown;
|
|
71
|
+
} | undefined;
|
|
72
|
+
} | {
|
|
73
|
+
uri: string;
|
|
74
|
+
blob: string;
|
|
75
|
+
mimeType?: string | undefined;
|
|
76
|
+
_meta?: {
|
|
77
|
+
[x: string]: unknown;
|
|
78
|
+
} | undefined;
|
|
79
|
+
};
|
|
80
|
+
annotations?: {
|
|
81
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
82
|
+
priority?: number | undefined;
|
|
83
|
+
lastModified?: string | undefined;
|
|
84
|
+
} | undefined;
|
|
85
|
+
_meta?: {
|
|
86
|
+
[x: string]: unknown;
|
|
87
|
+
} | undefined;
|
|
88
|
+
})[];
|
|
89
|
+
_meta?: {
|
|
90
|
+
[x: string]: unknown;
|
|
91
|
+
progressToken?: string | number | undefined;
|
|
92
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
93
|
+
taskId: string;
|
|
94
|
+
} | undefined;
|
|
95
|
+
} | undefined;
|
|
96
|
+
structuredContent?: {
|
|
97
|
+
[x: string]: unknown;
|
|
98
|
+
} | undefined;
|
|
99
|
+
isError?: boolean | undefined;
|
|
100
|
+
} | {
|
|
101
|
+
content: {
|
|
102
|
+
type: "text";
|
|
103
|
+
text: string;
|
|
104
|
+
}[];
|
|
105
|
+
structuredContent: {
|
|
106
|
+
requestId: string;
|
|
107
|
+
};
|
|
108
|
+
}>;
|
|
109
|
+
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/mcp/defi/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AAMxE,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAC;AAG1D,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,cAAc,CAAC;AAQtD,wBAAsB,kBAAkB,CACvC,MAAM,EAAE,aAAa,EACrB,WAAW,EAAE,mBAAmB,EAChC,IAAI,EAAE,iBAAiB,EACvB,QAAQ,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgIjB"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { MCP_NON_SUBMIT_TOOL_NAMES } from './catalog-adapter.js';
|
|
2
|
+
import { parseMcpToolInput, parseMcpToolOutput, } from '@continuumdao/ctm-mpc-defi/agent';
|
|
3
|
+
import { signAndSubmitMultiSignRequest } from '../../core/mpc/sign-request-body.js';
|
|
4
|
+
import { sdkResultToCallToolResult } from '../tool-utils.js';
|
|
5
|
+
import { importDefiHandler } from './import-map.js';
|
|
6
|
+
import { enrichMultisignContext, mapToolFieldsToBuilderArgs, stripEnrichmentKeys, } from './input-adapter.js';
|
|
7
|
+
export async function executeDefiMcpTool(config, defiContext, tool, rawInput) {
|
|
8
|
+
try {
|
|
9
|
+
defiContext.assertToolCallable(tool);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
return {
|
|
13
|
+
content: [
|
|
14
|
+
{
|
|
15
|
+
type: 'text',
|
|
16
|
+
text: error instanceof Error ? error.message : String(error),
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
isError: true,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const inputRecord = rawInput && typeof rawInput === 'object' && !Array.isArray(rawInput)
|
|
23
|
+
? rawInput
|
|
24
|
+
: {};
|
|
25
|
+
let validationInput = inputRecord;
|
|
26
|
+
if (typeof inputRecord.keyGenId === 'string' && inputRecord.keyGenId.trim()) {
|
|
27
|
+
const enriched = await enrichMultisignContext(config, inputRecord);
|
|
28
|
+
if (!enriched.ok) {
|
|
29
|
+
return sdkResultToCallToolResult(enriched);
|
|
30
|
+
}
|
|
31
|
+
validationInput = {
|
|
32
|
+
...inputRecord,
|
|
33
|
+
keyGen: enriched.data.keyGen,
|
|
34
|
+
executorAddress: enriched.data.executorAddress,
|
|
35
|
+
chainId: enriched.data.chainId,
|
|
36
|
+
rpcUrl: enriched.data.rpcUrl,
|
|
37
|
+
chainDetail: enriched.data.chainDetail,
|
|
38
|
+
useCustomGas: enriched.data.useCustomGas,
|
|
39
|
+
...(enriched.data.customGasChainDetails
|
|
40
|
+
? { customGasChainDetails: enriched.data.customGasChainDetails }
|
|
41
|
+
: {}),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
let parsed;
|
|
45
|
+
try {
|
|
46
|
+
parsed = parseMcpToolInput(tool.name, validationInput);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
return {
|
|
50
|
+
content: [
|
|
51
|
+
{
|
|
52
|
+
type: 'text',
|
|
53
|
+
text: error instanceof Error ? error.message : 'Invalid tool input.',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
isError: true,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const parsedInput = parsed && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
60
|
+
? parsed
|
|
61
|
+
: {};
|
|
62
|
+
try {
|
|
63
|
+
const handler = await importDefiHandler(tool.handler.importPath, tool.handler.exportName);
|
|
64
|
+
if (MCP_NON_SUBMIT_TOOL_NAMES.has(tool.name)) {
|
|
65
|
+
const result = await handler(parsedInput);
|
|
66
|
+
const validated = parseMcpToolOutput(tool.name, result);
|
|
67
|
+
return {
|
|
68
|
+
content: [{ type: 'text', text: JSON.stringify(validated) }],
|
|
69
|
+
structuredContent: validated,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const enriched = await enrichMultisignContext(config, parsedInput);
|
|
73
|
+
if (!enriched.ok) {
|
|
74
|
+
return sdkResultToCallToolResult(enriched);
|
|
75
|
+
}
|
|
76
|
+
const protocolFields = mapToolFieldsToBuilderArgs(tool.name, stripEnrichmentKeys(parsedInput));
|
|
77
|
+
const builderArgs = {
|
|
78
|
+
...protocolFields,
|
|
79
|
+
keyGen: enriched.data.keyGen,
|
|
80
|
+
executorAddress: enriched.data.executorAddress,
|
|
81
|
+
chainId: enriched.data.chainId,
|
|
82
|
+
rpcUrl: enriched.data.rpcUrl,
|
|
83
|
+
chainDetail: enriched.data.chainDetail,
|
|
84
|
+
useCustomGas: enriched.data.useCustomGas,
|
|
85
|
+
...(enriched.data.customGasChainDetails
|
|
86
|
+
? { customGasChainDetails: enriched.data.customGasChainDetails }
|
|
87
|
+
: {}),
|
|
88
|
+
};
|
|
89
|
+
const built = await handler(builderArgs);
|
|
90
|
+
const buildOut = parseMcpToolOutput(tool.name, built);
|
|
91
|
+
const submitted = await signAndSubmitMultiSignRequest(config, buildOut.bodyForSign);
|
|
92
|
+
if (!submitted.ok) {
|
|
93
|
+
return sdkResultToCallToolResult(submitted);
|
|
94
|
+
}
|
|
95
|
+
const payload = { requestId: submitted.data.requestId };
|
|
96
|
+
return {
|
|
97
|
+
content: [{ type: 'text', text: JSON.stringify(payload) }],
|
|
98
|
+
structuredContent: payload,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
return {
|
|
103
|
+
content: [
|
|
104
|
+
{
|
|
105
|
+
type: 'text',
|
|
106
|
+
text: error instanceof Error ? error.message : String(error),
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
isError: true,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=handler.js.map
|