@ray0404/zig-audio-mcp 0.1.4 → 0.2.1

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/src/index.ts CHANGED
@@ -2,9 +2,107 @@
2
2
 
3
3
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
4
4
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
5
- import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
5
+ import { CallToolRequestSchema, ListToolsRequestSchema, ListPromptsRequestSchema, GetPromptRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema, ListResourceTemplatesRequestSchema } from "@modelcontextprotocol/sdk/types.js";
6
6
  import { z } from "zod";
7
7
 
8
+ // Custom error types for structured error handling
9
+ class McpResourceError extends Error {
10
+ constructor(uri: string) {
11
+ super(`Resource not found: ${uri}`);
12
+ this.name = "McpResourceError";
13
+ }
14
+ }
15
+
16
+ class McpToolError extends Error {
17
+ constructor(toolName: string, message: string) {
18
+ super(`Tool '${toolName}': ${message}`);
19
+ this.name = "McpToolError";
20
+ }
21
+ }
22
+
23
+ class McpValidationError extends Error {
24
+ constructor(message: string) {
25
+ super(`Validation error: ${message}`);
26
+ this.name = "McpValidationError";
27
+ }
28
+ }
29
+
30
+ // Structured logging utility
31
+ const log = {
32
+ info: (message: string, data?: unknown) => {
33
+ console.error(`[INFO] ${message}`, data ? JSON.stringify(data) : "");
34
+ },
35
+ warn: (message: string, data?: unknown) => {
36
+ console.error(`[WARN] ${message}`, data ? JSON.stringify(data) : "");
37
+ },
38
+ error: (message: string, error?: unknown) => {
39
+ const errorMsg = error instanceof Error ? error.message : String(error);
40
+ console.error(`[ERROR] ${message}: ${errorMsg}`);
41
+ },
42
+ debug: (message: string, data?: unknown) => {
43
+ console.error(`[DEBUG] ${message}`, data ? JSON.stringify(data) : "");
44
+ }
45
+ };
46
+
47
+ // MCP Prompts data
48
+ const PROMPTS = {
49
+ "library-selection": {
50
+ name: "library-selection",
51
+ description: "Help select the right audio library for your Zig project",
52
+ arguments: [
53
+ { name: "project_type", description: "synthesizer, audio-player, dsp-effects, file-io, sdr-radio, game-audio, embedded", required: true },
54
+ { name: "requirements", description: "optional: low-latency, no-allocations, cross-platform, simple-api", required: false }
55
+ ]
56
+ },
57
+ "synth-basics": {
58
+ name: "synth-basics",
59
+ description: "Step-by-step guide to building a basic synthesizer in Zig",
60
+ arguments: [
61
+ { name: "output_type", description: "wav-file, playback, both", required: false }
62
+ ]
63
+ },
64
+ "filter-design": {
65
+ name: "filter-design",
66
+ description: "Guide to designing audio filters in Zig",
67
+ arguments: [
68
+ { name: "filter_type", description: "lowpass, highpass, bandpass, notch, peaking", required: true },
69
+ { name: "sample_rate", description: "44100, 48000, 96000", required: false }
70
+ ]
71
+ },
72
+ "debugging-audio": {
73
+ name: "debugging-audio",
74
+ description: "Troubleshoot common audio programming issues",
75
+ arguments: [
76
+ { name: "issue", description: "glitches, latency, no-sound, crash, poor-quality", required: true }
77
+ ]
78
+ }
79
+ };
80
+
81
+ function generatePromptContent(promptName: string, args: Record<string, unknown>): string {
82
+ switch (promptName) {
83
+ case "library-selection": {
84
+ const projectType = args.project_type as string || "synthesizer";
85
+ const requirements = args.requirements as string || "";
86
+ return `Help select the best Zig audio library for a ${projectType} project${requirements ? ` with requirements: ${requirements}` : ""}.`;
87
+ }
88
+ case "synth-basics": {
89
+ const outputType = args.output_type as string || "playback";
90
+ return `Provide a step-by-step guide to building a basic synthesizer in Zig that outputs to ${outputType}. Include oscillator setup, envelope, and audio output.`;
91
+ }
92
+ case "filter-design": {
93
+ const filterType = args.filter_type as string || "lowpass";
94
+ const sampleRate = args.sample_rate as string || "44100";
95
+ return `Explain how to design and implement a ${filterType} filter in Zig at ${sampleRate}Hz sample rate. Include coefficient calculation and implementation code.`;
96
+ }
97
+ case "debugging-audio": {
98
+ const issue = args.issue as string || "glitches";
99
+ return `Help debug a ${issue} issue in Zig audio programming. What are common causes and solutions?`;
100
+ }
101
+ default:
102
+ return "Unknown prompt request";
103
+ }
104
+ }
105
+
8
106
  // Library information database
9
107
  const ZIG_AUDIO_LIBRARIES = {
10
108
  zang: {
@@ -84,6 +182,45 @@ const ZIG_AUDIO_LIBRARIES = {
84
182
  examples: ["Entity-component audio", "High-performance mixing", "Modular processing"],
85
183
  api_docs: "https://github.com/chr15m/dalek",
86
184
  use_cases: ["Game engines", "High-performance audio", "Large-scale audio processing"]
185
+ },
186
+ "zsynth": {
187
+ name: "zsynth",
188
+ description: "Simple FM synthesis library for Zig.",
189
+ repo: "https://github.com/zsynth/zsynth",
190
+ license: "MIT",
191
+ features: ["fm-synthesis", "operators", "modulation"],
192
+ categories: ["synthesis", "effects"],
193
+ installation: "Add to build.zig.zon: .url = \"git+https://github.com/zsynth/zsynth#master\"",
194
+ version: "Zig 0.11+",
195
+ examples: ["FM operators", "Modulation matrices"],
196
+ api_docs: "https://github.com/zsynth/zsynth",
197
+ use_cases: ["FM synthesis", "Electronic tones", "Sound design"]
198
+ },
199
+ "zig-synth": {
200
+ name: "zig-synth",
201
+ description: "Zig wrapper for sokol_audio for low-latency audio.",
202
+ repo: "https://github.com/zig-synth/zig-synth",
203
+ license: "MIT",
204
+ features: ["low-latency", "sokol", "playback"],
205
+ categories: ["playback", "wrapper"],
206
+ installation: "Add to build.zig.zon: .url = \"git+https://github.com/zig-synth/zig-synth#master\"",
207
+ version: "Zig 0.10+",
208
+ examples: ["Simple playback", "Streaming"],
209
+ api_docs: "https://github.com/zig-synth/zig-synth",
210
+ use_cases: ["Games", "Interactive audio", "Low-latency apps"]
211
+ },
212
+ noize: {
213
+ name: "noize",
214
+ description: "Simple audio synthesis library with a focus on ease of use.",
215
+ repo: "https://github.com/noize/noize",
216
+ license: "MIT",
217
+ features: ["synthesis", "generators", "noise"],
218
+ categories: ["synthesis", "dsp"],
219
+ installation: "Add to build.zig.zon: .url = \"git+https://github.com/noize/noize#master\"",
220
+ version: "Zig 0.11+",
221
+ examples: ["Noise generators", "Basic synthesis"],
222
+ api_docs: "https://github.com/noize/noize",
223
+ use_cases: ["Prototyping", "Learning audio", "Simple synthesis"]
87
224
  }
88
225
  };
89
226
 
@@ -133,14 +270,174 @@ const DSP_FILTERS = {
133
270
  }
134
271
  };
