Skip to main content
Glama

Storyden

by Southclaws
Mozilla Public License 2.0
229
mutator-functions.ts1.62 kB
import { mergeWith } from "lodash"; import { MutatorCallback } from "swr"; import { Node, NodeGetOKResponse, NodeListOKResponse, NodeWithChildren, } from "@/api/openapi-schema"; export const nodeListMutator = ( updated: NodeWithChildren, ): MutatorCallback<NodeListOKResponse> => { return (data) => { if (!data) return; const nodes = data.nodes.map((node) => { if (node.slug === updated.slug) { return { ...node, ...updated, // Ensure the children are not included if the node is supposed to // hide them. The reason this needs to be done explicitly is because // these mutator functions are often called with a node state that was // pulled from GET /nodes/{id} API which always includes children, not // like the tree listing API which will adhere to child-hiding rules. children: updated.hide_child_tree ? [] : updated.children, }; } return node; }); return { ...data, nodes, }; }; }; export const nodeMutator = ( updated: NodeWithChildren, ): MutatorCallback<NodeGetOKResponse> => { return (previous) => { if (!previous) return; const node = mergeWith(previous, updated, (target, source) => { // If the target is an array, we want to replace it with the source value. if (Array.isArray(target)) { return source; } // If source is undefined, we want to keep the existing target value. if (source === undefined) { return target; } return source; }); return node; }; };

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Southclaws/storyden'

If you have feedback or need assistance with the MCP directory API, please join our Discord server