|
| 1 | +import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; |
| 2 | +import { RPCType } from "../types/RPCType"; |
| 3 | +import z from "zod/v3"; |
| 4 | +import { DEElementIDSchema, SiteIdSchema } from "../schemas"; |
| 5 | +import { formatErrorResponse, formatResponse } from "../utils"; |
| 6 | + |
| 7 | +export function registerDEInstancePropsTools(server: McpServer, rpc: RPCType) { |
| 8 | + const instancePropsToolRPCCall = async (siteId: string, actions: any) => { |
| 9 | + return rpc.callTool("instance_props_tool", { |
| 10 | + siteId, |
| 11 | + actions: actions || [], |
| 12 | + }); |
| 13 | + }; |
| 14 | + |
| 15 | + server.registerTool( |
| 16 | + "instance_props_tool", |
| 17 | + { |
| 18 | + title: "Designer Instance Props Tool", |
| 19 | + annotations: { |
| 20 | + readOnlyHint: false, |
| 21 | + openWorldHint: true, |
| 22 | + }, |
| 23 | + description: |
| 24 | + "Designer tool - Get, search, and set component instance properties (props). Use this to read prop values, search props by value type, and set static values or data bindings on component instances.", |
| 25 | + inputSchema: { |
| 26 | + ...SiteIdSchema, |
| 27 | + actions: z.array( |
| 28 | + z |
| 29 | + .object({ |
| 30 | + get_instance_props: z |
| 31 | + .object({ |
| 32 | + ...DEElementIDSchema, |
| 33 | + }) |
| 34 | + .optional() |
| 35 | + .describe( |
| 36 | + "Get a quick summary of all props on a component instance. Returns propId, value, and hasOverride for each prop.", |
| 37 | + ), |
| 38 | + search_instance_props: z |
| 39 | + .object({ |
| 40 | + ...DEElementIDSchema, |
| 41 | + value_type: z |
| 42 | + .enum([ |
| 43 | + "string", |
| 44 | + "textContent", |
| 45 | + "richText", |
| 46 | + "boolean", |
| 47 | + "color", |
| 48 | + "date", |
| 49 | + "link", |
| 50 | + "url", |
| 51 | + "email", |
| 52 | + "phone", |
| 53 | + "file", |
| 54 | + "videoUrl", |
| 55 | + "video", |
| 56 | + "image", |
| 57 | + "imageAsset", |
| 58 | + "cmsImage", |
| 59 | + "imageSet", |
| 60 | + "number", |
| 61 | + "enum", |
| 62 | + "option", |
| 63 | + "slot", |
| 64 | + "reference", |
| 65 | + "referenceSet", |
| 66 | + "variant", |
| 67 | + "filter", |
| 68 | + "sort", |
| 69 | + "selectedItems", |
| 70 | + "visibility", |
| 71 | + "booleanFilter", |
| 72 | + "altText", |
| 73 | + "id", |
| 74 | + ]) |
| 75 | + .optional() |
| 76 | + .describe( |
| 77 | + "Optional filter to only return props of a specific value type.", |
| 78 | + ), |
| 79 | + }) |
| 80 | + .optional() |
| 81 | + .describe( |
| 82 | + "Search instance props with full detail including display labels, binding metadata, and resolved values. Optionally filter by value type.", |
| 83 | + ), |
| 84 | + set_instance_props: z |
| 85 | + .object({ |
| 86 | + ...DEElementIDSchema, |
| 87 | + props: z |
| 88 | + .array( |
| 89 | + z.object({ |
| 90 | + propId: z.string().describe("The prop ID to set."), |
| 91 | + value: z |
| 92 | + .any() |
| 93 | + .describe( |
| 94 | + "The value to set. Can be a static value (string, number, boolean, null to reset), or a binding object ({ sourceType: 'cms', collectionId, fieldId } or { sourceType: 'prop', propId } or { sourceType: 'page', fieldKey }).", |
| 95 | + ), |
| 96 | + }), |
| 97 | + ) |
| 98 | + .describe( |
| 99 | + "Array of prop entries to set on the component instance.", |
| 100 | + ), |
| 101 | + }) |
| 102 | + .optional() |
| 103 | + .describe( |
| 104 | + "Set property values on a component instance. Supports static values, data bindings, and resetting overrides (value: null).", |
| 105 | + ), |
| 106 | + }) |
| 107 | + .strict() |
| 108 | + .refine( |
| 109 | + (d) => |
| 110 | + [ |
| 111 | + d.get_instance_props, |
| 112 | + d.search_instance_props, |
| 113 | + d.set_instance_props, |
| 114 | + ].filter(Boolean).length >= 1, |
| 115 | + { |
| 116 | + message: |
| 117 | + "Provide at least one of get_instance_props, search_instance_props, set_instance_props.", |
| 118 | + }, |
| 119 | + ), |
| 120 | + ), |
| 121 | + }, |
| 122 | + }, |
| 123 | + async ({ siteId, actions }) => { |
| 124 | + try { |
| 125 | + return formatResponse(await instancePropsToolRPCCall(siteId, actions)); |
| 126 | + } catch (error) { |
| 127 | + return formatErrorResponse(error); |
| 128 | + } |
| 129 | + }, |
| 130 | + ); |
| 131 | +} |
0 commit comments