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

Function createArtifact

packages/hosts/mcp/src/tool-server.ts:1813–1853  ·  view source on GitHub ↗
(input: {
      readonly code: string;
      readonly title?: string;
      readonly description?: string;
      readonly connections?: Readonly<Record<string, string>>;
      readonly artifactId?: string;
    })

Source from the content-addressed store, hash-verified

1811 * what is stored, so a pure code tweak doesn't have to restate them.
1812 */
1813 const createArtifact = (input: {
1814 readonly code: string;
1815 readonly title?: string;
1816 readonly description?: string;
1817 readonly connections?: Readonly<Record<string, string>>;
1818 readonly artifactId?: string;
1819 }): Effect.Effect<McpToolResult, unknown> =>
1820 Effect.gen(function* () {
1821 // An update reads the existing row FIRST, both to carry its title and
1822 // description forward and to refuse a foreign id before any work. The
1823 // refusal is `artifact_unavailable` — the same answer `execute-action`
1824 // gives — so create-artifact cannot be used to probe which ids exist.
1825 const existing =
1826 input.artifactId === undefined ? null : yield* loadArtifact(input.artifactId);
1827 if (input.artifactId !== undefined && !existing) return actionArtifactUnavailableResult();
1828
1829 const title = input.title ?? existing?.title;
1830 if (title === undefined) {
1831 return renderRejectedResult(
1832 "title is required when creating an artifact. Give it a short human-readable name.",
1833 );
1834 }
1835 // Only an update inherits; a create with no description stores none.
1836 const description = input.description ?? existing?.description ?? undefined;
1837
1838 return yield* validateRenderAndSave({
1839 code: input.code,
1840 title,
1841 description,
1842 connections: input.connections,
1843 existing,
1844 });
1845 }).pipe(
1846 Effect.withSpan("mcp.host.tool.create_artifact", {
1847 attributes: {
1848 "mcp.tool.name": "create-artifact",
1849 "mcp.artifact.update": input.artifactId !== undefined,
1850 "mcp.execute.code_length": input.code.length,
1851 },
1852 }),
1853 );
1854
1855 /**
1856 * `edit-artifact`: the update path for tweaks, patching the stored source

Callers 1

createExecutorMcpServerFunction · 0.85

Calls 4

loadArtifactFunction · 0.85
renderRejectedResultFunction · 0.85
validateRenderAndSaveFunction · 0.85

Tested by

no test coverage detected