@hadialmarzooq/agent-media-mcp 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Hadi Almarzooq
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+
4
+ declare function createMcpServer(): McpServer;
5
+ declare function startMcpServer(): Promise<void>;
6
+
7
+ export { createMcpServer, startMcpServer };
package/dist/index.js ADDED
@@ -0,0 +1,346 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { createRequire } from "module";
5
+ import { realpathSync } from "fs";
6
+ import { fileURLToPath } from "url";
7
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
8
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
9
+ import {
10
+ MediaError,
11
+ mediaPlanSchema,
12
+ parsePlan,
13
+ planMedia,
14
+ validatePlan,
15
+ verifyMedia
16
+ } from "@hadialmarzooq/agent-media-core";
17
+ import {
18
+ executePlan,
19
+ getCapabilities,
20
+ inspectMedia,
21
+ makeVertical,
22
+ optimizeForWeb,
23
+ normalize,
24
+ extractAudio,
25
+ extractFrame
26
+ } from "@hadialmarzooq/agent-media-ffmpeg";
27
+ import { z } from "zod";
28
+ var packageVersion = createRequire(import.meta.url)("../package.json").version;
29
+ var goalSchema = z.object({
30
+ trimStartSeconds: z.number().nonnegative().optional(),
31
+ durationSeconds: z.number().positive().optional(),
32
+ aspectRatio: z.string().optional(),
33
+ width: z.number().int().positive().optional(),
34
+ height: z.number().int().positive().optional(),
35
+ maxSizeMB: z.number().positive().optional(),
36
+ compatibility: z.enum(["high", "balanced"]).optional(),
37
+ quality: z.enum(["high", "balanced", "small"]).optional(),
38
+ audio: z.enum(["preserve", "remove"]).optional()
39
+ });
40
+ function createMcpServer() {
41
+ const server = new McpServer({ name: "agent-media", version: packageVersion });
42
+ server.registerTool(
43
+ "inspect_media",
44
+ {
45
+ description: "Inspect normalized media metadata.",
46
+ inputSchema: { input: z.string().min(1) }
47
+ },
48
+ async ({ input }) => safely(async () => inspectMedia(input))
49
+ );
50
+ server.registerTool(
51
+ "get_media_capabilities",
52
+ { description: "Detect local FFmpeg capabilities." },
53
+ async () => safely(getCapabilities)
54
+ );
55
+ server.registerTool(
56
+ "plan_media",
57
+ {
58
+ description: "Create an inspectable versioned semantic Media IR plan.",
59
+ inputSchema: { input: z.string().min(1), goals: goalSchema }
60
+ },
61
+ async ({ input, goals }) => safely(async () => ({
62
+ plan: planMedia({
63
+ source: await inspectMedia(input),
64
+ goals: cleanGoals(goals),
65
+ capabilities: await getCapabilities()
66
+ })
67
+ }))
68
+ );
69
+ server.registerTool(
70
+ "make_vertical",
71
+ {
72
+ description: "Inspect, plan, execute, and verify a high-compatibility 9:16 video. Reports MCP progress when requested.",
73
+ inputSchema: {
74
+ input: z.string().min(1),
75
+ output: z.string().min(1),
76
+ width: z.number().int().positive().optional(),
77
+ height: z.number().int().positive().optional(),
78
+ trimStartSeconds: z.number().nonnegative().optional(),
79
+ durationSeconds: z.number().positive().optional(),
80
+ maxSizeMB: z.number().positive().optional(),
81
+ audio: z.enum(["preserve", "remove"]).optional(),
82
+ overwrite: z.boolean().optional()
83
+ }
84
+ },
85
+ async (options, extra) => {
86
+ const notifications = mcpProgress(extra);
87
+ const response = await safely(
88
+ async () => makeVertical({
89
+ input: options.input,
90
+ output: options.output,
91
+ ...options.width === void 0 ? {} : { width: options.width },
92
+ ...options.height === void 0 ? {} : { height: options.height },
93
+ ...options.trimStartSeconds === void 0 ? {} : { trimStartSeconds: options.trimStartSeconds },
94
+ ...options.durationSeconds === void 0 ? {} : { durationSeconds: options.durationSeconds },
95
+ ...options.maxSizeMB === void 0 ? {} : { maxSizeMB: options.maxSizeMB },
96
+ ...options.audio === void 0 ? {} : { audio: options.audio },
97
+ ...options.overwrite === void 0 ? {} : { overwrite: options.overwrite },
98
+ signal: extra.signal,
99
+ onProgress: notifications.notify
100
+ })
101
+ );
102
+ await notifications.drain();
103
+ return response;
104
+ }
105
+ );
106
+ server.registerTool(
107
+ "optimize_for_web",
108
+ {
109
+ description: "Inspect, plan, execute, and verify a web-optimized high-compatibility video. Reports MCP progress when requested.",
110
+ inputSchema: {
111
+ input: z.string().min(1),
112
+ output: z.string().min(1),
113
+ trimStartSeconds: z.number().nonnegative().optional(),
114
+ durationSeconds: z.number().positive().optional(),
115
+ maxSizeMB: z.number().positive().optional(),
116
+ quality: z.enum(["high", "balanced", "small"]).optional(),
117
+ audio: z.enum(["preserve", "remove"]).optional(),
118
+ overwrite: z.boolean().optional()
119
+ }
120
+ },
121
+ async (options, extra) => {
122
+ const notifications = mcpProgress(extra);
123
+ const response = await safely(
124
+ async () => optimizeForWeb({
125
+ input: options.input,
126
+ output: options.output,
127
+ ...options.trimStartSeconds === void 0 ? {} : { trimStartSeconds: options.trimStartSeconds },
128
+ ...options.durationSeconds === void 0 ? {} : { durationSeconds: options.durationSeconds },
129
+ ...options.maxSizeMB === void 0 ? {} : { maxSizeMB: options.maxSizeMB },
130
+ ...options.quality === void 0 ? {} : { quality: options.quality },
131
+ ...options.audio === void 0 ? {} : { audio: options.audio },
132
+ ...options.overwrite === void 0 ? {} : { overwrite: options.overwrite },
133
+ signal: extra.signal,
134
+ onProgress: notifications.notify
135
+ })
136
+ );
137
+ await notifications.drain();
138
+ return response;
139
+ }
140
+ );
141
+ server.registerTool(
142
+ "normalize_media",
143
+ {
144
+ description: "Inspect, plan, execute, and verify a normalized high-compatibility copy (H.264, yuv420p, faststart). Reports MCP progress when requested.",
145
+ inputSchema: {
146
+ input: z.string().min(1),
147
+ output: z.string().min(1),
148
+ trimStartSeconds: z.number().nonnegative().optional(),
149
+ durationSeconds: z.number().positive().optional(),
150
+ audio: z.enum(["preserve", "remove"]).optional(),
151
+ overwrite: z.boolean().optional()
152
+ }
153
+ },
154
+ async (options, extra) => {
155
+ const notifications = mcpProgress(extra);
156
+ const response = await safely(
157
+ async () => normalize({
158
+ input: options.input,
159
+ output: options.output,
160
+ ...options.trimStartSeconds === void 0 ? {} : { trimStartSeconds: options.trimStartSeconds },
161
+ ...options.durationSeconds === void 0 ? {} : { durationSeconds: options.durationSeconds },
162
+ ...options.audio === void 0 ? {} : { audio: options.audio },
163
+ ...options.overwrite === void 0 ? {} : { overwrite: options.overwrite },
164
+ signal: extra.signal,
165
+ onProgress: notifications.notify
166
+ })
167
+ );
168
+ await notifications.drain();
169
+ return response;
170
+ }
171
+ );
172
+ server.registerTool(
173
+ "extract_audio",
174
+ {
175
+ description: "Extract and verify audio from any media source. Reports MCP progress when requested.",
176
+ inputSchema: {
177
+ input: z.string().min(1),
178
+ output: z.string().min(1),
179
+ format: z.enum(["m4a", "mp3", "wav"]).optional(),
180
+ trimStartSeconds: z.number().nonnegative().optional(),
181
+ durationSeconds: z.number().positive().optional(),
182
+ overwrite: z.boolean().optional()
183
+ }
184
+ },
185
+ async (options, extra) => {
186
+ const notifications = mcpProgress(extra);
187
+ const response = await safely(
188
+ async () => extractAudio({
189
+ input: options.input,
190
+ output: options.output,
191
+ ...options.format === void 0 ? {} : { format: options.format },
192
+ ...options.trimStartSeconds === void 0 ? {} : { trimStartSeconds: options.trimStartSeconds },
193
+ ...options.durationSeconds === void 0 ? {} : { durationSeconds: options.durationSeconds },
194
+ ...options.overwrite === void 0 ? {} : { overwrite: options.overwrite },
195
+ signal: extra.signal,
196
+ onProgress: notifications.notify
197
+ })
198
+ );
199
+ await notifications.drain();
200
+ return response;
201
+ }
202
+ );
203
+ server.registerTool(
204
+ "extract_frame",
205
+ {
206
+ description: "Extract and verify a still frame from a video source. Reports MCP progress when requested.",
207
+ inputSchema: {
208
+ input: z.string().min(1),
209
+ output: z.string().min(1),
210
+ atSeconds: z.number().nonnegative().optional(),
211
+ format: z.enum(["jpg", "png"]).optional(),
212
+ overwrite: z.boolean().optional()
213
+ }
214
+ },
215
+ async (options, extra) => {
216
+ const notifications = mcpProgress(extra);
217
+ const response = await safely(
218
+ async () => extractFrame({
219
+ input: options.input,
220
+ output: options.output,
221
+ ...options.atSeconds === void 0 ? {} : { atSeconds: options.atSeconds },
222
+ ...options.format === void 0 ? {} : { format: options.format },
223
+ ...options.overwrite === void 0 ? {} : { overwrite: options.overwrite },
224
+ signal: extra.signal,
225
+ onProgress: notifications.notify
226
+ })
227
+ );
228
+ await notifications.drain();
229
+ return response;
230
+ }
231
+ );
232
+ server.registerTool(
233
+ "execute_media_plan",
234
+ {
235
+ description: "Execute a serialized semantic Media IR plan.",
236
+ inputSchema: {
237
+ plan: z.union([z.string().min(1), mediaPlanSchema]),
238
+ output: z.string().min(1),
239
+ overwrite: z.boolean().optional()
240
+ }
241
+ },
242
+ async ({ plan: input, output, overwrite }, extra) => {
243
+ const notifications = mcpProgress(extra);
244
+ const response = await safely(async () => {
245
+ const plan = normalizePlan(input);
246
+ const execution = await executePlan(plan, {
247
+ output,
248
+ ...overwrite === void 0 ? {} : { overwrite },
249
+ signal: extra.signal,
250
+ onProgress: notifications.notify
251
+ });
252
+ return {
253
+ output: execution.output,
254
+ verification: verifyMedia(await inspectMedia(execution.output), plan.expectations)
255
+ };
256
+ });
257
+ await notifications.drain();
258
+ return response;
259
+ }
260
+ );
261
+ server.registerTool(
262
+ "verify_media",
263
+ {
264
+ description: "Verify output media against a serialized semantic Media IR plan.",
265
+ inputSchema: {
266
+ output: z.string().min(1),
267
+ plan: z.union([z.string().min(1), mediaPlanSchema])
268
+ }
269
+ },
270
+ async ({ output, plan: input }) => safely(async () => {
271
+ const plan = normalizePlan(input);
272
+ return verifyMedia(await inspectMedia(output), plan.expectations);
273
+ })
274
+ );
275
+ return server;
276
+ }
277
+ function result(value) {
278
+ return { content: [{ type: "text", text: JSON.stringify(value) }] };
279
+ }
280
+ async function safely(operation) {
281
+ try {
282
+ return result(await operation());
283
+ } catch (error) {
284
+ const structured = error instanceof MediaError ? error.toJSON() : {
285
+ code: "UNEXPECTED_ERROR",
286
+ message: error instanceof Error ? error.message : String(error)
287
+ };
288
+ return { ...result(structured), isError: true };
289
+ }
290
+ }
291
+ function normalizePlan(input) {
292
+ return typeof input === "string" ? parsePlan(input) : validatePlan(input);
293
+ }
294
+ function cleanGoals(goals) {
295
+ return cleanObject(goals);
296
+ }
297
+ function cleanObject(value) {
298
+ return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== void 0));
299
+ }
300
+ function mcpProgress(extra) {
301
+ const progressToken = extra._meta?.progressToken;
302
+ let pending = Promise.resolve();
303
+ return {
304
+ notify: (progress) => {
305
+ if (progressToken === void 0) return;
306
+ pending = pending.then(
307
+ () => extra.sendNotification({
308
+ method: "notifications/progress",
309
+ params: {
310
+ progressToken,
311
+ progress: progress.percent,
312
+ total: 100,
313
+ message: `${progress.phase}: ${progress.message}`
314
+ }
315
+ })
316
+ ).catch(() => void 0);
317
+ },
318
+ drain: () => pending
319
+ };
320
+ }
321
+ async function startMcpServer() {
322
+ await createMcpServer().connect(new StdioServerTransport());
323
+ }
324
+ if (isMainModule()) {
325
+ startMcpServer().catch((error) => {
326
+ const output = error instanceof MediaError ? error.toJSON() : {
327
+ code: "UNEXPECTED_ERROR",
328
+ message: error instanceof Error ? error.message : String(error)
329
+ };
330
+ process.stderr.write(`${JSON.stringify(output)}
331
+ `);
332
+ process.exitCode = 1;
333
+ });
334
+ }
335
+ function isMainModule() {
336
+ if (process.argv[1] === void 0) return false;
337
+ try {
338
+ return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
339
+ } catch {
340
+ return false;
341
+ }
342
+ }
343
+ export {
344
+ createMcpServer,
345
+ startMcpServer
346
+ };
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@hadialmarzooq/agent-media-mcp",
3
+ "version": "0.1.0",
4
+ "description": "MCP server for semantic, replayable, and verified media transformations.",
5
+ "keywords": [
6
+ "media",
7
+ "agents",
8
+ "ffmpeg",
9
+ "mcp",
10
+ "model-context-protocol"
11
+ ],
12
+ "homepage": "https://github.com/HadiAlMarzooq/agent-media#readme",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/HadiAlMarzooq/agent-media.git",
16
+ "directory": "packages/mcp"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/HadiAlMarzooq/agent-media/issues"
20
+ },
21
+ "license": "MIT",
22
+ "engines": {
23
+ "node": ">=22.0.0"
24
+ },
25
+ "type": "module",
26
+ "bin": {
27
+ "agent-media-mcp": "./dist/index.js"
28
+ },
29
+ "main": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "dependencies": {
38
+ "@modelcontextprotocol/sdk": "1.30.0",
39
+ "zod": "^4.5.4",
40
+ "@hadialmarzooq/agent-media-ffmpeg": "0.1.0",
41
+ "@hadialmarzooq/agent-media-core": "0.1.0"
42
+ },
43
+ "scripts": {
44
+ "build": "tsup src/index.ts --format esm --dts",
45
+ "typecheck": "tsc --noEmit"
46
+ }
47
+ }