MCPcopy Create free account
hub / github.com/allocnode/oh-my-sage / registerGraphTools

Function registerGraphTools

src/mcp/tools/graph.ts:24–474  ·  view source on GitHub ↗
(
  server: McpServer,
  gatewayManager: GatewayManager
)

Source from the content-addressed store, hash-verified

22 graphHash,
23 buildTextContext,
24 textToNodes,
25 checkGraphLayout,
26} from "../../core/index.js";
27import type { Graph, GraphNode } from "../../core/index.js";
28import {
29 ResponseFormatSchema,
30 textResult,
31 jsonResult,
32 errorResult,
33 handleError,
34 formatGraphListMarkdown,
35 shapeGraphOutput,
36 compactIssues,
37} from "../utils.js";
38import { GraphDraftStore } from "./graphDraft.js";
39
40const GraphVariableSchema = z.discriminatedUnion("type", [
41 z.object({ id: z.string().regex(/^[a-zA-Z0-9]+$/, "id 必须是纯字母数字"), type: z.literal("number"), value: z.number(), name: z.string().trim().min(1).optional() }),
42 z.object({ id: z.string().regex(/^[a-zA-Z0-9]+$/, "id 必须是纯字母数字"), type: z.literal("string"), value: z.string(), name: z.string().trim().min(1).optional() }),
43]);
44
45const GraphNodeSchema = z.object({
46 id: z.string().regex(/^[0-9a-zA-Z]+$/, "节点 ID 只能包含字母和数字"),
47 type: z.string().min(1),
48 cfg: z.record(z.unknown()),
49 props: z.record(z.unknown()),
50 inputs: z.record(z.unknown()),
51 outputs: z.record(z.array(z.string())),
52});
53
54const GraphMergeSchema = z.object({
55 id: z.string().min(1).describe("要局部修改的节点 ID"),
56 props: z.record(z.unknown()).optional().describe("浅合并到 props;值为 null 删除该键"),
57 cfg: z.record(z.unknown()).optional().describe("浅合并到 cfg;值为 null 删除该键"),
58 outputs: z.record(z.array(z.string())).optional().describe("按端口整体替换 outputs"),
59 inputs: z.record(z.unknown()).optional().describe("浅合并到 inputs;值为 null 删除该键"),
60});
61
62const GRAPH_FULL_HINT = "请改用 detail=summary,或用 node_ids 只取需要的节点";
63
64const PositionsSchema = z.record(z.object({
65 x: z.number(),
66 y: z.number(),
67 width: z.number().positive().optional(),
68 height: z.number().positive().optional(),
69}));
70
71const LayoutOptionsSchema = z.object({
72 mode: z.enum(["incremental", "full"]).optional().describe("incremental(默认)只摆放没有坐标的卡片;full 全图重排"),
73 pinned: z.array(z.string()).optional().describe("full 模式下保持不动的节点"),
74});
75const VALIDATE_HINT = "错误过多,请先修复前面的错误后重新校验";
76
77/** 缺少 cfg 时补一个默认 cfg,便于只传 {id, nodes} 校验 */
78function withDefaultCfg(graph: { id: string; nodes: unknown[]; cfg?: unknown }): Graph {
79 const cfg = (graph.cfg && typeof graph.cfg === "object" ? graph.cfg : {
80 id: graph.id,
81 enable: true,

Callers 1

createServerFunction · 0.85

Calls 11

getGraphsFunction · 0.85
handleErrorFunction · 0.85
formatJsonFunction · 0.85
formatGraphListMarkdownFunction · 0.85
getGraphFunction · 0.85
createGraphFunction · 0.85
updateGraphFunction · 0.85
deleteGraphFunction · 0.85
toggleGraphFunction · 0.85
validateGraphFunction · 0.85
ensureConnectedMethod · 0.80

Tested by

no test coverage detected