get_metaobject
Retrieve a metaobject's display name, handle, type, publishable status, and truncated field values using its GID. Use list_metaobjects to find GIDs first.
Instructions
Fetch a single metaobject by GID and return its display name, handle, type, publishable status, and all of its field values. Field values longer than 120 characters are truncated in the rendered output (full values are still on the underlying record). Use list_metaobjects to discover GIDs first.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Metaobject GID, e.g. 'gid://shopify/Metaobject/123456'. Discover GIDs via list_metaobjects. |
Implementation Reference
- src/tools/metaobjects.ts:349-377 (handler)The handler function for the 'get_metaobject' tool. It executes a GraphQL query (GET_METAOBJECT_QUERY) with the provided id, formats the returned metaobject fields, and returns a text response with display name, handle, type, status, and field values.
async (args) => { const data = await client.graphql<{ metaobject: MetaobjectNode | null; }>(GET_METAOBJECT_QUERY, { id: args.id }); if (!data.metaobject) { return { content: [ { type: "text" as const, text: `Metaobject not found: ${args.id}` }, ], }; } const m = data.metaobject; const status = m.capabilities?.publishable?.status; return { content: [ { type: "text" as const, text: [ `${m.displayName ?? m.handle} (${m.type})${status ? ` [${status}]` : ""}`, ` ID: ${m.id}`, ` Handle: ${m.handle}`, ` Updated: ${m.updatedAt}`, " Fields:", ...formatMetaobjectFields(m.fields), ].join("\n"), }, ], }; }, - src/tools/metaobjects.ts:187-193 (schema)The input schema for 'get_metaobject'. Defines a single required string parameter 'id' (a metaobject GID like 'gid://shopify/Metaobject/123456'), described with a hint to discover GIDs via list_metaobjects.
const getMetaobjectSchema = { id: z .string() .describe( "Metaobject GID, e.g. 'gid://shopify/Metaobject/123456'. Discover GIDs via list_metaobjects.", ), }; - src/tools/metaobjects.ts:345-378 (registration)Registration of the 'get_metaobject' tool via server.tool(). The tool is registered with its name, description, schema, and handler lambda. This is inside registerMetaobjectTools() which is called from src/server.ts line 67.
server.tool( "get_metaobject", "Fetch a single metaobject by GID and return its display name, handle, type, publishable status, and all of its field values. Field values longer than 120 characters are truncated in the rendered output (full values are still on the underlying record). Use list_metaobjects to discover GIDs first.", getMetaobjectSchema, async (args) => { const data = await client.graphql<{ metaobject: MetaobjectNode | null; }>(GET_METAOBJECT_QUERY, { id: args.id }); if (!data.metaobject) { return { content: [ { type: "text" as const, text: `Metaobject not found: ${args.id}` }, ], }; } const m = data.metaobject; const status = m.capabilities?.publishable?.status; return { content: [ { type: "text" as const, text: [ `${m.displayName ?? m.handle} (${m.type})${status ? ` [${status}]` : ""}`, ` ID: ${m.id}`, ` Handle: ${m.handle}`, ` Updated: ${m.updatedAt}`, " Fields:", ...formatMetaobjectFields(m.fields), ].join("\n"), }, ], }; }, ); - src/tools/metaobjects.ts:86-98 (helper)The GET_METAOBJECT_QUERY GraphQL query string used by the handler. Queries a single metaobject by ID, returning id, type, handle, displayName, updatedAt, capabilities (publishable status), and fields (key, type, value, jsonValue).
const GET_METAOBJECT_QUERY = /* GraphQL */ ` query GetMetaobject($id: ID!) { metaobject(id: $id) { id type handle displayName updatedAt capabilities { publishable { status } } fields { key type value jsonValue } } } `; - src/tools/metaobjects.ts:259-269 (helper)Helper function formatMetaobjectFields() used by the handler to format field key/type/value pairs, truncating values longer than 120 characters for display.
function formatMetaobjectFields(fields: MetaobjectField[]): string[] { return fields.map((f) => { const val = f.value === null || f.value === undefined ? "(null)" : f.value.length > 120 ? `${f.value.slice(0, 120)}…` : f.value; return ` ${f.key} (${f.type}): ${val}`; }); }