@ray0404/zig-audio-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/AGENTS.md +302 -0
- package/GEMINI.md +266 -0
- package/README.md +444 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1203 -0
- package/dist/index.js.map +1 -0
- package/dist/test.d.ts +2 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +162 -0
- package/dist/test.js.map +1 -0
- package/evaluation.xml +59 -0
- package/mcp-config.json +12 -0
- package/mcp.json +5 -0
- package/package.json +46 -0
- package/src/index.ts +1281 -0
- package/src/test.ts +195 -0
- package/tsconfig.json +20 -0
- package/tsconfig.tsbuildinfo +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
# MCP Zig Audio
|
|
2
|
+
|
|
3
|
+
A Model Context Protocol (MCP) server that provides AI assistance for writing high-quality Zig code focused on pro-audio and DSP algorithms.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
MCP Zig Audio is an MCP server that helps LLMs, AI agents, and developers write better Zig code for audio programming, digital signal processing (DSP), and synthesizer development. It provides tools for discovering audio libraries, understanding DSP concepts, explaining filter algorithms, and generating starter code.
|
|
8
|
+
|
|
9
|
+
## Key Features
|
|
10
|
+
|
|
11
|
+
- **Library Discovery** - Browse and filter through 6 major Zig audio/DSP libraries
|
|
12
|
+
- **Smart Recommendations** - Get library suggestions based on your specific audio programming needs
|
|
13
|
+
- **DSP Filter Design** - Interactive filter design with coefficient calculation and stability checks
|
|
14
|
+
- **Code Generation** - Generate starter code for oscillators, envelopes, filters, delay lines, and more
|
|
15
|
+
- **Code Verification** - Check Zig code for common issues and missing imports
|
|
16
|
+
- **Project Templates** - Generate complete project skeletons with build files
|
|
17
|
+
- **Learning Resources** - Curated tutorials, examples, and documentation references
|
|
18
|
+
- **Core Concepts** - Explanations of fundamental audio/DSP terminology
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
### Prerequisites
|
|
23
|
+
|
|
24
|
+
- Node.js 18.0.0 or higher
|
|
25
|
+
- npm or pnpm
|
|
26
|
+
|
|
27
|
+
### Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Clone the repository
|
|
31
|
+
git clone https://github.com/ray0404/zig-audio-mcp.git
|
|
32
|
+
cd zig-audio-mcp
|
|
33
|
+
|
|
34
|
+
# Install dependencies
|
|
35
|
+
npm install
|
|
36
|
+
|
|
37
|
+
# Build the TypeScript project
|
|
38
|
+
npm run build
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Running the Server
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
# Using stdio transport (default)
|
|
45
|
+
npm start
|
|
46
|
+
|
|
47
|
+
# Or run in development mode with auto-reload
|
|
48
|
+
npm run dev
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Connecting via MCP Client
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
55
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
56
|
+
|
|
57
|
+
const transport = new StdioClientTransport({
|
|
58
|
+
command: "node",
|
|
59
|
+
args: ["dist/index.js"]
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const client = new Client({
|
|
63
|
+
name: "my-client",
|
|
64
|
+
version: "1.0.0"
|
|
65
|
+
}, {
|
|
66
|
+
capabilities: {}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
await client.connect(transport);
|
|
70
|
+
|
|
71
|
+
// List available tools
|
|
72
|
+
const tools = await client.request(
|
|
73
|
+
{ method: "tools/list", params: {} },
|
|
74
|
+
{}
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
console.log(tools);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Available Tools
|
|
81
|
+
|
|
82
|
+
### 1. zig_audio_list_libraries
|
|
83
|
+
|
|
84
|
+
Lists available Zig audio/DSP libraries with optional filtering by category or feature.
|
|
85
|
+
|
|
86
|
+
**Parameters:**
|
|
87
|
+
- `category` (optional): Filter by category (synthesis, effects, filters, dsp, playback, recording, file-io, encoding, sdr, engine, wrapper, experimental, all)
|
|
88
|
+
- `feature` (optional): Filter by feature keyword
|
|
89
|
+
|
|
90
|
+
**Example:**
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"name": "zig_audio_list_libraries",
|
|
94
|
+
"arguments": {
|
|
95
|
+
"category": "synthesis"
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 2. zig_audio_library_info
|
|
101
|
+
|
|
102
|
+
Gets detailed information about a specific Zig audio library.
|
|
103
|
+
|
|
104
|
+
**Parameters:**
|
|
105
|
+
- `library` (required): Library name (zang, zaudio, bonk, pcm, zig-liquid-dsp, dalek)
|
|
106
|
+
|
|
107
|
+
**Example:**
|
|
108
|
+
```json
|
|
109
|
+
{
|
|
110
|
+
"name": "zig_audio_library_info",
|
|
111
|
+
"arguments": {
|
|
112
|
+
"library": "zang"
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 3. zig_dsp_explain_filter
|
|
118
|
+
|
|
119
|
+
Explains a DSP filter type with its mathematical formula, use cases, and compatible Zig libraries.
|
|
120
|
+
|
|
121
|
+
**Parameters:**
|
|
122
|
+
- `filter_type` (required): Filter type (lowpass, highpass, bandpass, notch, biquad, one-pole)
|
|
123
|
+
|
|
124
|
+
**Example:**
|
|
125
|
+
```json
|
|
126
|
+
{
|
|
127
|
+
"name": "zig_dsp_explain_filter",
|
|
128
|
+
"arguments": {
|
|
129
|
+
"filter_type": "lowpass"
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### 4. zig_audio_generate_code
|
|
135
|
+
|
|
136
|
+
Generates starter code for common audio/DSP tasks in Zig.
|
|
137
|
+
|
|
138
|
+
**Parameters:**
|
|
139
|
+
- `task` (required): Type of code to generate (oscillator, envelope, filter, delay, mixer, player, recorder, file-write, file-read)
|
|
140
|
+
- `parameters` (optional): Additional parameters for code generation
|
|
141
|
+
|
|
142
|
+
**Example:**
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"name": "zig_audio_generate_code",
|
|
146
|
+
"arguments": {
|
|
147
|
+
"task": "oscillator"
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### 5. zig_audio_list_resources
|
|
153
|
+
|
|
154
|
+
Lists learning resources for Zig audio development.
|
|
155
|
+
|
|
156
|
+
**Parameters:**
|
|
157
|
+
- `resource_type` (optional): Filter by type (tutorial, reference, example, article)
|
|
158
|
+
|
|
159
|
+
### 6. zig_dsp_get_concepts
|
|
160
|
+
|
|
161
|
+
Returns explanations of fundamental audio/DSP concepts including sample rate, bit depth, buffer size, Nyquist frequency, and aliasing.
|
|
162
|
+
|
|
163
|
+
### 7. zig_audio_recommend_library
|
|
164
|
+
|
|
165
|
+
Get intelligent library recommendations based on your audio programming use case and requirements.
|
|
166
|
+
|
|
167
|
+
**Parameters:**
|
|
168
|
+
- `use_case` (required): Description of what you're building (e.g., "synthesizer", "audio player", "DSP effects")
|
|
169
|
+
- `requirements` (optional): Specific requirements like "low latency", "no allocations", "cross-platform"
|
|
170
|
+
|
|
171
|
+
**Example:**
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"name": "zig_audio_recommend_library",
|
|
175
|
+
"arguments": {
|
|
176
|
+
"use_case": "building a real-time synthesizer",
|
|
177
|
+
"requirements": ["low latency", "no dynamic allocations"]
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### 8. zig_dsp_design_filter
|
|
183
|
+
|
|
184
|
+
Design DSP filters and calculate biquad coefficients with stability verification.
|
|
185
|
+
|
|
186
|
+
**Parameters:**
|
|
187
|
+
- `filter_type` (required): Filter type (lowpass, highpass, bandpass, notch)
|
|
188
|
+
- `parameters` (required): Filter parameters including sample_rate, cutoff frequency, Q factor
|
|
189
|
+
|
|
190
|
+
**Example:**
|
|
191
|
+
```json
|
|
192
|
+
{
|
|
193
|
+
"name": "zig_dsp_design_filter",
|
|
194
|
+
"arguments": {
|
|
195
|
+
"filter_type": "lowpass",
|
|
196
|
+
"parameters": {
|
|
197
|
+
"sample_rate": 44100,
|
|
198
|
+
"cutoff": 1000,
|
|
199
|
+
"q": 0.707
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### 9. zig_audio_verify_code
|
|
206
|
+
|
|
207
|
+
Verify Zig code for basic syntax issues, missing imports, and common mistakes.
|
|
208
|
+
|
|
209
|
+
**Parameters:**
|
|
210
|
+
- `code` (required): Zig code to analyze
|
|
211
|
+
- `libraries` (optional): Expected libraries that should be imported
|
|
212
|
+
|
|
213
|
+
**Example:**
|
|
214
|
+
```json
|
|
215
|
+
{
|
|
216
|
+
"name": "zig_audio_verify_code",
|
|
217
|
+
"arguments": {
|
|
218
|
+
"code": "const zang = @import(\"zang\"); var osc = zang.SineOsc.init();"
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### 10. zig_audio_project_template
|
|
224
|
+
|
|
225
|
+
Generate complete project templates for different types of audio applications.
|
|
226
|
+
|
|
227
|
+
**Parameters:**
|
|
228
|
+
- `project_type` (required): Type of project (synthesizer, audio-player, dsp-processor, file-processor, game-audio)
|
|
229
|
+
- `features` (optional): Additional features to include
|
|
230
|
+
|
|
231
|
+
**Example:**
|
|
232
|
+
```json
|
|
233
|
+
{
|
|
234
|
+
"name": "zig_audio_project_template",
|
|
235
|
+
"arguments": {
|
|
236
|
+
"project_type": "synthesizer"
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Supported Zig Libraries
|
|
242
|
+
|
|
243
|
+
### zang
|
|
244
|
+
- **Description:** Audio synthesis library with generators, effects, and filters
|
|
245
|
+
- **License:** MIT
|
|
246
|
+
- **Features:** Oscillators, envelopes, filters, effects, no dynamic allocations
|
|
247
|
+
- **Repository:** https://github.com/Hejsil/zang
|
|
248
|
+
|
|
249
|
+
### zaudio
|
|
250
|
+
- **Description:** Zig wrapper for miniaudio
|
|
251
|
+
- **License:** MIT
|
|
252
|
+
- **Features:** Playback, recording, node graph, streaming
|
|
253
|
+
- **Repository:** https://github.com/MasterQ32/zaudio
|
|
254
|
+
|
|
255
|
+
### bonk
|
|
256
|
+
- **Description:** DSP objects including filters and delay lines
|
|
257
|
+
- **License:** MPL-2.0
|
|
258
|
+
- **Features:** Filters, delay lines, waveshapers
|
|
259
|
+
- **Repository:** https://github.com/chr15m/bonk
|
|
260
|
+
|
|
261
|
+
### pcm
|
|
262
|
+
- **Description:** PCM audio file handling for WAV and AIFF
|
|
263
|
+
- **License:** MIT
|
|
264
|
+
- **Features:** WAV, AIFF, I/O, encoding
|
|
265
|
+
- **Repository:** https://github.com/Hejsil/pcm
|
|
266
|
+
|
|
267
|
+
### zig-liquid-dsp
|
|
268
|
+
- **Description:** DSP library for software-defined radio
|
|
269
|
+
- **License:** MIT
|
|
270
|
+
- **Features:** Filters, modulation, Fourier, SDR
|
|
271
|
+
- **Repository:** https://github.com/ggerard/zig-liquid-dsp
|
|
272
|
+
|
|
273
|
+
### dalek
|
|
274
|
+
- **Description:** Experimental data-oriented audio engine
|
|
275
|
+
- **License:** MIT
|
|
276
|
+
- **Features:** Data-oriented design, performance optimization
|
|
277
|
+
- **Repository:** https://github.com/chr15m/dalek
|
|
278
|
+
|
|
279
|
+
## DSP Filter Reference
|
|
280
|
+
|
|
281
|
+
### Low Pass Filter
|
|
282
|
+
Allows frequencies below the cutoff to pass through, attenuating higher frequencies.
|
|
283
|
+
|
|
284
|
+
**Formula:** `y[n] = a0 * x[n] + a1 * x[n-1] + a2 * x[n-2] - b1 * y[n-1] - b2 * y[n-2]`
|
|
285
|
+
|
|
286
|
+
**Use Cases:** Sub-bass smoothing, removing high-frequency noise, warmth/room modeling
|
|
287
|
+
|
|
288
|
+
**Zig Libraries:** zang, bonk, zig-liquid-dsp
|
|
289
|
+
|
|
290
|
+
### High Pass Filter
|
|
291
|
+
Allows frequencies above the cutoff to pass through, attenuating lower frequencies.
|
|
292
|
+
|
|
293
|
+
**Use Cases:** DC offset removal, rumble removal, clarifying midrange
|
|
294
|
+
|
|
295
|
+
**Zig Libraries:** zang, bonk, zig-liquid-dsp
|
|
296
|
+
|
|
297
|
+
### Band Pass Filter
|
|
298
|
+
Allows frequencies within a specific band to pass through.
|
|
299
|
+
|
|
300
|
+
**Use Cases:** Isolating instrument frequencies, telephone effect, formant simulation
|
|
301
|
+
|
|
302
|
+
### Notch Filter
|
|
303
|
+
Attenuates a specific frequency band while allowing others to pass.
|
|
304
|
+
|
|
305
|
+
**Use Cases:** Hum removal, feedback suppression, EQ notching
|
|
306
|
+
|
|
307
|
+
### Biquad Filter
|
|
308
|
+
Second-order IIR filter using two poles and two zeros. Generic form for many filter types.
|
|
309
|
+
|
|
310
|
+
**Use Cases:** Parametric EQ, crossover filters, tone control
|
|
311
|
+
|
|
312
|
+
### One-Pole Filter
|
|
313
|
+
Simple first-order filter with single pole. Good for smoothing and DC removal.
|
|
314
|
+
|
|
315
|
+
**Use Cases:** Smoothing, DC removal, simple envelopes
|
|
316
|
+
|
|
317
|
+
## Audio/DSP Concepts
|
|
318
|
+
|
|
319
|
+
### Sample Rate
|
|
320
|
+
Number of samples captured per second (e.g., 44100 Hz, 48000 Hz).
|
|
321
|
+
|
|
322
|
+
- **Typical Values:** 44100, 48000, 96000
|
|
323
|
+
- **Impact:** Higher rates = more accurate audio but more CPU/memory
|
|
324
|
+
|
|
325
|
+
### Bit Depth
|
|
326
|
+
Number of bits per sample for amplitude resolution.
|
|
327
|
+
|
|
328
|
+
- **Typical Values:** 16, 24, 32
|
|
329
|
+
- **Impact:** Higher depth = more dynamic range, less quantization noise
|
|
330
|
+
|
|
331
|
+
### Buffer Size
|
|
332
|
+
Number of samples processed per callback cycle.
|
|
333
|
+
|
|
334
|
+
- **Typical Values:** 64, 128, 256, 512, 1024
|
|
335
|
+
- **Impact:** Smaller = lower latency, higher CPU; larger = more stable, more latency
|
|
336
|
+
|
|
337
|
+
### Nyquist Frequency
|
|
338
|
+
Maximum representable frequency (sample_rate / 2).
|
|
339
|
+
|
|
340
|
+
- **Formula:** f_nyquist = sample_rate / 2
|
|
341
|
+
|
|
342
|
+
### Aliasing
|
|
343
|
+
Distortion from sampling frequencies above Nyquist.
|
|
344
|
+
|
|
345
|
+
- **Prevention:** Use anti-aliasing filters before downsampling
|
|
346
|
+
|
|
347
|
+
## Architecture
|
|
348
|
+
|
|
349
|
+
### Project Structure
|
|
350
|
+
|
|
351
|
+
```
|
|
352
|
+
mcp-zig-audio/
|
|
353
|
+
├── src/
|
|
354
|
+
│ ├── index.ts # Main MCP server implementation
|
|
355
|
+
│ └── test.ts # Evaluation test suite
|
|
356
|
+
├── dist/ # Compiled JavaScript output
|
|
357
|
+
├── package.json # Project dependencies
|
|
358
|
+
├── tsconfig.json # TypeScript configuration
|
|
359
|
+
└── evaluation.xml # Evaluation Q&A pairs
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
### Technology Stack
|
|
363
|
+
|
|
364
|
+
- **Language:** TypeScript
|
|
365
|
+
- **MCP SDK:** @modelcontextprotocol/sdk
|
|
366
|
+
- **Validation:** Zod
|
|
367
|
+
- **Transport:** Stdio (default), Streamable HTTP
|
|
368
|
+
|
|
369
|
+
### MCP Protocol Integration
|
|
370
|
+
|
|
371
|
+
The server implements the MCP specification using:
|
|
372
|
+
- `Server` class from `@modelcontextprotocol/sdk/server/index.js`
|
|
373
|
+
- `StdioServerTransport` for stdio communication
|
|
374
|
+
- Zod schemas for input validation
|
|
375
|
+
- JSON-RPC 2.0 message format
|
|
376
|
+
|
|
377
|
+
## Development
|
|
378
|
+
|
|
379
|
+
### Building
|
|
380
|
+
|
|
381
|
+
```bash
|
|
382
|
+
npm run build
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### Running Tests
|
|
386
|
+
|
|
387
|
+
```bash
|
|
388
|
+
npx tsx src/test.ts
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
### Development Mode
|
|
392
|
+
|
|
393
|
+
```bash
|
|
394
|
+
npm run dev
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
This runs the server with tsx for auto-reloading on file changes.
|
|
398
|
+
|
|
399
|
+
## Evaluation
|
|
400
|
+
|
|
401
|
+
The project includes an evaluation suite in `evaluation.xml` with 10 Q&A pairs to verify the MCP server correctly answers questions about Zig audio programming.
|
|
402
|
+
|
|
403
|
+
To run evaluation tests:
|
|
404
|
+
|
|
405
|
+
```bash
|
|
406
|
+
npx tsx src/test.ts
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
Expected output:
|
|
410
|
+
- All 9 tests should pass
|
|
411
|
+
- Tests cover tool listing, library discovery, filter explanations, code generation, and concept queries
|
|
412
|
+
|
|
413
|
+
## Use Cases
|
|
414
|
+
|
|
415
|
+
### For AI Assistants
|
|
416
|
+
|
|
417
|
+
When helping users write Zig audio code, use this MCP server to:
|
|
418
|
+
|
|
419
|
+
1. **Discover Libraries** - Find appropriate libraries for the task
|
|
420
|
+
2. **Understand Concepts** - Explain DSP fundamentals
|
|
421
|
+
3. **Generate Code** - Create starter implementations
|
|
422
|
+
4. **Filter Selection** - Choose the right filter algorithm
|
|
423
|
+
5. **Find Resources** - Locate learning materials
|
|
424
|
+
|
|
425
|
+
### For Developers
|
|
426
|
+
|
|
427
|
+
- Quick reference for Zig audio libraries
|
|
428
|
+
- Understanding DSP algorithms and their implementations
|
|
429
|
+
- Generating boilerplate code for audio projects
|
|
430
|
+
- Learning about audio programming concepts
|
|
431
|
+
|
|
432
|
+
## License
|
|
433
|
+
|
|
434
|
+
MIT
|
|
435
|
+
|
|
436
|
+
## Contributing
|
|
437
|
+
|
|
438
|
+
Contributions are welcome! Please ensure:
|
|
439
|
+
|
|
440
|
+
1. Tests pass: `npx tsx src/test.ts`
|
|
441
|
+
2. Build succeeds: `npm run build`
|
|
442
|
+
3. New features include Zod validation schemas
|
|
443
|
+
4. Tools follow the naming convention: `zig_audio_*` or `zig_dsp_*`
|
|
444
|
+
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|