Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { promises as fs } from 'fs';
import { notFound } from 'next/navigation';
import path from 'path';
import { actionGetUserMcpServer } from '~/components/mcp/action';
import { McpView } from '~/components/mcp/mcp-view';
import { getMCPSourceDir } from '~/lib/ai/tools/user-mcp';
import { MCPServerInsert } from '~/lib/db/schema';
import { findServerOnDisk } from '~/lib/db/mcp-servers';

type PageParams = {
project: string;
Expand All @@ -13,57 +9,8 @@ type PageParams = {

export default async function McpServerPage({ params }: { params: Promise<PageParams> }) {
const { server: serverId } = await params;
const mcpSourceDir = getMCPSourceDir();

// Check if server file exists locally
const filePath = path.join(mcpSourceDir, `${serverId}.ts`);
let server: MCPServerInsert | null = null;

try {
// Try to read the local file first
await fs.access(filePath);
const content = await fs.readFile(filePath, 'utf-8');

// Extract metadata from file content
const nameMatch = content.match(/name:\s*['"]([^'"]+)['"]/);
const versionMatch = content.match(/version:\s*['"]([^'"]+)['"]/);

server = {
name: serverId,
serverName: nameMatch?.[1] ?? serverId,
version: versionMatch?.[1] ?? '1.0.0',
filePath: `${serverId}.ts`,
enabled: false
};

// Try to get additional data from database if it exists
try {
const dbServer = await actionGetUserMcpServer(serverId);
if (dbServer && server) {
server.enabled = dbServer.enabled;
}
} catch (error) {
// Ignore database errors, we'll use the local file data
console.error('Error fetching server from database:', error);
}
} catch (error) {
// If local file doesn't exist, try database
try {
const dbServer = await actionGetUserMcpServer(serverId);
if (dbServer) {
server = {
name: dbServer.name,
serverName: dbServer.serverName,
version: dbServer.version,
filePath: dbServer.filePath,
enabled: dbServer.enabled
};
}
} catch (error) {
console.error('Error fetching server from database:', error);
}
}

const server = await findServerOnDisk(serverId);
if (!server) {
notFound();
}
Expand Down
125 changes: 0 additions & 125 deletions apps/dbagent/src/app/(main)/projects/[project]/mcp/create/page.tsx

This file was deleted.

32 changes: 3 additions & 29 deletions apps/dbagent/src/app/api/mcp/servers/[server]/route.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,13 @@
import { promises as fs } from 'fs';
import { NextResponse } from 'next/server';
import path from 'path';
import { getMCPSourceDir } from '~/lib/ai/tools/user-mcp';

const mcpSourceDir = getMCPSourceDir();
import { findServerOnDisk } from '~/lib/db/mcp-servers';

export async function GET(_: Request, { params }: { params: Promise<{ server: string }> }) {
try {
const { server } = await params;
const filePath = path.join(mcpSourceDir, `${server}.ts`);

// Check if file exists
try {
await fs.access(filePath);
} catch (error) {
const metadata = await findServerOnDisk(server);
if (!metadata) {
return NextResponse.json({ error: 'Server file not found' }, { status: 404 });
}

// Read file content
const content = await fs.readFile(filePath, 'utf-8');

// Extract metadata from file content
const nameMatch = content.match(/name:\s*['"]([^'"]+)['"]/);
const versionMatch = content.match(/version:\s*['"]([^'"]+)['"]/);
const descriptionMatch = content.match(/description:\s*['"]([^'"]+)['"]/);

const metadata = {
name: server,
serverName: nameMatch ? nameMatch[1] : server,
version: versionMatch ? versionMatch[1] : '1.0.0',
description: descriptionMatch ? descriptionMatch[1] : '',
filePath: `${server}.ts`,
enabled: false
};

return NextResponse.json(metadata);
} catch (error) {
console.error('Error reading server file:', error);
Expand Down
22 changes: 6 additions & 16 deletions apps/dbagent/src/app/api/mcp/servers/route.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
import { promises as fs } from 'fs';
import { NextResponse } from 'next/server';
import path from 'path';
import { getMCPSourceDir } from '~/lib/ai/tools/user-mcp';
import { getMCPServersDir } from '~/lib/ai/tools/user-mcp';

const mcpSourceDir = getMCPSourceDir();
const mcpServersDir = getMCPServersDir();

export async function GET() {
try {
const files = await fs.readdir(mcpSourceDir);
const serverFiles = files.filter((file) => file.endsWith('.ts') && !file.endsWith('.d.ts'));
const files = await fs.readdir(mcpServersDir);
const serverFiles = files.filter((file) => file.endsWith('.js'));

const servers = await Promise.all(
serverFiles.map(async (file) => {
const filePath = path.join(mcpSourceDir, file);
const content = await fs.readFile(filePath, 'utf-8');

// Extract server name and version from the file content
const nameMatch = content.match(/name:\s*['"]([^'"]+)['"]/);
const versionMatch = content.match(/version:\s*['"]([^'"]+)['"]/);

return {
name: path.basename(file, '.ts'),
serverName: nameMatch ? nameMatch[1] : path.basename(file, '.ts'),
version: versionMatch ? versionMatch[1] : '1.0.0',
filePath: file,
name: file.endsWith('.js') ? file.slice(0, -3) : file,
serverName: file,
enabled: false
};
})
Expand Down
52 changes: 0 additions & 52 deletions apps/dbagent/src/app/api/mcp/servers/upload/route.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
SelectValue,
toast
} from '@xata.io/components';
import { AlertCircle, Loader2 } from 'lucide-react';
import { Loader2 } from 'lucide-react';
import Link from 'next/link';
import { useEffect, useState } from 'react';
import { RDSClusterDetailedInfo, RDSClusterInfo } from '~/lib/aws/rds';
Expand Down Expand Up @@ -130,7 +130,6 @@ export function AWSIntegration({ projectId, connections }: { projectId: string;
<CardContent>
<div className="mb-6">
<Alert>
<AlertCircle className="h-4 w-4" />
<AlertTitle>Add an IAM policy and user</AlertTitle>
<AlertDescription>
To obtain the Access Key ID and Secret Access Key,{' '}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
Textarea,
toast
} from '@xata.io/components';
import { AlertCircle, Loader2 } from 'lucide-react';
import { Loader2 } from 'lucide-react';
import Link from 'next/link';
import { useEffect, useState } from 'react';
import { Connection } from '~/lib/db/schema';
Expand Down Expand Up @@ -115,7 +115,6 @@ export function GCPIntegration({ projectId, connections }: { projectId: string;
<CardContent>
<div className="mb-6">
<Alert>
<AlertCircle className="h-4 w-4" />
<AlertTitle>Create a service account</AlertTitle>
<AlertDescription>
To create a GCP service account for the Agent, follow this guide:{' '}
Expand Down
Loading
Loading