emitter-mcp 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server.js +81 -14
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -486,6 +486,17 @@ var extOf = (url, format) => {
|
|
|
486
486
|
return ext === "jpeg" ? "jpg" : ext;
|
|
487
487
|
};
|
|
488
488
|
var MIME = { png: "image/png", jpeg: "image/jpeg", jpg: "image/jpeg", webp: "image/webp", gif: "image/gif", avif: "image/avif", heif: "image/heic", tiff: "image/tiff" };
|
|
489
|
+
var IMAGE_EXTENSION = /\.(png|jpe?g|webp|gif|avif|heic|heif|tiff?)$/i;
|
|
490
|
+
async function isImageFile(path) {
|
|
491
|
+
if (!IMAGE_EXTENSION.test(path))
|
|
492
|
+
return false;
|
|
493
|
+
try {
|
|
494
|
+
const { format } = await sharp(path).metadata();
|
|
495
|
+
return Boolean(format && MIME[format]);
|
|
496
|
+
} catch {
|
|
497
|
+
return false;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
489
500
|
async function mimeOf(bytes) {
|
|
490
501
|
const { format } = await sharp(bytes).metadata();
|
|
491
502
|
const mime = format && MIME[format];
|
|
@@ -850,9 +861,40 @@ async function bytesOf(ctx, picture) {
|
|
|
850
861
|
return fetchBytes(ctx.fetch, picture.url, { baseMs: ctx.retryMs, sleep: ctx.sleep });
|
|
851
862
|
throw new ToolError(`${picture.label}: the file is gone and there is no url to fetch it from`, "not_found");
|
|
852
863
|
}
|
|
864
|
+
// package.json
|
|
865
|
+
var package_default = {
|
|
866
|
+
name: "emitter-mcp",
|
|
867
|
+
version: "1.0.2",
|
|
868
|
+
description: "MCP server for Emitter: make and edit images from an agent with short handles, inline pictures, and state kept on your own machine",
|
|
869
|
+
type: "module",
|
|
870
|
+
bin: {
|
|
871
|
+
"emitter-mcp": "dist/server.js"
|
|
872
|
+
},
|
|
873
|
+
files: [
|
|
874
|
+
"dist"
|
|
875
|
+
],
|
|
876
|
+
scripts: {
|
|
877
|
+
build: "bun build server.ts --target=node --format=esm --outfile dist/server.js --banner '#!/usr/bin/env node' --external sharp --external @modelcontextprotocol/sdk --external zod && chmod +x dist/server.js",
|
|
878
|
+
prepublishOnly: "bun run build"
|
|
879
|
+
},
|
|
880
|
+
engines: {
|
|
881
|
+
node: ">=20"
|
|
882
|
+
},
|
|
883
|
+
dependencies: {
|
|
884
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
885
|
+
sharp: "^0.35.4",
|
|
886
|
+
zod: "^4.6.7"
|
|
887
|
+
},
|
|
888
|
+
keywords: [
|
|
889
|
+
"mcp",
|
|
890
|
+
"emitter",
|
|
891
|
+
"image-generation"
|
|
892
|
+
]
|
|
893
|
+
};
|
|
853
894
|
|
|
854
895
|
// tools.ts
|
|
855
896
|
import { stat as stat2 } from "node:fs/promises";
|
|
897
|
+
import { basename as basename3 } from "node:path";
|
|
856
898
|
import { gzipSync } from "node:zlib";
|
|
857
899
|
import { z } from "zod";
|
|
858
900
|
|
|
@@ -1852,6 +1894,23 @@ var runLink = (origin, record) => {
|
|
|
1852
1894
|
return `${origin}/#run=${payload}`;
|
|
1853
1895
|
};
|
|
1854
1896
|
var shownAsOf = (link) => sharedId(link.slice(link.indexOf("#run=") + 5));
|
|
1897
|
+
var openableFile = async (path) => {
|
|
1898
|
+
if (await isImageFile(path))
|
|
1899
|
+
return path;
|
|
1900
|
+
throw new ToolError(`show opens pictures only, and ${basename3(path)} is not one (png, jpeg, webp, gif, avif, heic, or tiff)`, "bad_request");
|
|
1901
|
+
};
|
|
1902
|
+
var openableUrl = (ctx, url) => {
|
|
1903
|
+
const ours = isFalUrl(url) || (() => {
|
|
1904
|
+
try {
|
|
1905
|
+
return new URL(url).origin === new URL(ctx.config.url).origin;
|
|
1906
|
+
} catch {
|
|
1907
|
+
return false;
|
|
1908
|
+
}
|
|
1909
|
+
})();
|
|
1910
|
+
if (ours)
|
|
1911
|
+
return url;
|
|
1912
|
+
throw new ToolError(`show opens Emitter's own results only, and ${brief2(url, 80)} is somewhere else. Name a run, one of its images, or a picture on disk; look shows an image at any url inline.`, "bad_request");
|
|
1913
|
+
};
|
|
1855
1914
|
async function show(ctx, args) {
|
|
1856
1915
|
let record;
|
|
1857
1916
|
let pictures = [];
|
|
@@ -1885,9 +1944,9 @@ async function show(ctx, args) {
|
|
|
1885
1944
|
if (!url) {
|
|
1886
1945
|
for (const picture of pictures) {
|
|
1887
1946
|
if (picture.file && await stat2(picture.file).then(() => true, () => false))
|
|
1888
|
-
files.push(picture.file);
|
|
1947
|
+
files.push(await openableFile(picture.file));
|
|
1889
1948
|
else if (picture.url)
|
|
1890
|
-
files.push(picture.url);
|
|
1949
|
+
files.push(openableUrl(ctx, picture.url));
|
|
1891
1950
|
}
|
|
1892
1951
|
if (!files.length)
|
|
1893
1952
|
throw new ToolError(`${record ? record.run : "these images"}: nothing to show yet${record?.job ? "; the run is still rendering, call job first" : ""}`, "not_ready");
|
|
@@ -2006,38 +2065,46 @@ var batchShape = {
|
|
|
2006
2065
|
wait: generateShape.wait,
|
|
2007
2066
|
dir: generateShape.dir
|
|
2008
2067
|
};
|
|
2009
|
-
var
|
|
2068
|
+
var reads = (openWorldHint = false) => ({ readOnlyHint: true, openWorldHint });
|
|
2069
|
+
var writes = (hints) => ({
|
|
2070
|
+
readOnlyHint: false,
|
|
2071
|
+
destructiveHint: hints.destructive,
|
|
2072
|
+
idempotentHint: hints.idempotent,
|
|
2073
|
+
openWorldHint: hints.openWorld
|
|
2074
|
+
});
|
|
2075
|
+
var tool = (name, description, annotations, shape, run, loose = false) => ({
|
|
2010
2076
|
name,
|
|
2011
2077
|
description,
|
|
2078
|
+
annotations,
|
|
2012
2079
|
schema: loose ? z.looseObject(shape) : z.object(shape),
|
|
2013
2080
|
run
|
|
2014
2081
|
});
|
|
2015
2082
|
var TOOLS = [
|
|
2016
|
-
tool("guide", "How to use Emitter: how to write a prompt, the models and options, and how handles and these tools work. Call it once before the first generate of a session. With topic, one section of the full reference instead (several separated by commas, a dotted name like endpoints.generate.body.edit reaches into one); the page lists the topics. Returns text.", { topic: z.string().optional().describe("A topic name from the guide page, or several separated by commas. Left out: the one-page guide.") }, guide),
|
|
2017
|
-
tool("generate", `Render one run of images from a finished prompt, or edit an existing image (edit), or continue an earlier run in a new direction (from). Waits for the images, writes them to disk, and returns the run handle, each image's handle, file, size and flags, the cost, and the picture inline (one image, or a sheet of several). If it returns status "running", call job with the run handle.`, generateShape, generate, true),
|
|
2018
|
-
tool("batch", "Render several different briefs in one call: up to 16 jobs, each its own run with its own name and prompt. Any key generate takes (model, references, cutout, style, project, …) may sit beside jobs as a default under every job, or inside a job for that job alone. Use it instead of several generate calls; for variations of one brief use generate with count. Returns one line per job (its run handle and images, or its error while the others stand) and one sheet inline with every image labelled by its handle.", batchShape, batch, true),
|
|
2019
|
-
tool("job", 'Keep waiting on a run that generate or batch returned as "running", and finish it the same way: images on disk, the result, and the picture inline. Naming one run of a batch waits on all of that batch. With cancel: true, stop the run instead (what was already rendering still finishes). On a finished run it returns the result again.', {
|
|
2083
|
+
tool("guide", "How to use Emitter: how to write a prompt, the models and options, and how handles and these tools work. Call it once before the first generate of a session. With topic, one section of the full reference instead (several separated by commas, a dotted name like endpoints.generate.body.edit reaches into one); the page lists the topics. Returns text.", reads(), { topic: z.string().optional().describe("A topic name from the guide page, or several separated by commas. Left out: the one-page guide.") }, guide),
|
|
2084
|
+
tool("generate", `Render one run of images from a finished prompt, or edit an existing image (edit), or continue an earlier run in a new direction (from). Waits for the images, writes them to disk, and returns the run handle, each image's handle, file, size and flags, the cost, and the picture inline (one image, or a sheet of several). If it returns status "running", call job with the run handle.`, writes({ destructive: false, idempotent: false, openWorld: true }), generateShape, generate, true),
|
|
2085
|
+
tool("batch", "Render several different briefs in one call: up to 16 jobs, each its own run with its own name and prompt. Any key generate takes (model, references, cutout, style, project, …) may sit beside jobs as a default under every job, or inside a job for that job alone. Use it instead of several generate calls; for variations of one brief use generate with count. Returns one line per job (its run handle and images, or its error while the others stand) and one sheet inline with every image labelled by its handle.", writes({ destructive: false, idempotent: false, openWorld: true }), batchShape, batch, true),
|
|
2086
|
+
tool("job", 'Keep waiting on a run that generate or batch returned as "running", and finish it the same way: images on disk, the result, and the picture inline. Naming one run of a batch waits on all of that batch. With cancel: true, stop the run instead (what was already rendering still finishes). On a finished run it returns the result again.', writes({ destructive: false, idempotent: true, openWorld: false }), {
|
|
2020
2087
|
run: z.string().describe("The run handle, like sword-v2."),
|
|
2021
2088
|
cancel: z.boolean().optional().describe("true stops what is still queued."),
|
|
2022
2089
|
wait: z.number().min(0).max(MAX_WAIT).optional().describe(`Seconds to wait, default ${DEFAULT_WAIT}.`)
|
|
2023
2090
|
}, job),
|
|
2024
|
-
tool("look", "See images inline without downloading or reading files: run images by handle, whole runs, files on disk, or urls. Up to 4 come back as separate images, more (or sheet: true) as one labelled sheet. Use it to compare earlier results or to look closer at one image of a sheet. Returns each image's size and its flags (clipped edges, a halo, no alpha on a cutout) with the pictures.", {
|
|
2091
|
+
tool("look", "See images inline without downloading or reading files: run images by handle, whole runs, files on disk, or urls. Up to 4 come back as separate images, more (or sheet: true) as one labelled sheet. Use it to compare earlier results or to look closer at one image of a sheet. Returns each image's size and its flags (clipped edges, a halo, no alpha on a cutout) with the pictures.", reads(true), {
|
|
2025
2092
|
images: z.array(z.string()).min(1).describe(`Each ${imageName}. A run handle shows all its images.`),
|
|
2026
2093
|
sheet: z.boolean().optional().describe("true puts them on one labelled sheet even when there are 4 or fewer.")
|
|
2027
2094
|
}, look),
|
|
2028
|
-
tool("feedback", "Record how the user reacted to a result. said is their words verbatim, which the server turns into memory for later runs (their taste, what to keep and avoid); kept is the images they kept, which the ledger counts, and unkept takes that mark off. Either part alone is fine. Call it every time the user reacts or picks. Returns the memory entries touched and the ledger totals, with renders per kept image.", {
|
|
2095
|
+
tool("feedback", "Record how the user reacted to a result. said is their words verbatim, which the server turns into memory for later runs (their taste, what to keep and avoid); kept is the images they kept, which the ledger counts, and unkept takes that mark off. Either part alone is fine. Call it every time the user reacts or picks. Returns the memory entries touched and the ledger totals, with renders per kept image.", writes({ destructive: false, idempotent: false, openWorld: false }), {
|
|
2029
2096
|
run: z.string().optional().describe("The run the words are about. Left out: the run of the kept images, else the newest finished run."),
|
|
2030
2097
|
said: z.string().optional().describe("The user's words, verbatim."),
|
|
2031
2098
|
kept: z.array(z.string()).optional().describe("Handles of the images the user kept."),
|
|
2032
2099
|
unkept: z.array(z.string()).optional().describe("Handles of images to take the kept mark off.")
|
|
2033
2100
|
}, feedback),
|
|
2034
|
-
tool("context", "Where things stand, before rendering more or when picking work back up: the server and whether auth works, where renders go, the ledger totals with renders per kept image, the last few runs with their image handles and keeps, the standing taste from memory, and, on a local server, what the user kept in Emitter itself and which run they have open. Returns compact JSON.", {}, (ctx) => context(ctx)),
|
|
2035
|
-
tool("show", "Put results in front of the user: opens a run in Emitter's own UI in the background, or the image files when the server has no such link. Call it when the user should look at or pick from results. Returns the url or the file paths, and whether they were opened.", {
|
|
2101
|
+
tool("context", "Where things stand, before rendering more or when picking work back up: the server and whether auth works, where renders go, the ledger totals with renders per kept image, the last few runs with their image handles and keeps, the standing taste from memory, and, on a local server, what the user kept in Emitter itself and which run they have open. Returns compact JSON.", reads(), {}, (ctx) => context(ctx)),
|
|
2102
|
+
tool("show", "Put results in front of the user: opens a run in Emitter's own UI in the background, or the image files when the server has no such link. Call it when the user should look at or pick from results. Returns the url or the file paths, and whether they were opened.", writes({ destructive: false, idempotent: true, openWorld: false }), {
|
|
2036
2103
|
run: z.string().optional().describe("The run handle to show."),
|
|
2037
2104
|
images: z.array(z.string()).optional().describe(`In place of run: each ${imageName}.`),
|
|
2038
2105
|
open: z.boolean().optional().describe("false returns the link or paths without opening anything.")
|
|
2039
2106
|
}, show),
|
|
2040
|
-
tool("call", 'Any other route of the Emitter agent API, with auth added and image handles inside the body turned into what the API takes: /api/agent/check (judge an existing image), /api/agent/sheet, /api/agent/sequence, /api/agent/memory, /api/agent/styles and the rest; guide { topic: "endpoints" } lists them. Use the other tools for rendering, polling, and feedback. Returns the JSON answer, cut short with a note when it is long.', {
|
|
2107
|
+
tool("call", 'Any other route of the Emitter agent API, with auth added and image handles inside the body turned into what the API takes: /api/agent/check (judge an existing image), /api/agent/sheet, /api/agent/sequence, /api/agent/memory, /api/agent/styles and the rest; guide { topic: "endpoints" } lists them. Use the other tools for rendering, polling, and feedback. Returns the JSON answer, cut short with a note when it is long.', writes({ destructive: true, idempotent: false, openWorld: true }), {
|
|
2041
2108
|
method: z.enum(["GET", "POST", "PATCH", "DELETE"]).optional().describe("Default GET, or POST when there is a body."),
|
|
2042
2109
|
path: z.string().describe("A path under /api/agent/, with its query if any."),
|
|
2043
2110
|
body: z.record(z.string(), z.unknown()).optional().describe("The JSON body. Image handles and image file paths in it are resolved.")
|
|
@@ -2064,8 +2131,8 @@ async function runTool(deps, name, args) {
|
|
|
2064
2131
|
|
|
2065
2132
|
// server.ts
|
|
2066
2133
|
var deps = defaultDeps();
|
|
2067
|
-
var server = new McpServer({ name: "emitter", version:
|
|
2134
|
+
var server = new McpServer({ name: "emitter", version: package_default.version }, { instructions: INSTRUCTIONS });
|
|
2068
2135
|
for (const tool2 of TOOLS) {
|
|
2069
|
-
server.registerTool(tool2.name, { description: tool2.description, inputSchema: tool2.schema }, async (args) => runTool(deps, tool2.name, args));
|
|
2136
|
+
server.registerTool(tool2.name, { description: tool2.description, inputSchema: tool2.schema, annotations: tool2.annotations }, async (args) => runTool(deps, tool2.name, args));
|
|
2070
2137
|
}
|
|
2071
2138
|
await server.connect(new StdioServerTransport);
|
package/package.json
CHANGED