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