MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / saveAndDeliverArtifact

Function saveAndDeliverArtifact

packages/hosts/mcp/src/tool-server.ts:1576–1608  ·  view source on GitHub ↗
(input: {
      readonly code: string;
      readonly title: string;
      readonly description?: string;
      readonly existingId?: string;
      readonly bindings?: Readonly<Record<string, ArtifactBinding>>;
      /** Sanitized layout markup from the smoke render, when it produced any. */
      readonly preview?: string | null;
    })

Source from the content-addressed store, hash-verified

1574 : Effect.void;
1575
1576 const saveAndDeliverArtifact = (input: {
1577 readonly code: string;
1578 readonly title: string;
1579 readonly description?: string;
1580 readonly existingId?: string;
1581 readonly bindings?: Readonly<Record<string, ArtifactBinding>>;
1582 /** Sanitized layout markup from the smoke render, when it produced any. */
1583 readonly preview?: string | null;
1584 }): Effect.Effect<McpToolResult, unknown> =>
1585 Effect.gen(function* () {
1586 if (!artifacts) return artifactsUnavailableResult();
1587 const saved = yield* artifacts.save({
1588 ...(input.existingId === undefined ? {} : { id: input.existingId }),
1589 title: input.title,
1590 description: input.description ?? null,
1591 code: input.code,
1592 ...(input.bindings === undefined ? {} : { bindings: input.bindings }),
1593 preview: input.preview ?? null,
1594 });
1595 yield* notifyArtifactUsage(input.existingId === undefined ? "created" : "updated");
1596 // Resolve once and report the value actually used, so the span can
1597 // never disagree with what the client received.
1598 const delivered = deliverArtifact({
1599 code: saved.code,
1600 artifactId: saved.id,
1601 title: saved.title,
1602 });
1603 yield* Effect.annotateCurrentSpan({
1604 "mcp.artifact.id": saved.id,
1605 "mcp.artifact.apps_enabled": appsEnabled,
1606 });
1607 return delivered;
1608 });
1609
1610 /**
1611 * Whether the client can render an app, resolved at render time.

Callers 1

createArtifactFunction · 0.85

Calls 3

deliverArtifactFunction · 0.85
notifyArtifactUsageFunction · 0.70

Tested by

no test coverage detected