mcp-ai-music 1.0.10 → 1.0.12
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/dist/index.js +22 -35
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -27,7 +27,7 @@ function getServiceBase() {
|
|
|
27
27
|
process.env.SUNO_CALLBACK_URL);
|
|
28
28
|
}
|
|
29
29
|
// 构造回调地址,可附带 chatSessionId
|
|
30
|
-
function buildCallbackUrl(kind
|
|
30
|
+
function buildCallbackUrl(kind) {
|
|
31
31
|
const base = getServiceBase();
|
|
32
32
|
if (!base) {
|
|
33
33
|
throw new Error("未配置 SUNO_SERVICE_BASE(或兼容变量),用于设置服务端基地址");
|
|
@@ -37,11 +37,7 @@ function buildCallbackUrl(kind, chatSessionId) {
|
|
|
37
37
|
"upload-cover": "/suno/callback/upload-cover",
|
|
38
38
|
"upload-extend": "/suno/callback/upload-extend",
|
|
39
39
|
};
|
|
40
|
-
|
|
41
|
-
if (chatSessionId) {
|
|
42
|
-
return `${url}?chat_session_id=${encodeURIComponent(chatSessionId)}`;
|
|
43
|
-
}
|
|
44
|
-
return url;
|
|
40
|
+
return `${base.replace(/\/$/, "")}${pathMap[kind]}`;
|
|
45
41
|
}
|
|
46
42
|
// 查询同样使用统一基地址
|
|
47
43
|
function getQueryBase() {
|
|
@@ -460,7 +456,7 @@ async function handleGenerateMusic(input, chatSessionId) {
|
|
|
460
456
|
errorMessage: "title长度超过限制,最大允许80字符。",
|
|
461
457
|
};
|
|
462
458
|
}
|
|
463
|
-
const callbackUrl = buildCallbackUrl("generate"
|
|
459
|
+
const callbackUrl = buildCallbackUrl("generate");
|
|
464
460
|
console.error(`使用回调地址: ${callbackUrl}`);
|
|
465
461
|
// 构建请求体,根据API文档,当customMode=true且instrumental=false时,
|
|
466
462
|
// 如果提供了lyrics,则使用lyrics作为prompt字段发送给API
|
|
@@ -567,7 +563,7 @@ async function handleCoverMusic(input, chatSessionId) {
|
|
|
567
563
|
instrumental,
|
|
568
564
|
model,
|
|
569
565
|
negativeTags,
|
|
570
|
-
callBackUrl: buildCallbackUrl("upload-cover"
|
|
566
|
+
callBackUrl: buildCallbackUrl("upload-cover"), // 必需的参数
|
|
571
567
|
};
|
|
572
568
|
// 根据Suno API文档,当instrumental=false且提供了lyrics时,使用lyrics作为prompt字段发送给API
|
|
573
569
|
if (!instrumental && lyrics) {
|
|
@@ -670,7 +666,7 @@ async function handleExtendMusic(input, chatSessionId) {
|
|
|
670
666
|
continueAt,
|
|
671
667
|
model,
|
|
672
668
|
negativeTags,
|
|
673
|
-
callBackUrl: buildCallbackUrl("upload-extend"
|
|
669
|
+
callBackUrl: buildCallbackUrl("upload-extend"), // 必需的参数
|
|
674
670
|
};
|
|
675
671
|
// 根据Suno API文档,当instrumental=false且提供了lyrics时,使用lyrics作为prompt字段发送给API
|
|
676
672
|
if (!instrumental && lyrics) {
|
|
@@ -988,35 +984,26 @@ server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
|
|
|
988
984
|
server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
989
985
|
try {
|
|
990
986
|
const toolName = request.params.name;
|
|
991
|
-
const
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
undefined;
|
|
996
|
-
if (chatSessionId) {
|
|
997
|
-
console.error(`接收到 chatSessionId: ${chatSessionId}`);
|
|
987
|
+
const params = request.params.arguments ?? {};
|
|
988
|
+
console.error(`收到工具调用请求: ${toolName}, 输入: ${JSON.stringify(params)}`);
|
|
989
|
+
if (toolName === 'generate_music') {
|
|
990
|
+
return await handleGenerateMusic(params);
|
|
998
991
|
}
|
|
999
|
-
|
|
1000
|
-
|
|
992
|
+
if (toolName === 'upload_cover') {
|
|
993
|
+
return await handleCoverMusic(params);
|
|
1001
994
|
}
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
return await handleCoverMusic(toolInput, chatSessionId);
|
|
1008
|
-
case EXTEND_MUSIC_TOOL.name:
|
|
1009
|
-
return await handleExtendMusic(toolInput, chatSessionId);
|
|
1010
|
-
case QUERY_PROGRESS_TOOL.name:
|
|
1011
|
-
return await handleQueryProgress(toolInput);
|
|
1012
|
-
default:
|
|
1013
|
-
console.error(`未知的工具名称: ${toolName}`);
|
|
1014
|
-
return {
|
|
1015
|
-
content: [],
|
|
1016
|
-
isError: true,
|
|
1017
|
-
errorMessage: `未找到名为 '${toolName}' 的工具。`,
|
|
1018
|
-
};
|
|
995
|
+
if (toolName === 'upload_extend') {
|
|
996
|
+
return await handleExtendMusic(params);
|
|
997
|
+
}
|
|
998
|
+
if (toolName === 'query_progress') {
|
|
999
|
+
return await handleQueryProgress(params);
|
|
1019
1000
|
}
|
|
1001
|
+
console.error(`未知的工具名称: ${toolName}`);
|
|
1002
|
+
return {
|
|
1003
|
+
content: [],
|
|
1004
|
+
isError: true,
|
|
1005
|
+
errorMessage: `未找到名为 '${toolName}' 的工具。`,
|
|
1006
|
+
};
|
|
1020
1007
|
}
|
|
1021
1008
|
catch (error) {
|
|
1022
1009
|
const errorMessage = error instanceof Error ? error.message : String(error);
|