Files
sproutclaw-data/agent/extensions/pi-mcp-adapter/tool-registrar.ts
shumengya 50edff80f5 feat: 导出 SproutClaw .sproutclaw 配置
包含 extensions、skills、prompts、settings、auth、models、mcp 等配置。
排除 node_modules、npm 缓存、sessions 等运行时数据。
2026-06-26 15:48:56 +08:00

47 lines
1.5 KiB
TypeScript

// tool-registrar.ts - MCP content transformation
// NOTE: Tools are NOT registered with Pi - only the unified `mcp` proxy tool is registered.
// This keeps the LLM context small (1 tool instead of 100s).
import type { McpContent, ContentBlock } from "./types.ts";
/**
* Transform MCP content types to Pi content blocks.
*/
export function transformMcpContent(content: McpContent[]): ContentBlock[] {
return content.map(c => {
if (c.type === "text") {
return { type: "text" as const, text: c.text ?? "" };
}
if (c.type === "image") {
return {
type: "image" as const,
data: c.data ?? "",
mimeType: c.mimeType ?? "image/png",
};
}
if (c.type === "resource") {
const resourceUri = c.resource?.uri ?? "(no URI)";
const resourceContent = c.resource?.text ?? (c.resource ? JSON.stringify(c.resource) : "(no content)");
return {
type: "text" as const,
text: `[Resource: ${resourceUri}]\n${resourceContent}`,
};
}
if (c.type === "resource_link") {
const linkName = c.name ?? c.uri ?? "unknown";
const linkUri = c.uri ?? "(no URI)";
return {
type: "text" as const,
text: `[Resource Link: ${linkName}]\nURI: ${linkUri}`,
};
}
if (c.type === "audio") {
return {
type: "text" as const,
text: `[Audio content: ${c.mimeType ?? "audio/*"}]`,
};
}
return { type: "text" as const, text: JSON.stringify(c) };
});
}