refactor(api): migrate MCP listing from DeepNLP to PulseMCP service

- Updated imports to use PulseMCPSearchParams and PulseMCPService instead of DeepNLP equivalents
- Replaced DeepNLP API calls with PulseMCP API endpoints and parameters
- Modified cached MCP transformation to manual mapping for PulseMCP data format
- Enhanced error handling and retry logic in server tools retrieval
- Added PulseMCP API base URL constant for centralized configuration

This change switches the underlying MCP provider from DeepNLP to PulseMCP, ensuring compatibility with the new API while maintaining existing functionality for MCP listing and tool retrieval.
This commit is contained in:
Evandro Fonseca Junior committed 2025-10-28 20:19:00 -03:00
1 parent ce010d39ee
commit 1042f2136b
15 files changed
+1237 -398

No files matched your search

+58 -27
View File
@@ -2,13 +2,15 @@ import { NextResponse } from "next/server";
import {
MCPProvider,
MCPSearchParams,
DeepNLPSearchParams,
PulseMCPSearchParams,
} from "@/lib/types/mcp";
import { DeepNLPService } from "@/lib/services/deepnlp";
import { PulseMCPService } from "@/lib/services/pulsemcp";
import { MCPRepository } from "@/database/repositories/mcp";
import { MCPCacheRepository } from "@/database/repositories/mcp-cache";
import { MCPSyncService } from "@/lib/services/mcp-sync";
const PULSEMCP_API_BASE = "https://api.pulsemcp.com/v0beta";
export const dynamic = "force-dynamic";
export async function GET(request: Request) {
@@ -55,10 +57,25 @@ export async function GET(request: Request) {
if (cachedMcps.length > 0 || cacheValid) {
console.log(`Found ${cachedMcps.length} MCPs in cache`);
// Transformar para formato interno
const mcps = cachedMcps.map((item) =>
DeepNLPService.transformToMCPProvider(item)
);
// Os dados já estão no formato interno após transformação no saveBatch
const mcps = cachedMcps.map((item) => ({
id: item.id,
name: item.content_name,
author: item.publisher_id,
description: item.description || "",
version: "1.0.0",
category: item.category as MCPProvider["category"],
tags: item.content_tag_list ? item.content_tag_list.split(",") : [],
rating: item.rating,
totalRatings: item.review_cnt,
repository: item.detail_url || "",
homepage: item.website || "",
installed: false, // Será definido abaixo
subfield: item.subfield || "",
field: item.field || "",
config: [],
tools: [],
}));
// Adicionar status de instalação
const installedMCPs = MCPRepository.listInstalled();
@@ -81,32 +98,46 @@ export async function GET(request: Request) {
});
}
// 3. Fallback: buscar da API se cache vazio
console.log("Cache empty, falling back to DeepNLP API");
// 3. Fallback: buscar da API PulseMCP se cache vazio
console.log("Cache empty, falling back to PulseMCP API");
const deepnlpCategory =
category && category !== "all"
? DeepNLPService.getCategoryMapping(category)
: undefined;
const deepnlpParams: DeepNLPSearchParams = {
const pulseMCPParams: PulseMCPSearchParams = {
query: search,
category: deepnlpCategory,
page_id: page,
count_per_page: limit,
mode: "list",
offset: page * limit,
};
console.log("Calling DeepNLP API with params:", deepnlpParams);
console.log("Calling PulseMCP API with params:", pulseMCPParams);
const response = await DeepNLPService.searchMCPs(deepnlpParams);
const mcps = response.items.map((item) =>
DeepNLPService.transformToMCPProvider(item)
const response = await fetch(
`${PULSEMCP_API_BASE}/servers?${new URLSearchParams({
...(search && { query: search }),
count_per_page: limit.toString(),
offset: (page * limit).toString(),
})}`,
{
method: "GET",
headers: {
Accept: "application/json",
"User-Agent": "Ollahub-MCP-Client/1.0 (https://ollahub.com)",
},
}
);
if (!response.ok) {
throw new Error(
`PulseMCP API error: ${response.status} ${response.statusText}`
);
}
const data = await response.json();
const mcps = data.servers.map((item: any) =>
PulseMCPService.transformToMCPProvider(item)
);
// Adicionar status de instalação
const installedMCPs = MCPRepository.listInstalled();
const mcpsWithStatus = mcps.map((mcp) => ({
const mcpsWithStatus = mcps.map((mcp: MCPProvider) => ({
...mcp,
installed: installedMCPs.includes(mcp.id),
}));
@@ -114,12 +145,12 @@ export async function GET(request: Request) {
return NextResponse.json({
success: true,
mcps: mcpsWithStatus,
total: response.total_hits,
hasMore: response.total_hits > (page + 1) * limit,
total: data.total_count,
hasMore: data.total_count > (page + 1) * limit,
cached: false,
});
} catch (error: any) {
console.error("Error fetching MCPs from DeepNLP:", error);
console.error("Error fetching MCPs from PulseMCP:", error);
// Fallback para dados mock em caso de erro
console.log("Falling back to mock data due to API error");
@@ -136,13 +167,13 @@ export async function GET(request: Request) {
tags: ["maps", "location", "directions"],
rating: 4.5,
totalRatings: 2,
downloads: 20,
capabilities: ["geocoding", "directions", "places"],
repository:
"https://github.com/modelcontextprotocol/servers/tree/main/src/google-maps",
installed: false,
subfield: "MAP",
field: "MCP SERVER",
config: [],
tools: [],
},
];
+69
View File
@@ -0,0 +1,69 @@
import { NextResponse } from "next/server";
import { PulseMCPService } from "@/lib/services/pulsemcp";
const PULSEMCP_API_BASE = "https://api.pulsemcp.com/v0beta";
export const dynamic = "force-dynamic";
export async function GET(request: Request) {
try {
const { searchParams } = new URL(request.url);
const limit = parseInt(searchParams.get("limit") || "20");
const offset = parseInt(searchParams.get("offset") || "0");
console.log("🔍 Testando PulseMCP API diretamente...");
// Chamar API PulseMCP diretamente
const response = await fetch(
`${PULSEMCP_API_BASE}/servers?${new URLSearchParams({
count_per_page: limit.toString(),
offset: offset.toString(),
})}`,
{
method: "GET",
headers: {
Accept: "application/json",
"User-Agent": "Ollahub-MCP-Client/1.0 (https://ollahub.com)",
},
}
);
if (!response.ok) {
throw new Error(
`PulseMCP API error: ${response.status} ${response.statusText}`
);
}
const data = await response.json();
console.log(
`✅ PulseMCP API respondeu com ${data.servers.length} servidores`
);
// Transformar para formato interno
const mcps = data.servers.map((item: any) =>
PulseMCPService.transformToMCPProvider(item)
);
return NextResponse.json({
success: true,
mcps: mcps,
total: data.total_count,
hasMore: data.total_count > offset + limit,
source: "pulsemcp-direct",
message: `Listando ${mcps.length} servidores diretamente da API PulseMCP`,
});
} catch (error: any) {
console.error("❌ Erro ao chamar PulseMCP API:", error);
return NextResponse.json(
{
success: false,
error: error.message,
mcps: [],
total: 0,
source: "pulsemcp-direct-error",
},
{ status: 500 }
);
}
}