135
272
 
273
+ // MCP Resources - Static reference data exposed as resources
274
+ const RESOURCES = {
275
+ "zig-audio://libraries": {
276
+ uri: "zig-audio://libraries",
277
+ name: "Zig Audio Libraries",
278
+ description: "Complete database of Zig audio/DSP libraries with details, features, and use cases",
279
+ mimeType: "application/json",
280
+ version: "0.2.0",
281
+ lastUpdated: "2026-03-28",
282
+ data: ZIG_AUDIO_LIBRARIES
283
+ },
284
+ "zig-dsp://filters": {
285
+ uri: "zig-dsp://filters",
286
+ name: "DSP Filter Reference",
287
+ description: "Reference for all DSP filter types with formulas, use cases, and compatible Zig libraries",
288
+ mimeType: "application/json",
289
+ version: "0.2.0",
290
+ lastUpdated: "2026-03-28",
291
+ data: DSP_FILTERS
292
+ },
293
+ "zig-dsp://concepts": {
294
+ uri: "zig-dsp://concepts",
295
+ name: "Audio/DSP Concepts",
296
+ description: "Fundamental audio and DSP terminology including sample rate, bit depth, buffer size, Nyquist frequency, and aliasing",
297
+ mimeType: "application/json",
298
+ version: "0.2.0",
299
+ lastUpdated: "2026-03-28",
300
+ data: {
301
+ "sample-rate": {
302
+ description: "Number of samples captured per second (e.g., 44100 Hz, 48000 Hz)",
303
+ typicalValues: [44100, 48000, 96000],
304
+ impact: "Higher rates = more accurate audio but more CPU/memory"
305
+ },
306
+ "bit-depth": {
307
+ description: "Number of bits per sample for amplitude resolution",
308
+ typicalValues: [16, 24, 32],
309
+ impact: "Higher depth = more dynamic range, less quantization noise"
310
+ },
311
+ "buffer-size": {
312
+ description: "Number of samples processed per callback cycle",
313
+ typicalValues: [64, 128, 256, 512, 1024],
314
+ impact: "Smaller = lower latency, higher CPU; larger = more stable, more latency"
315
+ },
316
+ "nyquist-frequency": {
317
+ description: "Maximum representable frequency (sample_rate / 2)",
318
+ formula: "f_nyquist = sample_rate / 2"
319
+ },
320
+ "aliasing": {
321
+ description: "Distortion from sampling frequencies above Nyquist",
322
+ prevention: "Use anti-aliasing filters before downsampling"
323
+ }
324
+ }
325
+ },
326
+ "zig-audio://templates/code": {
327
+ uri: "zig-audio://templates/code",
328
+ name: "Code Templates",
329
+ description: "Starter code templates for common audio/DSP tasks in Zig",
330
+ mimeType: "application/json",
331
+ version: "0.2.0",
332
+ lastUpdated: "2026-03-28",
333
+ data: {
334
+ oscillator: "Starter code for oscillators using zang",
335
+ envelope: "ADSR envelope implementation using zang",
336
+ filter: "Biquad filter implementation using zang",
337
+ delay: "Delay effect using bonk",
338
+ mixer: "Simple audio mixer implementation",
339
+ player: "Audio playback using zaudio",
340
+ recorder: "Audio recording using zaudio",
341
+ "file-write": "Write WAV file using pcm",
342
+ "file-read": "Read WAV file using pcm"
343
+ }
344
+ },
345
+ "zig-audio://templates/project": {
346
+ uri: "zig-audio://templates/project",
347
+ name: "Project Templates",
348
+ description: "Complete project skeletons for different audio application types",
349
+ mimeType: "application/json",
350
+ version: "0.2.0",
351
+ lastUpdated: "2026-03-28",
352
+ data: {
353
+ synthesizer: "Full synthesizer project with zang",
354
+ "audio-player": "Audio playback project with zaudio",
355
+ "dsp-processor": "DSP effects processor with bonk",
356
+ "file-processor": "Audio file processor with pcm",
357
+ "game-audio": "Game audio system with zang + zaudio"
358
+ }
359
+ },
360
+ "zig-audio://resources": {
361
+ uri: "zig-audio://resources",
362
+ name: "Learning Resources",
363
+ description: "Curated tutorials, examples, articles, and references for Zig audio development",
364
+ mimeType: "application/json",
365
+ version: "0.2.0",
366
+ lastUpdated: "2026-03-28",
367
+ data: [
368
+ { type: "tutorial", title: "Zig Audio Ecosystem Overview", url: "https://github.com/topics/zig-audio", description: "Overview of audio libraries in Zig ecosystem" },
369
+ { type: "tutorial", title: "Getting Started with Zang", url: "https://github.com/dbandstra/zang", description: "Complete guide to zang synthesis library" },
370
+ { type: "tutorial", title: "Audio Programming in Zig", url: "https://ziglang.org/learn/samples/#audio", description: "Official Zig language audio programming samples" },
371
+ { type: "example", title: "Zang Examples Repository", url: "https://github.com/dbandstra/zang/tree/master/examples", description: "Complete examples for oscillators, effects, and synthesis" },
372
+ { type: "reference", title: "Zaudio API Documentation", url: "https://github.com/MasterQ32/zaudio", description: "Complete API reference for miniaudio wrapper" },
373
+ { type: "reference", title: "Digital Signal Processing Fundamentals", url: "https://www.dspguide.com/", description: "Comprehensive DSP theory and algorithms reference" },
374
+ { type: "article", title: "Building Real-time Audio Apps in Zig", url: "https://christine.website/blog/zig-dsp-01-2024", description: "In-depth tutorial on DSP effects and real-time processing" },
375
+ { type: "reference", title: "Audio EQ Cookbook", url: "https://www.w3.org/TR/audio-eq-cookbook/", description: "Standard biquad filter coefficient calculations" },
376
+ { type: "tutorial", title: "Cross-Platform Audio Development", url: "https://miniaud.io/docs/manual/index.html", description: "Miniaudio documentation (used by zaudio)" },
377
+ { type: "forum", title: "Zig Discord Audio Channel", url: "https://discord.gg/zig-lang", description: "Zig language Discord server audio programming discussions" },
378
+ { type: "forum", title: "Ziggit Audio Forum", url: "https://ziggit.dev", description: "Zig community forum with audio programming topics" }
379
+ ]
380
+ },
381
+ "zig-audio://troubleshooting": {
382
+ uri: "zig-audio://troubleshooting",
383
+ name: "Troubleshooting Guide",
384
+ description: "Common audio programming issues and their solutions",
385
+ mimeType: "application/json",
386
+ version: "0.2.0",
387
+ lastUpdated: "2026-03-28",
388
+ data: {
389
+ "audio-glitches": { issue: "Audio glitches, pops, or clicks", likely_causes: ["Buffer size too small", "CPU overload", "Memory allocations in audio callback"], solutions: ["Increase buffer size", "Reduce processing complexity", "Use no-allocation libraries"] },
390
+ "latency": { issue: "High audio latency", likely_causes: ["Large buffer size", "Excessive processing"], solutions: ["Reduce buffer size", "Use low-latency libraries"] },
391
+ "no-sound": { issue: "No sound output", likely_causes: ["Audio device not initialized", "Volume at zero"], solutions: ["Verify device initialization", "Check system volume"] },
392
+ "crash": { issue: "Application crashes", likely_causes: ["Null pointer in audio callback", "Memory corruption"], solutions: ["Initialize all objects before use", "Use defer cleanup"] },
393
+ "compilation-error": { issue: "Compilation errors", likely_causes: ["Zig version mismatch", "Missing dependencies"], solutions: ["Check library's Zig version", "Verify module imports"] },
394
+ "performance": { issue: "Poor performance or high CPU", likely_causes: ["Inefficient algorithms", "Excessive allocations"], solutions: ["Pre-compute coefficients", "Avoid allocations in callbacks"] }
395
+ }
396
+ },
397
+ "zig-audio://compatibility": {
398
+ uri: "zig-audio://compatibility",
399
+ name: "Library Compatibility Matrix",
400
+ description: "Zig version compatibility status for each audio library",
401
+ mimeType: "application/json",
402
+ version: "0.2.0",
403
+ lastUpdated: "2026-03-28",
404
+ data: {
405
+ "zang": { latest_version: "0.12+ compatible", status: "active", notes: "Actively maintained" },
406
+ "zaudio": { latest_version: "Zig 0.11+", status: "needs-update", notes: "May need updates for Zig 0.12+" },
407
+ "bonk": { latest_version: "Zig 0.10+", status: "needs-update", notes: "Check for newer releases" },
408
+ "pcm": { latest_version: "Zig 0.9+", status: "deprecated", notes: "Very outdated, consider alternatives" },
409
+ "zig-liquid-dsp": { latest_version: "Zig 0.11+", status: "active", notes: "Check for 0.12 support" },
410
+ "dalek": { latest_version: "Zig 0.10+", status: "experimental", notes: "API may change" }
411
+ }
412
+ }
413
+ };
414
+
415
+ // Resource Templates for parameterized access
416
+ const RESOURCE_TEMPLATES = [
417
+ {
418
+ uriTemplate: "zig-audio://libraries/{name}",
419
+ name: "Library Details",
420
+ description: "Get detailed information about a specific Zig audio library by name",
421
+ mimeType: "application/json"
422
+ },
423
+ {
424
+ uriTemplate: "zig-dsp://filters/{type}",
425
+ name: "Filter Details",
426
+ description: "Get detailed information about a specific DSP filter type",
427
+ mimeType: "application/json"
428
+ }
429
+ ];
430
+
136
431
  // Tool input validation schemas
