@mushan_bit/freesound-mcp 1.0.2 → 1.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/CHANGELOG.md ADDED
@@ -0,0 +1,64 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
5
+ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [1.1.0] - 2026-11-30
8
+
9
+ ### Added
10
+
11
+ - `freesound_get_sound` for full sound metadata: description, author, tags,
12
+ license, technical audio properties, preview URLs, waveform/spectrogram
13
+ images, and the OAuth2 download endpoint.
14
+ - `freesound_similar` for acoustically and semantically similar sounds, with
15
+ pagination and selectable similarity spaces.
16
+ - Search pagination (`page`, `pageSize`), sorting (`sort`), duration ranges,
17
+ tags, file type, category, uploader, and pack grouping.
18
+ - Rich search results including author, tags, sample rate, file size,
19
+ downloads, rating, and relevance score.
20
+ - Original (non-preview) downloads through `quality: "original"` and
21
+ `FREESOUND_OAUTH_TOKEN`.
22
+ - Custom download filenames, `~` expansion, and `FREESOUND_DOWNLOAD_DIR`.
23
+ - Streamed downloads written to a temporary file and atomically renamed.
24
+ - Automatic retries with exponential backoff and `Retry-After` support for
25
+ 429, 5xx, timeout, and network failures.
26
+ - Configurable request timeout and retry budget.
27
+ - A `node:test` suite covering the API client, search, similar sounds, sound
28
+ details, downloads, and MCP tool integration.
29
+ - GitHub Actions CI across Node.js 20, 22, and 24.
30
+ - `npm start`, `npm run typecheck`, and `prepublishOnly` scripts.
31
+
32
+ ### Fixed
33
+
34
+ - Multiple search filters were sent as repeated `filter` parameters, so the
35
+ last condition silently replaced earlier ones.
36
+ - License filters containing spaces (for example `Creative Commons 0`) were
37
+ not quoted and never matched.
38
+ - The download tool declared an output schema that did not match the returned
39
+ structured content.
40
+ - `FREESOUND_API_KEY` was read once at import time, so late environment
41
+ configuration was ignored.
42
+ - The package `main`, `bin`, license, and documented build path were
43
+ incorrect or inconsistent.
44
+ - Downloaded files could overwrite arbitrary paths through an unsanitized
45
+ filename; filenames are now sanitized and extensions enforced.
46
+ - Null or non-numeric optional metadata fields could break the sound details
47
+ output schema; they are now ignored.
48
+ - Windows reserved filenames and trailing dots/spaces are sanitized.
49
+
50
+ ### Changed
51
+
52
+ - Split the server entry point, MCP registration, HTTP client, and domain
53
+ modules to make the project testable and easier to extend.
54
+ - Tool failures now return friendly `isError` results instead of leaking
55
+ internal exceptions.
56
+ - The server version now follows `package.json`.
57
+ - Removed the unused example script from the published build.
58
+
59
+ ## [1.0.2]
60
+
61
+ - Initial published version with `freesound_search` and `freesound_download`.
62
+
63
+ [1.1.0]: https://github.com/MuShan-bit/freesound-mcp/compare/v1.0.2...v1.1.0
64
+ [1.0.2]: https://github.com/MuShan-bit/freesound-mcp/releases/tag/v1.0.2
package/README.md CHANGED
@@ -1,124 +1,356 @@
1
- # Freesound-MCP
2
-
3
- A Model Context Protocol (MCP) server that enables AI applications to search and download audio resources from the [Freesound](https://freesound.org/) platform via natural language commands.
1
+ <h1 align="center">Freesound MCP</h1>
2
+
3
+ <p align="center">
4
+ <strong>Search, inspect, and download Creative Commons sounds from Freesound inside any MCP-compatible AI client.</strong>
5
+ </p>
6
+
7
+ <p align="center">
8
+ <a href="https://github.com/MuShan-bit/freesound-mcp/actions/workflows/ci.yml">
9
+ <img alt="CI status" src="https://img.shields.io/github/actions/workflow/status/MuShan-bit/freesound-mcp/ci.yml?branch=main&style=flat-square&logo=githubactions&logoColor=white">
10
+ </a>
11
+ <a href="https://www.npmjs.com/package/@mushan_bit/freesound-mcp">
12
+ <img alt="npm version" src="https://img.shields.io/npm/v/@mushan_bit/freesound-mcp?style=flat-square&logo=npm&logoColor=white">
13
+ </a>
14
+ <a href="https://www.npmjs.com/package/@mushan_bit/freesound-mcp">
15
+ <img alt="npm downloads" src="https://img.shields.io/npm/dm/@mushan_bit/freesound-mcp?style=flat-square&logo=npm&logoColor=white">
16
+ </a>
17
+ <a href="LICENSE">
18
+ <img alt="MIT license" src="https://img.shields.io/badge/license-MIT-green?style=flat-square">
19
+ </a>
20
+ <a href="https://nodejs.org">
21
+ <img alt="Node.js 20 or newer" src="https://img.shields.io/badge/node-%3E%3D20-339933?style=flat-square&logo=nodedotjs&logoColor=white">
22
+ </a>
23
+ <a href="https://lobehub.com/mcp/mushan-bit-freesound-mcp">
24
+ <img alt="MCP Badge" src="https://lobehub.com/badge/mcp/mushan-bit-freesound-mcp">
25
+ </a>
26
+ </p>
27
+
28
+ ---
29
+
30
+ A [Model Context Protocol](https://modelcontextprotocol.io/) server that lets AI
31
+ applications search, inspect, discover similar sounds, and download audio from
32
+ [Freesound](https://freesound.org/) using natural language.
33
+
34
+ Freesound-MCP speaks MCP over stdio, keeps no database, and runs as a single
35
+ Node.js process. It is designed for Claude Desktop, Cursor, VS Code, and any
36
+ other MCP-compatible host.
37
+
38
+ ## Contents
39
+
40
+ - [Overview](#overview)
41
+ - [Tools](#tools)
42
+ - [Requirements](#requirements)
43
+ - [Installation](#installation)
44
+ - [Configuration](#configuration)
45
+ - [Usage](#usage)
46
+ - [Security and licensing](#security-and-licensing)
47
+ - [Troubleshooting](#troubleshooting)
48
+ - [Development](#development)
49
+ - [Contributing](#contributing)
50
+ - [License](#license)
51
+ - [Acknowledgments](#acknowledgments)
4
52
 
5
53
  ## Overview
6
54
 
7
- Freesound-MCP is designed to simplify the integration of copyright-free sound resources into AI tools. It follows the Model Context Protocol standard and communicates with host applications via stdin/stdout. The server provides two main capabilities:
55
+ - 🔍 **Search** by keywords with pagination, sorting, duration ranges, license,
56
+ tags, file type, category, uploader, and pack grouping.
57
+ - 🎵 **Inspect** full metadata for a single sound: description, author, license,
58
+ technical audio properties, preview URLs, and waveform/spectrogram images.
59
+ - 🔗 **Discover similar** sounds using Freesound's acoustic and semantic
60
+ similarity spaces, with relevance scores.
61
+ - ⬇️ **Download** preview MP3/OGG files, or the original upload when OAuth2 is
62
+ configured. Files are streamed to disk and safely named.
63
+ - 🛡️ **Resilient** requests with timeouts, exponential backoff, and
64
+ `Retry-After` support.
65
+
66
+ ## Tools
67
+
68
+ | Tool | Description | Read-only |
69
+ | --- | --- | --- |
70
+ | `freesound_search` | Search sounds with filters, sorting, and pagination | Yes |
71
+ | `freesound_similar` | Find sounds similar to a reference sound | Yes |
72
+ | `freesound_get_sound` | Get detailed metadata for one sound | Yes |
73
+ | `freesound_download` | Download a preview or original file to disk | No |
74
+
75
+ ### `freesound_search`
76
+
77
+ | Parameter | Type | Default | Description |
78
+ | --- | --- | --- | --- |
79
+ | `query` | string | — (required) | Keywords; pass an empty string to browse all sounds |
80
+ | `page` | integer | `1` | Page number |
81
+ | `pageSize` | integer | `15` | Results per page, 1-150 |
82
+ | `sort` | string | `score` | `score`, `duration_asc`, `duration_desc`, `created_asc`, `created_desc`, `downloads_asc`, `downloads_desc`, `rating_asc`, or `rating_desc` |
83
+ | `minDuration` | number | — | Minimum duration in seconds |
84
+ | `maxDuration` | number | — | Maximum duration in seconds |
85
+ | `license` | string | — | `Creative Commons 0`, `Attribution`, or `Attribution NonCommercial`; values with spaces are quoted automatically |
86
+ | `tags` | string[] | — | Tags that every result must contain (AND) |
87
+ | `type` | string | — | `wav`, `aif`, `aiff`, `ogg`, `mp3`, `m4a`, or `flac` |
88
+ | `category` | string | — | Broad Sound Taxonomy category, for example `Instrument samples` |
89
+ | `username` | string | — | Uploader username |
90
+ | `groupByPack` | boolean | `false` | Return at most one sound per pack |
91
+
92
+ Returns `count`, `page`, `pageSize`, `totalPages`, and `results`. Each result
93
+ contains `id`, `name`, `duration`, `license`, `preview`, and, when available,
94
+ `username`, `tags`, `type`, `channels`, `samplerate`, `filesize`, `downloads`,
95
+ `rating`, and `score`.
96
+
97
+ ```json
98
+ {
99
+ "count": 128,
100
+ "page": 1,
101
+ "pageSize": 15,
102
+ "totalPages": 9,
103
+ "results": [
104
+ {
105
+ "id": 123456,
106
+ "name": "Rain on a tin roof",
107
+ "duration": 12.4,
108
+ "license": "Creative Commons 0",
109
+ "preview": "https://cdn.freesound.org/previews/...",
110
+ "username": "fieldrecordist",
111
+ "tags": ["rain", "ambience"],
112
+ "type": "wav",
113
+ "samplerate": 48000,
114
+ "downloads": 421,
115
+ "rating": 4.6
116
+ }
117
+ ]
118
+ }
119
+ ```
120
+
121
+ ### `freesound_similar`
122
+
123
+ | Parameter | Type | Default | Description |
124
+ | --- | --- | --- | --- |
125
+ | `soundId` | integer | — (required) | Reference Freesound sound ID |
126
+ | `page` | integer | `1` | Page number |
127
+ | `pageSize` | integer | `15` | Results per page, 1-150 |
128
+ | `similaritySpace` | string | API default | `laion_clap` (semantic + acoustic) or `freesound_classic` (low-level acoustic features) |
129
+
130
+ Returns the same paginated structure as `freesound_search`, including a
131
+ relevance `score` for every result.
132
+
133
+ ### `freesound_get_sound`
134
+
135
+ | Parameter | Type | Description |
136
+ | --- | --- | --- |
137
+ | `soundId` | integer | Freesound sound ID (required) |
8
138
 
9
- - 🔍 **Search Sounds**: Search for sounds by keywords with optional filters for maximum duration and license type
10
- - ⬇️ **Download Sounds**: Download audio files by sound ID from Freesound
11
- - 🎵 **Metadata Support**: Retrieve detailed information about sounds, including duration, license, and preview links
139
+ Returns `id`, `name`, `description`, `tags`, `license`, `username`, and
140
+ `duration`, plus optional `type`, `channels`, `samplerate`, `filesize`,
141
+ `bitrate`, `bitdepth`, `created`, `url`, `downloadUrl`, `previewHqMp3`,
142
+ `previewLqMp3`, `previewHqOgg`, `previewLqOgg`, `waveformUrl`,
143
+ `spectrogramUrl`, `downloads`, `rating`, `numRatings`, `numComments`,
144
+ `category`, `subcategory`, `pack`, and `genAiPreference`.
12
145
 
13
- ## Features
146
+ `downloadUrl` points at the original file endpoint and requires OAuth2.
14
147
 
15
- - Lightweight MCP server built with Node.js
16
- - Standard input/output communication mechanism compliant with MCP protocol
17
- - Secure API key management through environment variables
18
- - No database required - simple, stateless design
148
+ ### `freesound_download`
19
149
 
20
- ## Prerequisites
150
+ | Parameter | Type | Default | Description |
151
+ | --- | --- | --- | --- |
152
+ | `soundId` | integer | — (required) | Freesound sound ID |
153
+ | `quality` | string | `lq` | `hq`/`lq` for previews, or `original` for the uploaded file |
154
+ | `filename` | string | generated | Output filename; unsafe characters are stripped and the extension is enforced |
155
+ | `downloadDir` | string | `~/.freesound-mcp/downloads` | Target directory; supports `~` |
21
156
 
22
- - Node.js (supports CommonJS modules)
23
- - npm or yarn package manager
24
- - A Freesound API key (get one at [Freesound API page](https://freesound.org/docs/api/authentication.html))
157
+ Returns `filePath`, `soundId`, `name`, `quality`, `format`, `bytes`,
158
+ `duration`, `license`, and `sourceUrl`.
159
+
160
+ Notes:
161
+
162
+ - Preview downloads do not require OAuth2 and are MP3/OGG transcodes, not the
163
+ original upload.
164
+ - `quality: "original"` requires `FREESOUND_OAUTH_TOKEN` and downloads the file
165
+ as uploaded.
166
+ - Files are streamed to a temporary file and atomically renamed, so an
167
+ interrupted download never leaves a partial file under the final name.
168
+
169
+ ## Requirements
170
+
171
+ - Node.js 20 or newer
172
+ - npm 9 or newer (or pnpm/yarn)
173
+ - A Freesound API key from the
174
+ [Freesound API documentation](https://freesound.org/docs/api/authentication.html)
175
+ - Optional: a Freesound OAuth2 access token for original-quality downloads
25
176
 
26
177
  ## Installation
27
178
 
28
- 1. Clone the repository:
29
- ```bash
30
- git clone https://github.com/yourusername/freesound-mcp.git
31
- cd freesound-mcp
32
- ```
179
+ ### From npm
33
180
 
34
- 2. Install dependencies:
35
181
  ```bash
36
- npm install
182
+ npx -y @mushan_bit/freesound-mcp
37
183
  ```
38
184
 
39
- 3. Build the project:
185
+ The server speaks MCP over stdio, so it is normally launched by your MCP client
186
+ rather than run by hand.
187
+
188
+ ### From source
189
+
40
190
  ```bash
191
+ git clone https://github.com/MuShan-bit/freesound-mcp.git
192
+ cd freesound-mcp
193
+ npm ci
41
194
  npm run build
42
195
  ```
43
196
 
44
- ## Setup
45
-
46
- 1. Get your Freesound API key from [Freesound API page](https://freesound.org/docs/api/authentication.html)
197
+ ## Configuration
198
+
199
+ ### Environment variables
200
+
201
+ | Variable | Required | Default | Description |
202
+ | --- | --- | --- | --- |
203
+ | `FREESOUND_API_KEY` | Yes | — | API token used for search and metadata requests |
204
+ | `FREESOUND_OAUTH_TOKEN` | No | — | OAuth2 access token for `quality: "original"` downloads |
205
+ | `FREESOUND_DOWNLOAD_DIR` | No | `~/.freesound-mcp/downloads` | Default download directory |
206
+ | `FREESOUND_TIMEOUT_MS` | No | `20000` | Per-request timeout in milliseconds |
207
+ | `FREESOUND_MAX_RETRIES` | No | `2` | Retries for 429/5xx, timeouts, and network errors (0-5) |
208
+ | `FREESOUND_RETRY_BASE_MS` | No | `500` | Base delay for exponential backoff |
209
+ | `FREESOUND_API_BASE_URL` | No | `https://freesound.org/apiv2` | API base URL override (testing or proxy) |
210
+
211
+ Requests that receive `429 Too Many Requests` honour the `Retry-After` header
212
+ (up to 10 seconds) before retrying. Other retryable failures use exponential
213
+ backoff with jitter.
214
+
215
+ ### Claude Desktop
216
+
217
+ Add this to `claude_desktop_config.json`:
218
+
219
+ - macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
220
+ - Windows: `%APPDATA%\Claude\claude_desktop_config.json`
221
+
222
+ ```json
223
+ {
224
+ "mcpServers": {
225
+ "freesound": {
226
+ "command": "npx",
227
+ "args": ["-y", "@mushan_bit/freesound-mcp"],
228
+ "env": {
229
+ "FREESOUND_API_KEY": "your_freesound_api_key"
230
+ }
231
+ }
232
+ }
233
+ }
234
+ ```
47
235
 
48
- 2. Set your API key as an environment variable:
49
- ```bash
50
- export FREESOUND_API_KEY=your_freesound_api_key_here
236
+ To run a local build instead:
237
+
238
+ ```json
239
+ {
240
+ "mcpServers": {
241
+ "freesound": {
242
+ "command": "node",
243
+ "args": ["/absolute/path/to/freesound-mcp/build/index.js"],
244
+ "env": {
245
+ "FREESOUND_API_KEY": "your_freesound_api_key",
246
+ "FREESOUND_OAUTH_TOKEN": "optional_oauth2_token"
247
+ }
248
+ }
249
+ }
250
+ }
51
251
  ```
52
252
 
53
- ## Configuration in Claude Desktop
253
+ Restart the client after editing the configuration.
54
254
 
55
- To configure this MCP server in Claude Desktop:
255
+ ### Cursor
56
256
 
57
- 1. Open Claude Desktop preferences
58
- 2. Navigate to "Beta Features" → "Model Context Protocol (MCP) Tools"
59
- 3. Click "Configure" to manage MCP servers
60
- 4. Add a new server configuration with these details:
61
- - Name: "Freesound MCP"
62
- - Command: `node`
63
- - Arguments: `/path/to/freesound-mcp/dist/index.js` (after running `npm run build`)
64
- - Environment Variables: Ensure `FREESOUND_API_KEY` is available to the process
65
- 5. Save the configuration and restart Claude
257
+ Add the same `mcpServers` object to `~/.cursor/mcp.json` (global) or
258
+ `.cursor/mcp.json` (project).
66
259
 
67
- After restarting Claude, you'll be able to use the Freesound tools in your conversations.
260
+ ### VS Code
68
261
 
69
- ## Usage
262
+ Add the server to `.vscode/mcp.json`:
263
+
264
+ ```json
265
+ {
266
+ "servers": {
267
+ "freesound": {
268
+ "command": "npx",
269
+ "args": ["-y", "@mushan_bit/freesound-mcp"],
270
+ "env": {
271
+ "FREESOUND_API_KEY": "your_freesound_api_key"
272
+ }
273
+ }
274
+ }
275
+ }
276
+ ```
70
277
 
71
- Once configured in Claude, you can use natural language commands such as:
278
+ ## Usage
72
279
 
73
- - "Find me a rainforest ambient sound under 30 seconds"
74
- - "Download sound #123456 as high quality"
280
+ Ask your AI client in natural language:
75
281
 
76
- ### Available Tools
282
+ - "Find me a rainforest ambience under 30 seconds with a Creative Commons 0 license."
283
+ - "Search for CC0 piano samples, newest first, 5 per page."
284
+ - "Show me the details for sound #123456."
285
+ - "Find sounds similar to #123456."
286
+ - "Download sound #123456 as a high-quality preview."
287
+ - "Download the original file for #123456." (requires OAuth2)
77
288
 
78
- #### 1. Freesound Search (`freesound_search`)
289
+ The model calls the tools above and reports the license and author returned by
290
+ Freesound.
79
291
 
80
- Search for sounds on Freesound by providing keywords and optional filters.
292
+ ## Security and licensing
81
293
 
82
- Parameters:
83
- - `query` (required): Search keywords
84
- - `maxDuration` (optional): Maximum duration of sounds in seconds
85
- - `license` (optional): License type of sounds to search for
294
+ - Keep `FREESOUND_API_KEY` and `FREESOUND_OAUTH_TOKEN` secret. Pass them through
295
+ your MCP client's `env` block, never through source control.
296
+ - Freesound content is licensed under Creative Commons terms. Check the
297
+ `license` field before use, credit the author, and respect
298
+ `Attribution NonCommercial` restrictions.
299
+ - `freesound_download` writes to the local filesystem. Choose a writable
300
+ `downloadDir` and avoid running the server with elevated privileges.
301
+ - Filenames supplied by callers are sanitized, and downloads are written to a
302
+ temporary file before being renamed into place.
86
303
 
87
- Returns:
88
- - Array of sound objects containing:
89
- - `id`: Sound ID
90
- - `name`: Sound name
91
- - `duration`: Sound duration in seconds
92
- - `license`: Sound license
93
- - `preview`: Sound preview URL
304
+ ## Troubleshooting
94
305
 
95
- #### 2. Freesound Download (`freesound_download`)
306
+ | Symptom | Fix |
307
+ | --- | --- |
308
+ | `401 Unauthorized` | Check `FREESOUND_API_KEY` and restart the client |
309
+ | `429 Too Many Requests` | Lower request frequency or increase `FREESOUND_MAX_RETRIES`; Freesound enforces API quotas |
310
+ | `FREESOUND_OAUTH_TOKEN is not set` | Set an OAuth2 token to use `quality: "original"` |
311
+ | "does not expose a downloadable preview" | The sound has no previews; try another sound or original download |
312
+ | Download fails with `EACCES`/`ENOENT` | Choose a writable `downloadDir` |
313
+ | Server missing from the client | Run `npm run build`, use an absolute path, and check the client's MCP logs |
96
314
 
97
- Download a sound from Freesound by sound ID.
315
+ ## Development
98
316
 
99
- Parameters:
100
- - `soundId` (required): ID of the sound to download
101
- - `quality` (optional): Audio quality ('hq' for high quality or 'lq' for low quality), defaults to 'lq'
102
- - `downloadDir` (optional): Custom download directory, defaults to ~/.freesound-mcp/downloads
317
+ ```bash
318
+ npm ci
319
+ npm run build # compile TypeScript to build/
320
+ npm run typecheck # type-check without emitting
321
+ npm test # build + run the node:test suite
322
+ npm start # run the compiled stdio server
323
+ ```
103
324
 
104
- Returns:
105
- - `filePath`: Path where the file was downloaded
325
+ The test suite uses Node's built-in test runner and mocks `fetch`, so it runs
326
+ offline without a Freesound API key. The runner collects `*.test.js` files
327
+ explicitly, so `npm test` also works on Node.js 20 and Windows shells. CI runs
328
+ the same commands on Node.js 20, 22, and 24.
106
329
 
107
- ## Security Considerations
330
+ Project layout:
108
331
 
109
- - Keep your `FREESOUND_API_KEY` secret and never expose it in client-side code
110
- - Input parameters are validated to prevent malicious IDs from being passed to the API
111
- - The server follows MCP security best practices for communication
332
+ - `src/index.ts` — stdio entry point and shutdown handling
333
+ - `src/server.ts` — MCP tool registration, schemas, and error mapping
334
+ - `src/freesound/client.ts` — authenticated HTTP client, timeouts, retries
335
+ - `src/freesound/search.ts` — search parameters, filters, and result mapping
336
+ - `src/freesound/similar.ts` — similar-sounds endpoint
337
+ - `src/freesound/sounds.ts` — sound details, preview/original downloads
338
+ - `src/freesound/errors.ts` — structured error types
339
+ - `test/` — unit tests, in-memory MCP tests, and a real stdio end-to-end test
112
340
 
113
341
  ## Contributing
114
342
 
115
- Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
343
+ Contributions are welcome! Please open an issue first for major changes, then
344
+ submit a pull request. Keep the test suite green and update the README and
345
+ CHANGELOG for user-visible changes.
116
346
 
117
347
  ## License
118
348
 
119
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
349
+ This project is licensed under the MIT License — see [LICENSE](LICENSE) for
350
+ details.
120
351
 
121
352
  ## Acknowledgments
122
353
 
123
- - Thanks to [Freesound](https://freesound.org/) for providing the audio resources API
124
- - Built using the [Model Context Protocol SDK](https://github.com/modelcontextprotocol/sdk)
354
+ - [Freesound](https://freesound.org/) for the audio resources and API
355
+ - [Model Context Protocol SDK](https://github.com/modelcontextprotocol/sdk)
356
+ - [LobeHub](https://lobehub.com/mcp) for the MCP directory badge