#!/usr/bin/env node
// Entry point for the PocketBase MCP Server
// This file uses the new Cloudflare-compatible agent
import { createAgent } from './agent-simple.js';
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
// Parse command line arguments
const args = process.argv.slice(2);
const transportType = args.find(arg => arg.startsWith('--transport='))?.split('=')[1] || 'stdio';
async function main() {
console.log('π Starting PocketBase MCP Server...');
console.log('π§ Using Cloudflare-compatible agent');
try {
// Create the agent
const agent = createAgent();
// Initialize the agent
await agent.init();
// Create the appropriate transport
let transport;
switch (transportType) {
case 'stdio':
console.log('π‘ Using STDIO transport');
transport = new StdioServerTransport();
break;
case 'sse':
case 'http':
console.warn(`β οΈ ${transportType.toUpperCase()} transport not implemented in this version`);
console.log('π‘ Falling back to STDIO transport');
transport = new StdioServerTransport();
break;
default:
console.error(`β Unsupported transport: ${transportType}`);
console.log('π‘ Falling back to STDIO transport');
transport = new StdioServerTransport();
}
// Connect the agent to the transport
await agent.connect(transport);
console.log('β
PocketBase MCP Server started successfully');
console.log('π― Server is ready for Cloudflare deployment');
} catch (error) {
console.error('β Failed to start server:', error);
process.exit(1);
}
}
// Handle graceful shutdown
process.on('SIGINT', () => {
console.log('\nπ Shutting down gracefully...');
process.exit(0);
});
process.on('SIGTERM', () => {
console.log('\nπ Shutting down gracefully...');
process.exit(0);
});
// Start the server
main().catch(error => {
console.error('π₯ Unexpected error:', error);
process.exit(1);
});