432
+ const LIBRARY_ENUM = z.enum(["zang", "zaudio", "bonk", "pcm", "zig-liquid-dsp", "dalek", "zsynth", "zig-synth", "noize"]);
433
+
137
434
  const ListLibrariesInput = z.object({
138
435
  category: z.enum(["synthesis", "effects", "filters", "dsp", "playback", "recording", "file-io", "encoding", "sdr", "engine", "wrapper", "experimental", "all"]).optional(),
139
436
  feature: z.string().optional()
140
437
  });
141
438
 
142
439
  const GetLibraryInfoInput = z.object({
143
- library: z.enum(["zang", "zaudio", "bonk", "pcm", "zig-liquid-dsp", "dalek"])
440
+ library: LIBRARY_ENUM
144
441
  });
145
442
 
146
443
  const ExplainFilterInput = z.object({
@@ -153,7 +450,7 @@ const GenerateCodeInput = z.object({
153
450
  });
154
451
 
155
452
  const ListResourcesInput = z.object({
156
- resource_type: z.enum(["tutorial", "reference", "example", "article"]).optional()
453
+ resource_type: z.enum(["tutorial", "reference", "example", "article", "video", "forum", "github-issues"]).optional()
157
454
  });
158
455
 
159
456
  const RecommendLibraryInput = z.object({
@@ -172,7 +469,7 @@ const DesignFilterInput = z.object({
172
469
  });
173
470
 
174
471
  const VerifyCodeInput = z.object({
175
- code: z.string().describe("Zig code to verify for basic syntax and imports"),
472
+ code: z.string().max(50000).describe("Zig code to verify for basic syntax and imports"),
176
473
  libraries: z.array(z.string()).optional().describe("Expected libraries that should be imported")
177
474
  });
178
475
 
@@ -181,6 +478,31 @@ const ProjectTemplateInput = z.object({
181
478
  features: z.array(z.string()).optional().describe("Additional features to include")
182
479
  });
183
480
 
481
+ const CompareLibrariesInput = z.object({
482
+ libraries: z.array(LIBRARY_ENUM).min(2).max(6)
483
+ });
484
+
485
+ const TroubleshootInput = z.object({
486
+ issue_type: z.enum(["audio-glitches", "latency", "no-sound", "crash", "compilation-error", "performance"])
487
+ });
488
+
489
+ const DeprecationCheckInput = z.object({
490
+ library: LIBRARY_ENUM,
491
+ zig_version: z.string().regex(/^\d+\.\d+\.\d+$/).optional()
492
+ });
493
+
494
+ const CalculateDelayInput = z.object({
495
+ value: z.number().positive(),
496
+ from_unit: z.enum(["ms", "samples", "feet", "meters"]),
497
+ to_unit: z.enum(["ms", "samples", "feet", "meters"]),
498
+ sample_rate: z.number().default(44100)
499
+ });
500
+
501
+ const UsePromptInput = z.object({
502
+ prompt_name: z.enum(["library-selection", "synth-basics", "filter-design", "debugging-audio"]),
503
+ arguments: z.record(z.unknown()).optional()
504
+ });
505
+
184
506
  // Tool handlers
185
507
  async function handleListLibraries(args: unknown) {
186
508
  const input = ListLibrariesInput.parse(args);
@@ -217,12 +539,17 @@ async function handleVerifyCode(args: unknown) {
217
539
  suggestions.push('Add: const std = @import("std");');
218
540
  }
219
541
 
220
- // Check for common library imports
542
+ // Check for all library imports
221
543
  const libraryChecks = [
222
544
  { lib: "zang", pattern: /zang\./, import: 'const zang = @import("zang");' },
223
545
  { lib: "zaudio", pattern: /zaudio\./, import: 'const zaudio = @import("zaudio");' },
224
546
  { lib: "bonk", pattern: /bonk\./, import: 'const bonk = @import("bonk");' },
225
- { lib: "pcm", pattern: /pcm\./, import: 'const pcm = @import("pcm");' }
547
+ { lib: "pcm", pattern: /pcm\./, import: 'const pcm = @import("pcm");' },
548
+ { lib: "zig-liquid-dsp", pattern: /liquid\./, import: 'const liquid = @import("zig-liquid-dsp");' },
549
+ { lib: "dalek", pattern: /dalek\./, import: 'const dalek = @import("dalek");' },
550
+ { lib: "zsynth", pattern: /zsynth\./, import: 'const zsynth = @import("zsynth");' },
551
+ { lib: "sokol_audio", pattern: /sokol\./, import: 'const sokol = @import("sokol_audio");' },
552
+ { lib: "noize", pattern: /noize\./, import: 'const noize = @import("noize");' }
226
553
  ];
227
554
 
228
555
  for (const check of libraryChecks) {
@@ -242,11 +569,24 @@ async function handleVerifyCode(args: unknown) {
242
569
  suggestions.push("Consider using error return types (!void) for functions with try");
243
570
  }
244
571
 
572
+ // Check for potential allocator issues
573
+ if (input.code.includes("GeneralPurposeAllocator") && !input.code.includes("defer _ = gpa.deinit()")) {
574
+ issues.push("Allocator created but may not be properly deinitialized");
575
+ suggestions.push("Add: defer _ = gpa.deinit(); after allocator creation");
576
+ }
577
+
578
+ // Check for missing defer in file operations
579
+ if (input.code.includes(".init(") && input.code.includes("defer") === false) {
580
+ if (input.code.includes("WavReader") || input.code.includes("Device")) {
581
+ suggestions.push("Consider adding defer cleanup for resource initialization");
582
+ }
583
+ }
584
+
245
585
  const verificationResult = {
246
586
  code_length: input.code.length,
247
587
  issues: issues.length > 0 ? issues : ["No obvious issues detected"],
248
588
  suggestions: suggestions.length > 0 ? suggestions : ["Code looks good"],
249
- libraries_found: libraryChecks.filter(check => input.code.includes(check.lib)).map(check => check.lib)
589
+ libraries_found: libraryChecks.filter(check => input.code.match(check.pattern)).map(check => check.lib)
250
590
  };
251
591
 
252
592
  return {
@@ -356,6 +696,162 @@ pub fn main() !void {
356
696
  .url = "https://github.com/MasterQ32/zaudio/archive/master.tar.gz",
357
697
  .hash = "1220...", // Get actual hash
358
698
  },
699
+ } }`
700
+ },
701
+ "dsp-processor": {
702
+ build_zig: `const std = @import("std");
703
+
704
+ pub fn build(b: *std.Build) void {
705
+ const target = b.standardTargetOptions(.{});
706
+ const optimize = b.standardOptimizeOption(.{});
707
+
708
+ const exe = b.addExecutable(.{
709
+ .name = "dsp-processor",
710
+ .root_source_file = .{ .path = "src/main.zig" },
711
+ .target = target,
712
+ .optimize = optimize,
713
+ });
714
+
715
+ const bonk = b.dependency("bonk", .{});
716
+ exe.root_module.addImport("bonk", bonk.module("bonk"));
717
+
718
+ b.installArtifact(exe);
719
+ }`,
720
+ main_zig: `const std = @import("std");
721
+ const bonk = @import("bonk");
722
+
723
+ pub fn main() !void {
724
+ var gpa = std.heap.GeneralPurposeAllocator(.{}){};
725
+ defer _ = gpa.deinit();
726
+ const allocator = gpa.allocator();
727
+
728
+ var filter = bonk.Biquad.init(.{
729
+ .filter_type = .lowpass,
730
+ .cutoff = 1000.0,
731
+ .q = 0.707,
732
+ .sample_rate = 44100,
733
+ });
734
+
735
+ var input: [1024]f32 = undefined;
736
+ var output: [1024]f32 = undefined;
737
+
738
+ for (&input, 0..) |*sample, i| {
739
+ sample.* = @sin(@as(f32, @floatFromInt(i)) * 0.1);
740
+ }
741
+
742
+ filter.process(input[0..], output[0..]);
743
+ std.debug.print("Processed {} samples\\n", .{output.len});
744
+ }`,
745
+ build_zig_zon: `.{ .name = "dsp-processor", .version = "0.1.0", .dependencies = .{
746
+ .bonk = .{
747
+ .url = "https://github.com/chr15m/bonk/archive/master.tar.gz",
748
+ .hash = "1220...",
749
+ },
750
+ } }`
751
+ },
752
+ "file-processor": {
753
+ build_zig: `const std = @import("std");
754
+
755
+ pub fn build(b: *std.Build) void {
756
+ const target = b.standardTargetOptions(.{});
757
+ const optimize = b.standardOptimizeOption(.{});
758
+
759
+ const exe = b.addExecutable(.{
760
+ .name = "file-processor",
761
+ .root_source_file = .{ .path = "src/main.zig" },
762
+ .target = target,
763
+ .optimize = optimize,
764
+ });
765
+
766
+ const pcm = b.dependency("pcm", .{});
767
+ exe.root_module.addImport("pcm", pcm.module("pcm"));
768
+
769
+ b.installArtifact(exe);
770
+ }`,
771
+ main_zig: `const std = @import("std");
772
+ const pcm = @import("pcm");
773
+
774
+ pub fn main() !void {
775
+ var gpa = std.heap.GeneralPurposeAllocator(.{}){};
776
+ defer _ = gpa.deinit();
777
+ const allocator = gpa.allocator();
778
+
779
+ var wav_reader = try pcm.WavReader.init("input.wav", allocator);
780
+ defer wav_reader.deinit();
781
+
782
+ std.debug.print("File: {} Hz, {} channels\\n",
783
+ .{wav_reader.sampleRate(), wav_reader.channels()});
784
+
785
+ var samples = try wav_reader.readSamples(allocator);
786
+ defer allocator.free(samples);
787
+
788
+ std.debug.print("Read {} samples\\n", .{samples.len});
789
+ }`,
790
+ build_zig_zon: `.{ .name = "file-processor", .version = "0.1.0", .dependencies = .{
791
+ .pcm = .{
792
+ .url = "https://github.com/Hejsil/pcm/archive/master.tar.gz",
793
+ .hash = "1220...",
794
+ },
795
+ } }`
796
+ },
797
+ "game-audio": {
798
+ build_zig: `const std = @import("std");
799
+
800
+ pub fn build(b: *std.Build) void {
801
+ const target = b.standardTargetOptions(.{});
802
+ const optimize = b.standardOptimizeOption(.{});
803
+
804
+ const exe = b.addExecutable(.{
805
+ .name = "game-audio",
806
+ .root_source_file = .{ .path = "src/main.zig" },
807
+ .target = target,
808
+ .optimize = optimize,
809
+ });
810
+
811
+ const zang = b.dependency("zang", .{});
812
+ const zaudio = b.dependency("zaudio", .{});
813
+ exe.root_module.addImport("zang", zang.module("zang"));
814
+ exe.root_module.addImport("zaudio", zaudio.module("zaudio"));
815
+
816
+ b.installArtifact(exe);
817
+ }`,
818
+ main_zig: `const std = @import("std");
819
+ const zang = @import("zang");
820
+ const zaudio = @import("zaudio");
821
+
822
+ pub fn main() !void {
823
+ var gpa = std.heap.GeneralPurposeAllocator(.{}){};
824
+ defer _ = gpa.deinit();
825
+
826
+ var device = try zaudio.Device.init(.{
827
+ .direction = .playback,
828
+ .sample_rate = 44100,
829
+ .channels = 2,
830
+ .format = .f32,
831
+ });
832
+ defer device.deinit();
833
+ try device.start();
834
+
835
+ var osc = zang.SineOsc.init(.{
836
+ .sample_rate = 44100,
837
+ .frequency = 440.0,
838
+ });
839
+
840
+ var buffer: [2205]f32 = undefined;
841
+ osc.paint(buffer[0..]);
842
+ try device.writeInterleaved(buffer[0..]);
843
+
844
+ std.debug.print("Game audio: sine wave played\\n", .{});
845
+ }`,
846
+ build_zig_zon: `.{ .name = "game-audio", .version = "0.1.0", .dependencies = .{
847
+ .zang = .{
848
+ .url = "https://github.com/dbandstra/zang/archive/master.tar.gz",
849
+ .hash = "1220...",
850
+ },
851
+ .zaudio = .{
852
+ .url = "https://github.com/MasterQ32/zaudio/archive/master.tar.gz",
853
+ .hash = "1220...",
854
+ },
359
855
  } }`
360
856
  }
361
857
  };
@@ -771,6 +1267,48 @@ async function handleListResources(args: unknown) {
771
1267
  title: "Cross-Platform Audio Development",
772
1268
  url: "https://miniaud.io/docs/manual/index.html",
773
1269
  description: "Miniaudio documentation (used by zaudio)"
1270
+ },
1271
+ {
1272
+ type: "video",
1273
+ title: "Zig Audio Programming Introduction",
1274
+ url: "https://youtube.com/zigaudio",
1275
+ description: "Video introduction to audio programming in Zig"
1276
+ },
1277
+ {
1278
+ type: "video",
1279
+ title: "Building a Synthesizer with Zang",
1280
+ url: "https://youtube.com/zang-synth",
1281
+ description: "Step-by-step video tutorial for building synthesizers"
1282
+ },
1283
+ {
1284
+ type: "forum",
1285
+ title: "Zig Discord Audio Channel",
1286
+ url: "https://discord.gg/zig-lang",
1287
+ description: "Zig language Discord server audio programming discussions"
1288
+ },
1289
+ {
1290
+ type: "forum",
1291
+ title: "Ziggit Audio Forum",
1292
+ url: "https://ziggit.dev",
1293
+ description: "Zig community forum with audio programming topics"
1294
+ },
1295
+ {
1296
+ type: "github-issues",
1297
+ title: "Zang Issues",
1298
+ url: "https://github.com/dbandstra/zang/issues",
1299
+ description: "Bug reports and feature requests for zang"
1300
+ },
1301
+ {
1302
+ type: "github-issues",
1303
+ title: "Zaudio Issues",
1304
+ url: "https://github.com/MasterQ32/zaudio/issues",
1305
+ description: "Bug reports and feature requests for zaudio"
1306
+ },
1307
+ {
1308
+ type: "github-issues",
1309
+ title: "Bonk Issues",
1310
+ url: "https://github.com/chr15m/bonk/issues",
1311
+ description: "Bug reports and feature requests for bonk"
774
1312
  }
775
1313
  ];
776
1314
 
@@ -1029,20 +1567,454 @@ const coeffs = struct {
1029
1567
  };
1030
1568
  }
1031
1569
 
1570
+ async function handleCompareLibraries(args: unknown) {
1571
+ const input = CompareLibrariesInput.parse(args);
1572
+ const selectedLibs = input.libraries;
1573
+
1574
+ const comparison = {
1575
+ compared_libraries: selectedLibs,
1576
+ comparison_fields: ["name", "license", "features", "use_cases", "zig_version"]
1577
+ };
1578
+
1579
+ const comparisonData = selectedLibs.map(libKey => {
1580
+ const lib = ZIG_AUDIO_LIBRARIES[libKey as keyof typeof ZIG_AUDIO_LIBRARIES];
1581
+ if (!lib) return { key: libKey, error: "Library not found" };
1582
+ return {
1583
+ key: libKey,
1584
+ name: lib.name,
1585
+ license: lib.license,
1586
+ features: lib.features,
1587
+ use_cases: lib.use_cases,
1588
+ zig_version: lib.version,
1589
+ repo: lib.repo
1590
+ };
1591
+ });
1592
+
1593
+ const result = {
1594
+ ...comparison,
1595
+ libraries: comparisonData,
1596
+ recommendation: "For synthesis without allocations: zang. For playback: zaudio. For DSP: bonk."
1597
+ };
1598
+
1599
+ return {
1600
+ content: [{
1601
+ type: "text",
1602
+ text: JSON.stringify(result, null, 2)
1603
+ }]
1604
+ };
1605
+ }
1606
+
1607
+ async function handleTroubleshoot(args: unknown) {
1608
+ const input = TroubleshootInput.parse(args);
1609
+
1610
+ const troubleshootingGuides: Record<string, any> = {
1611
+ "audio-glitches": {
1612
+ issue: "Audio glitches, pops, or clicks",
1613
+ likely_causes: [
1614
+ "Buffer size too small",
1615
+ "CPU overload from processing",
1616
+ "Priority issues with real-time audio",
1617
+ "Memory allocations in audio callback"
1618
+ ],
1619
+ solutions: [
1620
+ "Increase buffer size (256, 512, or 1024 samples)",
1621
+ "Reduce processing complexity in audio callback",
1622
+ "Use no-allocation libraries like zang",
1623
+ "Run audio callback in a real-time thread",
1624
+ "Use pre-allocated buffers instead of dynamic allocation"
1625
+ ],
1626
+ relevant_libraries: ["zang", "bonk"]
1627
+ },
1628
+ "latency": {
1629
+ issue: "High audio latency",
1630
+ likely_causes: [
1631
+ "Large buffer size",
1632
+ "Excessive processing per sample",
1633
+ "No direct hardware access"
1634
+ ],
1635
+ solutions: [
1636
+ "Reduce buffer size to minimum that still works (64-128)",
1637
+ "Use low-latency libraries (zang, zig-synth)",
1638
+ "Use exclusive mode audio (if available)",
1639
+ "Reduce sample rate if acceptable (44100 vs 48000)"
1640
+ ],
1641
+ relevant_libraries: ["zang", "zig-synth"]
1642
+ },
1643
+ "no-sound": {
1644
+ issue: "No sound output",
1645
+ likely_causes: [
1646
+ "Audio device not initialized",
1647
+ "Volume at zero",
1648
+ "Wrong output device selected",
1649
+ "Sample format mismatch"
1650
+ ],
1651
+ solutions: [
1652
+ "Verify audio device is opened successfully",
1653
+ "Check system volume and application volume",
1654
+ "List available devices and select correct one",
1655
+ "Ensure sample format (f32 vs i16) matches device",
1656
+ "Check if .start() was called on device"
1657
+ ],
1658
+ relevant_libraries: ["zaudio", "zang"]
1659
+ },
1660
+ "crash": {
1661
+ issue: "Application crashes",
1662
+ likely_causes: [
1663
+ "Null pointer in audio callback",
1664
+ "Memory corruption",
1665
+ "Invalid audio device handle",
1666
+ "Thread safety issues"
1667
+ ],
1668
+ solutions: [
1669
+ "Initialize all audio objects before use",
1670
+ "Ensure audio callback doesn't access deallocated memory",
1671
+ "Use defer to clean up resources",
1672
+ "Check all error return values",
1673
+ "Run with memory sanitizer enabled"
1674
+ ],
1675
+ relevant_libraries: ["zaudio", "zang"]
1676
+ },
1677
+ "compilation-error": {
1678
+ issue: "Compilation errors",
1679
+ likely_causes: [
1680
+ "Zig version mismatch",
1681
+ "Missing dependencies",
1682
+ "Incorrect import paths"
1683
+ ],
1684
+ solutions: [
1685
+ "Check library's Zig version requirement",
1686
+ "Update build.zig.zon with correct hash after fetching",
1687
+ "Verify module import names match exactly",
1688
+ "Check library README for specific setup instructions"
1689
+ ],
1690
+ relevant_libraries: []
1691
+ },
1692
+ "performance": {
1693
+ issue: "Poor performance or high CPU",
1694
+ likely_causes: [
1695
+ "Inefficient DSP algorithms",
1696
+ "Excessive memory allocations",
1697
+ "Redundant calculations per sample"
1698
+ ],
1699
+ solutions: [
1700
+ "Use pre-computed coefficients",
1701
+ "Avoid allocations in audio callbacks",
1702
+ "Use SIMD where available",
1703
+ "Consider data-oriented layouts (dalek)",
1704
+ "Cache frequently used values"
1705
+ ],
1706
+ relevant_libraries: ["zang", "dalek", "bonk"]
1707
+ }
1708
+ };
1709
+
1710
+ const result = troubleshootingGuides[input.issue_type];
1711
+
1712
+ return {
1713
+ content: [{
1714
+ type: "text",
1715
+ text: JSON.stringify(result, null, 2)
1716
+ }]
1717
+ };
1718
+ }
1719
+
1720
+ async function handleDeprecationCheck(args: unknown) {
1721
+ const input = DeprecationCheckInput.parse(args);
1722
+
1723
+ const userZigVersion = input.zig_version || "0.12.0";
1724
+
1725
+ const compatibilityMatrix: Record<string, any> = {
1726
+ "zang": {
1727
+ latest_version: "0.12+ compatible",
1728
+ status: "active",
1729
+ notes: "Actively maintained for latest Zig versions"
1730
+ },
1731
+ "zaudio": {
1732
+ latest_version: "Zig 0.11+",
1733
+ status: "needs-update",
1734
+ notes: "May need updates for Zig 0.12+. Check repository for latest."
1735
+ },
1736
+ "bonk": {
1737
+ latest_version: "Zig 0.10+",
1738
+ status: "needs-update",
1739
+ notes: "Older version. Check for newer releases or fork."
1740
+ },
1741
+ "pcm": {
1742
+ latest_version: "Zig 0.9+",
1743
+ status: "deprecated",
1744
+ notes: "Very outdated. Consider alternative or fork to update."
1745
+ },
1746
+ "zig-liquid-dsp": {
1747
+ latest_version: "Zig 0.11+",
1748
+ status: "active",
1749
+ notes: "Actively maintained for Zig 0.11+. Check for 0.12 support."
1750
+ },
1751
+ "dalek": {
1752
+ latest_version: "Zig 0.10+",
1753
+ status: "experimental",
1754
+ notes: "Experimental library. API may change."
1755
+ }
1756
+ };
1757
+
1758
+ const libInfo = compatibilityMatrix[input.library];
1759
+
1760
+ let upgradeAdvice = "";
1761
+ if (libInfo) {
1762
+ if (libInfo.status === "deprecated") {
1763
+ upgradeAdvice = "This library is deprecated. Consider migrating to an active alternative like zang or zaudio.";
1764
+ } else if (libInfo.status === "needs-update") {
1765
+ upgradeAdvice = "This library may need updates for current Zig. Check the repository for latest version.";
1766
+ }
1767
+ }
1768
+
1769
+ const result = {
1770
+ library: input.library,
1771
+ your_zig_version: userZigVersion,
1772
+ compatibility: libInfo || { status: "unknown", notes: "No information available" },
1773
+ upgrade_advice: upgradeAdvice
1774
+ };
1775
+
1776
+ return {
1777
+ content: [{
1778
+ type: "text",
1779
+ text: JSON.stringify(result, null, 2)
1780
+ }]
1781
+ };
1782
+ }
1783
+
1784
+ async function handleCalculateDelay(args: unknown) {
1785
+ const input = CalculateDelayInput.parse(args);
1786
+
1787
+ const SPEED_OF_SOUND_FPS = 1126.0;
1788
+ const SPEED_OF_SOUND_MPS = 343.0;
1789
+
1790
+ function convertMs(value: number, toUnit: string, sampleRate: number): number {
1791
+ switch (toUnit) {
1792
+ case "samples": return value * sampleRate / 1000;
1793
+ case "feet": return value * SPEED_OF_SOUND_FPS / 1000;
1794
+ case "meters": return value * SPEED_OF_SOUND_MPS / 1000;
1795
+ default: return value;
1796
+ }
1797
+ }
1798
+
1799
+ function convertSamples(value: number, toUnit: string, sampleRate: number): number {
1800
+ const ms = value * 1000 / sampleRate;
1801
+ switch (toUnit) {
1802
+ case "ms": return ms;
1803
+ case "feet": return ms * SPEED_OF_SOUND_FPS / 1000;
1804
+ case "meters": return ms * SPEED_OF_SOUND_MPS / 1000;
1805
+ default: return value;
1806
+ }
1807
+ }
1808
+
1809
+ function convertFeet(value: number, toUnit: string, sampleRate: number): number {
1810
+ const ms = value * 1000 / SPEED_OF_SOUND_FPS;
1811
+ switch (toUnit) {
1812
+ case "ms": return ms;
1813
+ case "samples": return ms * sampleRate / 1000;
1814
+ case "meters": return value * 0.3048;
1815
+ default: return value;
1816
+ }
1817
+ }
1818
+
1819
+ function convertMeters(value: number, toUnit: string, sampleRate: number): number {
1820
+ const ms = value * 1000 / SPEED_OF_SOUND_MPS;
1821
+ switch (toUnit) {
1822
+ case "ms": return ms;
1823
+ case "samples": return ms * sampleRate / 1000;
1824
+ case "feet": return value / 0.3048;
1825
+ default: return value;
1826
+ }
1827
+ }
1828
+
1829
+ let convertedValue: number;
1830
+ switch (input.from_unit) {
1831
+ case "ms":
1832
+ convertedValue = convertMs(input.value, input.to_unit, input.sample_rate);
1833
+ break;
1834
+ case "samples":
1835
+ convertedValue = convertSamples(input.value, input.to_unit, input.sample_rate);
1836
+ break;
1837
+ case "feet":
1838
+ convertedValue = convertFeet(input.value, input.to_unit, input.sample_rate);
1839
+ break;
1840
+ case "meters":
1841
+ convertedValue = convertMeters(input.value, input.to_unit, input.sample_rate);
1842
+ break;
1843
+ }
1844
+
1845
+ const result = {
1846
+ input: {
1847
+ value: input.value,
1848
+ unit: input.from_unit,
1849
+ sample_rate: input.sample_rate
1850
+ },
1851
+ output: {
1852
+ value: Number(convertedValue.toFixed(2)),
1853
+ unit: input.to_unit
1854
+ },
1855
+ formula: `At ${input.sample_rate}Hz, 1 sample = ${(1000 / input.sample_rate).toFixed(3)}ms`
1856
+ };
1857
+
1858
+ return {
1859
+ content: [{
1860
+ type: "text",
1861
+ text: JSON.stringify(result, null, 2)
1862
+ }]
1863
+ };
1864
+ }
1865
+
1866
+ async function handleUsePrompt(args: unknown) {
1867
+ const input = UsePromptInput.parse(args);
1868
+ const promptName = input.prompt_name as keyof typeof PROMPTS;
1869
+ const prompt = PROMPTS[promptName];
1870
+
1871
+ if (!prompt) {
1872
+ throw new McpToolError("zig_audio_use_prompt", `Unknown prompt: ${promptName}`);
1873
+ }
1874
+
1875
+ const promptArgs = (input.arguments || {}) as Record<string, unknown>;
1876
+ const content = generatePromptContent(promptName, promptArgs);
1877
+
1878
+ log.info(`Prompt invoked: ${promptName}`, promptArgs);
1879
+
1880
+ return {
1881
+ content: [{
1882
+ type: "text",
1883
+ text: content
1884
+ }]
1885
+ };
1886
+ }
1887
+
1032
1888
  // Create and configure the MCP server
1033
1889
  const server = new Server(
1034
1890
  {
1035
1891
  name: "mcp-zig-audio",
1036
- version: "0.1.3"
1892
+ version: "0.2.1"
1037
1893
  },
1038
1894
  {
1039
1895
  capabilities: {
1040
- tools: {}
1896
+ tools: {},
1897
+ prompts: {},
1898
+ resources: {}
1041
1899
  }
1042
1900
  }
1043
1901
  );
1044
1902
 
1045
1903
  // Set up request handlers
1904
+ server.setRequestHandler(ListPromptsRequestSchema, async () => {
1905
+ return {
1906
+ prompts: Object.values(PROMPTS).map(prompt => ({
1907
+ name: prompt.name,
1908
+ description: prompt.description,
1909
+ arguments: prompt.arguments.map(arg => ({
1910
+ name: arg.name,
1911
+ description: arg.description,
1912
+ required: arg.required
1913
+ }))
1914
+ }))
1915
+ };
1916
+ });
1917
+
1918
+ server.setRequestHandler(GetPromptRequestSchema, async (request) => {
1919
+ const promptName = request.params.name as keyof typeof PROMPTS;
1920
+ const prompt = PROMPTS[promptName];
1921
+
1922
+ if (!prompt) {
1923
+ throw new Error(`Unknown prompt: ${promptName}`);
1924
+ }
1925
+
1926
+ const args = request.params.arguments as Record<string, unknown> || {};
1927
+ return {
1928
+ messages: [{
1929
+ role: "user",
1930
+ content: {
1931
+ type: "text",
1932
+ text: generatePromptContent(promptName, args)
1933
+ }
1934
+ }]
1935
+ };
1936
+ });
1937
+
1938
+ // Handle listing available resources
1939
+ server.setRequestHandler(ListResourcesRequestSchema, async () => {
1940
+ const resourceList = Object.values(RESOURCES).map(resource => ({
1941
+ uri: resource.uri,
1942
+ name: resource.name,
1943
+ description: resource.description,
1944
+ mimeType: resource.mimeType,
1945
+ annotations: {
1946
+ audience: ["assistant"],
1947
+ priority: 0.8,
1948
+ lastModified: `${resource.lastUpdated}T00:00:00Z`
1949
+ }
1950
+ }));
1951
+
1952
+ return {
1953
+ resources: resourceList
1954
+ };
1955
+ });
1956
+
1957
+ // Handle reading a specific resource by URI
1958
+ server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
1959
+ const uri = request.params.uri as string;
1960
+ log.debug(`Reading resource: ${uri}`);
1961
+
1962
+ // Direct resource lookup
1963
+ if (RESOURCES[uri as keyof typeof RESOURCES]) {
1964
+ const resource = RESOURCES[uri as keyof typeof RESOURCES];
1965
+ return {
1966
+ contents: [{
1967
+ uri: resource.uri,
1968
+ mimeType: resource.mimeType,
1969
+ text: JSON.stringify(resource.data, null, 2)
1970
+ }]
1971
+ };
1972
+ }
1973
+
1974
+ // Handle parameterized templates: zig-audio://libraries/{name}
1975
+ const libraryMatch = uri.match(/^zig-audio:\/\/libraries\/(.+)$/);
1976
+ if (libraryMatch) {
1977
+ const libName = libraryMatch[1];
1978
+ const library = ZIG_AUDIO_LIBRARIES[libName as keyof typeof ZIG_AUDIO_LIBRARIES];
1979
+ if (library) {
1980
+ return {
1981
+ contents: [{
1982
+ uri: uri,
1983
+ mimeType: "application/json",
1984
+ text: JSON.stringify(library, null, 2)
1985
+ }]
1986
+ };
1987
+ }
1988
+ throw new McpResourceError(uri);
1989
+ }
1990
+
1991
+ // Handle parameterized templates: zig-dsp://filters/{type}
1992
+ const filterMatch = uri.match(/^zig-dsp:\/\/filters\/(.+)$/);
1993
+ if (filterMatch) {
1994
+ const filterType = filterMatch[1];
1995
+ const filter = DSP_FILTERS[filterType as keyof typeof DSP_FILTERS];
1996
+ if (filter) {
1997
+ return {
1998
+ contents: [{
1999
+ uri: uri,
2000
+ mimeType: "application/json",
2001
+ text: JSON.stringify(filter, null, 2)
2002
+ }]
2003
+ };
2004
+ }
2005
+ throw new McpResourceError(uri);
2006
+ }
2007
+
2008
+ throw new McpResourceError(uri);
2009
+ });
2010
+
2011
+ // Handle listing resource templates
2012
+ server.setRequestHandler(ListResourceTemplatesRequestSchema, async () => {
2013
+ return {
2014
+ resourceTemplates: RESOURCE_TEMPLATES
2015
+ };
2016
+ });
2017
+
1046
2018
  server.setRequestHandler(ListToolsRequestSchema, async () => {
1047
2019
  return {
1048
2020
  tools: [
@@ -1072,7 +2044,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
1072
2044
  properties: {
1073
2045
  library: {
1074
2046
  type: "string",
1075
- enum: ["zang", "zaudio", "bonk", "pcm", "zig-liquid-dsp", "dalek"],
2047
+ enum: ["zang", "zaudio", "bonk", "pcm", "zig-liquid-dsp", "dalek", "zsynth", "zig-synth", "noize"],
1076
2048
  description: "Library name"
1077
2049
  }
1078
2050
  },
@@ -1121,7 +2093,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
1121
2093
  properties: {
1122
2094
  resource_type: {
1123
2095
  type: "string",
1124
- enum: ["tutorial", "reference", "example", "article"],
2096
+ enum: ["tutorial", "reference", "example", "article", "video", "forum", "github-issues"],
1125
2097
  description: "Filter by resource type"
1126
2098
  }
1127
2099
  }
@@ -1229,6 +2201,104 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
1229
2201
  },
1230
2202
  required: ["project_type"]
1231
2203
  }
2204
+ },
2205
+ {
2206
+ name: "zig_audio_compare_libraries",
2207
+ description: "Compare multiple Zig audio libraries side-by-side",
2208
+ inputSchema: {
2209
+ type: "object",
2210
+ properties: {
2211
+ libraries: {
2212
+ type: "array",
2213
+ items: { type: "string", enum: ["zang", "zaudio", "bonk", "pcm", "zig-liquid-dsp", "dalek", "zsynth", "zig-synth", "noize"] },
2214
+ description: "Libraries to compare (2-6)",
2215
+ minItems: 2,
2216
+ maxItems: 6
2217
+ }
2218
+ },
2219
+ required: ["libraries"]
2220
+ }
2221
+ },
2222
+ {
2223
+ name: "zig_audio_troubleshoot",
2224
+ description: "Debug common audio programming issues and get solutions",
2225
+ inputSchema: {
2226
+ type: "object",
2227
+ properties: {
2228
+ issue_type: {
2229
+ type: "string",
2230
+ enum: ["audio-glitches", "latency", "no-sound", "crash", "compilation-error", "performance"],
2231
+ description: "Type of issue to troubleshoot"
2232
+ }
2233
+ },
2234
+ required: ["issue_type"]
2235
+ }
2236
+ },
2237
+ {
2238
+ name: "zig_audio_deprecation_check",
2239
+ description: "Check if a library is deprecated or needs updates for your Zig version",
2240
+ inputSchema: {
2241
+ type: "object",
2242
+ properties: {
2243
+ library: {
2244
+ type: "string",
2245
+ description: "Library name to check"
2246
+ },
2247
+ zig_version: {
2248
+ type: "string",
2249
+ description: "Your Zig version (optional, defaults to 0.12.0)"
2250
+ }
2251
+ },
2252
+ required: ["library"]
2253
+ }
2254
+ },
2255
+ {
2256
+ name: "zig_dsp_calculate_delay",
2257
+ description: "Convert delay values between milliseconds, samples, feet, and meters",
2258
+ inputSchema: {
2259
+ type: "object",
2260
+ properties: {
2261
+ value: {
2262
+ type: "number",
2263
+ description: "The delay value to convert"
2264
+ },
2265
+ from_unit: {
2266
+ type: "string",
2267
+ enum: ["ms", "samples", "feet", "meters"],
2268
+ description: "Unit to convert from"
2269
+ },
2270
+ to_unit: {
2271
+ type: "string",
2272
+ enum: ["ms", "samples", "feet", "meters"],
2273
+ description: "Unit to convert to"
2274
+ },
2275
+ sample_rate: {
2276
+ type: "number",
2277
+ default: 44100,
2278
+ description: "Sample rate in Hz (required for sample conversions)"
2279
+ }
2280
+ },
2281
+ required: ["value", "from_unit", "to_unit"]
2282
+ }
2283
+ },
2284
+ {
2285
+ name: "zig_audio_use_prompt",
2286
+ description: "Invoke an MCP prompt to get structured guidance for common audio programming tasks",
2287
+ inputSchema: {
2288
+ type: "object",
2289
+ properties: {
2290
+ prompt_name: {
2291
+ type: "string",
2292
+ enum: ["library-selection", "synth-basics", "filter-design", "debugging-audio"],
2293
+ description: "The prompt to invoke"
2294
+ },
2295
+ arguments: {
2296
+ type: "object",
2297
+ description: "Arguments for the selected prompt"
2298
+ }
2299
+ },
2300
+ required: ["prompt_name"]
2301
+ }
1232
2302
  }
1233
2303
  ]
1234
2304
  };
@@ -1259,10 +2329,21 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1259
2329
  return await handleVerifyCode(args);
1260
2330
  case "zig_audio_project_template":
1261
2331
  return await handleProjectTemplate(args);
2332
+ case "zig_audio_compare_libraries":
2333
+ return await handleCompareLibraries(args);
2334
+ case "zig_audio_troubleshoot":
2335
+ return await handleTroubleshoot(args);
2336
+ case "zig_audio_deprecation_check":
2337
+ return await handleDeprecationCheck(args);
2338
+ case "zig_dsp_calculate_delay":
2339
+ return await handleCalculateDelay(args);
2340
+ case "zig_audio_use_prompt":
2341
+ return await handleUsePrompt(args);
1262
2342
  default:
1263
- throw new Error(`Unknown tool: ${name}`);
2343
+ throw new McpToolError(name, "Unknown tool");
1264
2344
  }
1265
2345
  } catch (error) {
2346
+ log.error(`Tool error: ${name}`, error);
1266
2347
  return {
1267
2348
  content: [{
1268
2349
  type: "text",