Skip to main content
Glama

sdd_save

Validates and persists an SDD contract, recording phase transitions for project traceability.

Instructions

Validate and persist an SDD contract. Records the phase transition for project traceability.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contractYesJSON string of the SDD contract to save

Implementation Reference

  • The main handler function for the 'sdd_save' tool. Parses the JSON contract, validates it with SddContractSchema, inserts it into the SQLite database, and returns the saved contract ID, phase, and project.
    // ── Save SDD Contract ──────────────────────────────
    server.tool(
      "sdd_save",
      "Validate and persist an SDD contract. Records the phase transition for project traceability.",
      {
        contract: z.string().max(131072).describe("JSON string of the SDD contract to save"),
      },
      async ({ contract }) => {
        try {
          const parsed = JSON.parse(contract);
          const result = SddContractSchema.parse(parsed);
          const db = getDb();
          const id = generateId("sdd");
    
          db.prepare(
            `INSERT INTO contracts (id, phase, change_name, project, status, confidence, executive_summary, data)
             VALUES (?, ?, ?, ?, ?, ?, ?, ?)`
          ).run(
            id,
            result.phase,
            result.change_name,
            result.project,
            result.status,
            result.confidence,
            result.executive_summary,
            JSON.stringify(result.data)
          );
    
          return {
            content: [
              {
                type: "text" as const,
                text: JSON.stringify({
                  saved: true,
                  id,
                  phase: result.phase,
                  project: result.project,
                }),
              },
            ],
          };
        } catch (e) {
          return {
            content: [
              {
                type: "text" as const,
                text: JSON.stringify({
                  saved: false,
                  error: `${e}`,
                }),
              },
            ],
          };
        }
      }
    );
  • SddContractSchema: Zod schema defining the shape of an SDD contract (phase, change_name, project, status, confidence, executive_summary, artifacts, risks, etc.) used by the handler for validation.
    export const SddContractSchema = z.object({
      schema_version: z.string().max(32).default("1.0"),
      phase: z.enum(SDD_PHASES),
      change_name: z.string().min(1).max(256),
      project: z.string().min(1).max(256),
      status: z.enum(["success", "partial", "failed", "blocked"]),
      confidence: z.number().min(0).max(1),
      executive_summary: z.string().min(10).max(65536),
      artifacts_saved: z.array(ArtifactSchema).max(50).default([]),
      next_recommended: z.array(z.enum(SDD_PHASES)).max(9).default([]),
      risks: z.array(RiskSchema).max(50).default([]),
      data: z.record(z.unknown()).default({}),
    });
  • The registerSddTools function registers all SDD tools (including sdd_save) on the McpServer instance.
    export function registerSddTools(server: McpServer): void {
      // ── Validate SDD Contract ───────────────────────────
      server.tool(
        "sdd_validate",
        "Validate an SDD contract against the phase schema. Returns validation result with confidence check and allowed transitions.",
        {
          contract: z
            .string()
            .max(131072)
            .describe("JSON string of the SDD contract to validate"),
        },
        async ({ contract }) => {
          try {
            const parsed = JSON.parse(contract);
            const result = SddContractSchema.safeParse(parsed);
    
            if (!result.success) {
              return {
                content: [
                  {
                    type: "text" as const,
                    text: JSON.stringify({
                      valid: false,
                      errors: result.error.issues.map((i) => ({
                        path: i.path.join("."),
                        message: i.message,
                      })),
                    }),
                  },
                ],
              };
            }
    
            const data = result.data;
            const threshold = CONFIDENCE_THRESHOLDS[data.phase];
            const meetsConfidence = data.confidence >= threshold;
            const allowedNext = PHASE_TRANSITIONS[data.phase];
    
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify({
                    valid: true,
                    phase: data.phase,
                    confidence: data.confidence,
                    threshold,
                    meets_confidence: meetsConfidence,
                    allowed_next_phases: allowedNext,
                    warnings: !meetsConfidence
                      ? [
                          `Confidence ${data.confidence} is below threshold ${threshold} for phase "${data.phase}"`,
                        ]
                      : [],
                  }),
                },
              ],
            };
          } catch (e) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify({
                    valid: false,
                    errors: [{ path: "root", message: `Invalid JSON: ${e}` }],
                  }),
                },
              ],
            };
          }
        }
      );
    
      // ── Save SDD Contract ──────────────────────────────
      server.tool(
        "sdd_save",
  • generateId helper: creates a UUID-based ID with an optional prefix (used to generate the 'sdd-...' ID for the contract).
    import { randomUUID } from "node:crypto";
    
    export function generateId(prefix: string = ""): string {
      const uuid = randomUUID().replace(/-/g, "");
      return prefix ? `${prefix}-${uuid}` : uuid;
    }
  • src/server.ts:12-22 (registration)
    Server creation that calls registerSddTools, which includes the 'sdd_save' tool registration.
    export function createServer(): McpServer {
      const server = new McpServer({
        name: "forgespec-mcp",
        version: pkg.version,
      });
    
      registerSddTools(server);
      registerTaskBoardTools(server);
      registerFileTools(server);
    
      return server;
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Description reveals that the tool persists data and records a phase transition, indicating a write operation with traceability. However, it does not disclose potential side effects like overwriting, permission requirements, or error conditions. Given no annotations, the description partially fulfills the transparency burden.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Description is two sentences, each serving a distinct purpose: the first states the primary action, the second adds context. No redundant or filler words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple tool with one parameter and no output schema, the description covers the essential purpose and a key behavioral aspect (phase transition). Lacks mention of success/failure outcomes but is adequate for straightforward usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema fully describes the single parameter 'contract' with clear definition (JSON string of SDD contract). The tool description adds no extra meaning beyond the schema, so baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description clearly states the tool validates and persists an SDD contract and records phase transitions, distinguishing it from sibling tools like sdd_validate (likely only validates) and sdd_get (retrieves). However, 'persist' could be more specific (e.g., save to database).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance on when to use this tool versus alternatives such as sdd_validate or sdd_get. The description implies it is for saving after validation, but does not state prerequisites or exclusion conditions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

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/lleontor705/forgespec-mcp'

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