Files
Enterprise-Knowledge-Base/frontend/src/api/mcp-service.ts
T
wizardchen 77b6133e2a feat: Add MCP services support and enhance migration scripts
- Introduced new MCP services functionality, including management routes and integration with the agent service.
- Updated Docker Compose configuration to include a new SQL migration for MCP services.
- Enhanced Makefile with new migration commands for versioning and creating migrations.
- Improved chat component to handle selected MCP services in message processing.
- Updated migration documentation to reflect new strategies and added MCP services migration files.
2025-11-09 03:27:24 +08:00

99 lines
2.7 KiB
TypeScript

import { get, post, put, del } from '@/utils/request'
export interface MCPService {
id: string
tenant_id?: number
name: string
description: string
enabled: boolean
transport_type: 'sse' | 'http-streamable'
url: string
headers?: Record<string, string>
auth_config?: {
api_key?: string
token?: string
custom_headers?: Record<string, string>
}
advanced_config?: {
timeout?: number
retry_count?: number
retry_delay?: number
}
created_at?: string
updated_at?: string
}
export interface MCPTool {
name: string
description: string
inputSchema: Record<string, any>
}
export interface MCPResource {
uri: string
name: string
description?: string
mimeType?: string
}
export interface MCPTestResult {
success: boolean
message?: string
tools?: MCPTool[]
resources?: MCPResource[]
}
// List all MCP services
export async function listMCPServices(): Promise<MCPService[]> {
const response: any = await get('/api/v1/mcp-services')
return response.data || []
}
// Get a single MCP service by ID
export async function getMCPService(id: string): Promise<MCPService> {
const response: any = await get(`/api/v1/mcp-services/${id}`)
return response.data
}
// Create a new MCP service
export async function createMCPService(data: Partial<MCPService>): Promise<MCPService> {
const response: any = await post('/api/v1/mcp-services', data)
return response.data
}
// Update an existing MCP service
export async function updateMCPService(id: string, data: Partial<MCPService>): Promise<MCPService> {
const response: any = await put(`/api/v1/mcp-services/${id}`, data)
return response.data
}
// Delete an MCP service
export async function deleteMCPService(id: string): Promise<void> {
await del(`/api/v1/mcp-services/${id}`)
}
// Test MCP service connection
export async function testMCPService(id: string): Promise<MCPTestResult> {
const response: any = await post(`/api/v1/mcp-services/${id}/test`, {})
// 后端返回格式: { success: true, data: MCPTestResult }
// response interceptor 已经返回了 data,所以 response 就是 { success: true, data: {...} }
if (response && response.data) {
return response.data
}
// 如果格式不对,尝试直接返回 response(可能是直接返回的数据)
return response
}
// Get tools from an MCP service
export async function getMCPServiceTools(id: string): Promise<MCPTool[]> {
const response: any = await get(`/api/v1/mcp-services/${id}/tools`)
return response.data || []
}
// Get resources from an MCP service
export async function getMCPServiceResources(id: string): Promise<MCPResource[]> {
const response: any = await get(`/api/v1/mcp-services/${id}/resources`)
return response.data || []
}