@mushan_bit/freesound-mcp 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dylan Kong
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.
package/README.md ADDED
@@ -0,0 +1,124 @@
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.
4
+
5
+ ## Overview
6
+
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:
8
+
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
12
+
13
+ ## Features
14
+
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
19
+
20
+ ## Prerequisites
21
+
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))
25
+
26
+ ## Installation
27
+
28
+ 1. Clone the repository:
29
+ ```bash
30
+ git clone https://github.com/yourusername/freesound-mcp.git
31
+ cd freesound-mcp
32
+ ```
33
+
34
+ 2. Install dependencies:
35
+ ```bash
36
+ npm install
37
+ ```
38
+
39
+ 3. Build the project:
40
+ ```bash
41
+ npm run build
42
+ ```
43
+
44
+ ## Setup
45
+
46
+ 1. Get your Freesound API key from [Freesound API page](https://freesound.org/docs/api/authentication.html)
47
+
48
+ 2. Set your API key as an environment variable:
49
+ ```bash
50
+ export FREESOUND_API_KEY=your_freesound_api_key_here
51
+ ```
52
+
53
+ ## Configuration in Claude Desktop
54
+
55
+ To configure this MCP server in Claude Desktop:
56
+
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
66
+
67
+ After restarting Claude, you'll be able to use the Freesound tools in your conversations.
68
+
69
+ ## Usage
70
+
71
+ Once configured in Claude, you can use natural language commands such as:
72
+
73
+ - "Find me a rainforest ambient sound under 30 seconds"
74
+ - "Download sound #123456 as high quality"
75
+
76
+ ### Available Tools
77
+
78
+ #### 1. Freesound Search (`freesound_search`)
79
+
80
+ Search for sounds on Freesound by providing keywords and optional filters.
81
+
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
86
+
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
94
+
95
+ #### 2. Freesound Download (`freesound_download`)
96
+
97
+ Download a sound from Freesound by sound ID.
98
+
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
103
+
104
+ Returns:
105
+ - `filePath`: Path where the file was downloaded
106
+
107
+ ## Security Considerations
108
+
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
112
+
113
+ ## Contributing
114
+
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.
116
+
117
+ ## License
118
+
119
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
120
+
121
+ ## Acknowledgments
122
+
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)
@@ -0,0 +1,48 @@
1
+ import fs from 'fs';
2
+ import { searchSounds, downloadSound } from '../tools/freesound.js';
3
+ async function testFreesoundAPI() {
4
+ try {
5
+ console.log('Testing Freesound API...');
6
+ console.log('API Key:', process.env.FREESOUND_API_KEY ? 'Present' : 'Missing');
7
+ // Test search functionality
8
+ console.log('Testing searchSounds function...');
9
+ const results = await searchSounds({
10
+ query: 'piano'
11
+ });
12
+ console.log(`Found ${results.length} results:`);
13
+ results.slice(0, 3).forEach((sound, index) => {
14
+ console.log(`${index + 1}. ${sound.name}`);
15
+ console.log(` ID: ${sound.id}`);
16
+ console.log(` Duration: ${sound.duration}s`);
17
+ console.log(` License: ${sound.license}`);
18
+ console.log(` Preview: ${sound.preview}`);
19
+ console.log('');
20
+ });
21
+ console.log('✅ Freesound API test successful!');
22
+ // Test download functionality with first result
23
+ if (results.length > 0) {
24
+ console.log('\nTesting download functionality...');
25
+ const firstSound = results[0];
26
+ console.log(`Downloading: ${firstSound.name} (ID: ${firstSound.id})`);
27
+ try {
28
+ const downloadedPath = await downloadSound(firstSound.id);
29
+ console.log(`✅ Downloaded preview MP3 to: ${downloadedPath}`);
30
+ // Check file info
31
+ const stats = fs.statSync(downloadedPath);
32
+ console.log(` File size: ${(stats.size / 1024).toFixed(2)} KB`);
33
+ }
34
+ catch (downloadError) {
35
+ console.log(`⚠️ Download test failed: ${downloadError.message}`);
36
+ }
37
+ console.log('\n📝 Note: To download original high-quality audio files, you need:');
38
+ console.log(' 1. OAuth2 authentication (more complex setup)');
39
+ console.log(' 2. Use downloadOriginalAudio() function with an access token');
40
+ console.log(' 3. The current downloadSound() function downloads preview MP3s');
41
+ }
42
+ }
43
+ catch (error) {
44
+ console.error('❌ Freesound API test failed:', error.message);
45
+ process.exit(1);
46
+ }
47
+ }
48
+ testFreesoundAPI();
package/build/index.js ADDED
@@ -0,0 +1,75 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import { z } from "zod";
4
+ import { searchSounds, downloadSound } from "./tools/freesound.js";
5
+ // Create server instance
6
+ const server = new McpServer({
7
+ name: "freesound-mcp",
8
+ version: "1.0.0",
9
+ });
10
+ server.registerTool('freesound_search', {
11
+ title: 'Freesound Search',
12
+ description: 'Search for sounds on Freesound',
13
+ inputSchema: {
14
+ query: z.string().describe("Search keywords"),
15
+ maxDuration: z.number().describe("Maximum duration of sounds in seconds").optional(),
16
+ license: z.string().describe("License of sounds to search for").optional(),
17
+ },
18
+ outputSchema: {
19
+ results: z.array(z.object({
20
+ id: z.number().describe("Sound ID"),
21
+ name: z.string().optional().describe("Sound name"),
22
+ duration: z.number().optional().describe("Sound duration in seconds"),
23
+ license: z.string().optional().describe("Sound license"),
24
+ preview: z.string().optional().describe("Sound preview URL"),
25
+ }))
26
+ }
27
+ }, async (args, extra) => {
28
+ const sounds = await searchSounds(args);
29
+ const structuredContent = {
30
+ results: sounds
31
+ };
32
+ return {
33
+ content: [
34
+ {
35
+ type: "text",
36
+ text: JSON.stringify(structuredContent, null, 2)
37
+ }
38
+ ],
39
+ structuredContent
40
+ };
41
+ });
42
+ server.registerTool('freesound_download', {
43
+ title: 'Freesound Download',
44
+ description: 'Download a sound from Freesound by sound ID',
45
+ inputSchema: {
46
+ soundId: z.number().describe("ID of the sound to download"),
47
+ quality: z.enum(['hq', 'lq']).describe("Audio quality: 'hq' for high quality or 'lq' for low quality").optional().default('lq'),
48
+ downloadDir: z.string().describe("Custom download directory, defaults to ~/.freesound-mcp/downloads").optional(),
49
+ },
50
+ outputSchema: {
51
+ filePath: z.string().describe("Path where the file was downloaded"),
52
+ }
53
+ }, async (args, extra) => {
54
+ const { soundId, quality = 'lq', downloadDir } = args;
55
+ const filePath = await downloadSound(soundId, quality, downloadDir);
56
+ return {
57
+ filePath: filePath,
58
+ content: [
59
+ {
60
+ type: "text",
61
+ text: JSON.stringify({ filePath: filePath }, null, 2)
62
+ }
63
+ ],
64
+ structuredContent: { filePath: filePath }
65
+ };
66
+ });
67
+ async function main() {
68
+ const transport = new StdioServerTransport();
69
+ await server.connect(transport);
70
+ console.error("Freesound MCP Server running on stdio"); // 修正控制台消息
71
+ }
72
+ main().catch((error) => {
73
+ console.error("Fatal error in main():", error);
74
+ process.exit(1);
75
+ });
@@ -0,0 +1,100 @@
1
+ import fs from "fs";
2
+ import os from "os";
3
+ import path from "path";
4
+ const API_KEY = process.env.FREESOUND_API_KEY;
5
+ const BASE_URL = "https://freesound.org/apiv2";
6
+ /**
7
+ * fetch
8
+ * @param url url
9
+ * @returns result
10
+ */
11
+ async function apiFetch(url) {
12
+ const res = await fetch(url, {
13
+ headers: {
14
+ "Authorization": `Token ${API_KEY}`
15
+ }
16
+ });
17
+ if (!res.ok) {
18
+ const errorText = await res.text();
19
+ throw new Error(`Freesound API error: ${res.status} - ${errorText}`);
20
+ }
21
+ return res.json();
22
+ }
23
+ /**
24
+ * searchSounds
25
+ * @param query query
26
+ * @param maxDuration maxDuration
27
+ * @param license license
28
+ * @returns result
29
+ */
30
+ export async function searchSounds({ query, maxDuration, license }) {
31
+ let url = `${BASE_URL}/search/text/?query=${encodeURIComponent(query)}&fields=id,name,duration,previews,license`;
32
+ if (maxDuration) {
33
+ url += `&filter=duration:[0+TO+${maxDuration}]`;
34
+ }
35
+ if (license) {
36
+ url += `&filter=license:${license}`;
37
+ }
38
+ const data = await apiFetch(url);
39
+ return data.results.map(item => ({
40
+ id: item.id,
41
+ name: item.name,
42
+ duration: item.duration,
43
+ license: item.license,
44
+ preview: item.previews["preview-hq-mp3"]
45
+ }));
46
+ }
47
+ /**
48
+ * downloadSound
49
+ * @param soundId soundId
50
+ * @param quality audio quality ('hq' for high quality or 'lq' for low quality)
51
+ * @param downloadDir custom download directory
52
+ * @returns result
53
+ */
54
+ export async function downloadSound(soundId, quality = 'lq', downloadDir) {
55
+ const sound = await apiFetch(`${BASE_URL}/sounds/${soundId}/`);
56
+ // Determine which preview URL to use based on quality
57
+ let previewUrl;
58
+ if (quality === 'hq') {
59
+ previewUrl = sound.previews?.["preview-hq-mp3"] || sound.previews?.["preview-lq-mp3"];
60
+ }
61
+ else {
62
+ previewUrl = sound.previews?.["preview-lq-mp3"] || sound.previews?.["preview-hq-mp3"];
63
+ }
64
+ if (!previewUrl) {
65
+ throw new Error('No preview available for this sound');
66
+ }
67
+ const res = await fetch(previewUrl);
68
+ if (!res.ok) {
69
+ const errorText = await res.text();
70
+ throw new Error(`Download failed: ${res.status} - ${errorText}`);
71
+ }
72
+ // Use provided directory or default to ~/.freesound-mcp/downloads
73
+ const dir = downloadDir || path.join(os.homedir(), '.freesound-mcp', 'downloads');
74
+ // Ensure directory exists
75
+ fs.mkdirSync(dir, { recursive: true });
76
+ const filePath = path.join(dir, `${soundId}_preview_${quality}.mp3`);
77
+ const buffer = await res.arrayBuffer();
78
+ fs.writeFileSync(filePath, new Uint8Array(buffer));
79
+ return filePath;
80
+ }
81
+ // New function to download original audio (requires OAuth2)
82
+ export async function downloadOriginalAudio(soundId, accessToken, downloadDir) {
83
+ const sound = await apiFetch(`${BASE_URL}/sounds/${soundId}/`);
84
+ const downloadUrl = sound.download;
85
+ const res = await fetch(downloadUrl, {
86
+ headers: { Authorization: `Bearer ${accessToken}` }
87
+ });
88
+ if (!res.ok) {
89
+ const errorText = await res.text();
90
+ throw new Error(`Download failed: ${res.status} - ${errorText}`);
91
+ }
92
+ // Use provided directory or default to ~/.freesound-mcp/downloads
93
+ const dir = downloadDir || path.join(os.homedir(), '.freesound-mcp', 'downloads');
94
+ // Ensure directory exists
95
+ fs.mkdirSync(dir, { recursive: true });
96
+ const filePath = path.join(dir, `${soundId}.${sound.type || 'wav'}`);
97
+ const buffer = await res.arrayBuffer();
98
+ fs.writeFileSync(filePath, new Uint8Array(buffer));
99
+ return filePath;
100
+ }
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@mushan_bit/freesound-mcp",
3
+ "version": "1.0.2",
4
+ "main": "index.js",
5
+ "type": "module",
6
+ "keywords": [
7
+ "mcp",
8
+ "freesound"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc && chmod 755 build/index.js"
12
+ },
13
+ "files": [
14
+ "build"
15
+ ],
16
+ "license": "ISC",
17
+ "author": "mushan <mushanfu0@gmail.com>",
18
+ "description": "",
19
+ "dependencies": {
20
+ "@modelcontextprotocol/sdk": "^1.25.3",
21
+ "zod": "^4.3.6"
22
+ },
23
+ "devDependencies": {
24
+ "@types/node": "^25.0.10",
25
+ "typescript": "^5.9.3"
26
+ }
27
+ }