filemaker-data-api-mcp
Version:
Model Context Protocol (MCP) server providing FileMaker Data API integration with database introspection for AI agents. Compatible with Claude, Windsurf, Cursor, Cline, and other MCP-enabled assistants.
138 lines • 4.59 kB
JavaScript
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import express from "express";
import https from "https";
import http from "http";
import fs from "fs";
/**
* Parse transport configuration from environment variables
*/
export function getTransportConfig() {
const transportType = (process.env.MCP_TRANSPORT || "stdio");
const config = {
type: transportType,
port: process.env.MCP_PORT ? parseInt(process.env.MCP_PORT, 10) : 3000,
host: process.env.MCP_HOST || "localhost",
certPath: process.env.MCP_CERT_PATH,
keyPath: process.env.MCP_KEY_PATH,
};
return config;
}
/**
* Create and connect transport based on configuration
*/
export async function setupTransport(server, config) {
switch (config.type) {
case "stdio":
await setupStdioTransport(server);
break;
case "http":
await setupHttpTransport(server, config);
break;
case "https":
await setupHttpsTransport(server, config);
break;
default:
throw new Error(`Unknown transport type: ${config.type}`);
}
}
/**
* Setup stdio transport (default, for local use)
*/
async function setupStdioTransport(server) {
const transport = new StdioServerTransport();
await server.connect(transport);
console.error("FileMaker Data API MCP Server running on stdio");
}
/**
* Custom HTTP transport wrapper for MCP server
*/
class HttpTransportWrapper {
server;
app;
constructor(server, app) {
this.server = server;
this.app = app;
this.setupRoutes();
}
setupRoutes() {
// Health check endpoint
this.app.get("/health", (req, res) => {
res.json({ status: "ok", transport: "http" });
});
// MCP endpoint - handles both GET and POST
this.app.post("/mcp", async (req, res) => {
try {
const request = req.body;
// The server processes requests through its tool handlers
// This is a simple echo/passthrough for now
res.json({
status: "ok",
message: "MCP request received",
request: request,
});
}
catch (error) {
console.error("Error handling MCP request:", error);
res.status(500).json({
error: error instanceof Error ? error.message : "Unknown error",
});
}
});
this.app.get("/mcp", (req, res) => {
res.json({
info: "FileMaker Data API MCP Server",
transport: "http",
methods: ["POST"],
endpoint: "/mcp",
});
});
}
}
/**
* Setup HTTP transport
*/
async function setupHttpTransport(server, config) {
const app = express();
// Middleware
app.use(express.json());
// Create transport wrapper
new HttpTransportWrapper(server, app);
const port = config.port || 3000;
const host = config.host || "localhost";
http.createServer(app).listen(port, host, () => {
console.error(`FileMaker Data API MCP Server running on http://${host}:${port}`);
console.error(`MCP endpoint: http://${host}:${port}/mcp`);
console.error(`Health check: http://${host}:${port}/health`);
});
}
/**
* Setup HTTPS transport
*/
async function setupHttpsTransport(server, config) {
const app = express();
// Middleware
app.use(express.json());
// Create transport wrapper
new HttpTransportWrapper(server, app);
// Load certificates
if (!config.certPath || !config.keyPath) {
throw new Error("HTTPS transport requires MCP_CERT_PATH and MCP_KEY_PATH environment variables");
}
let cert;
let key;
try {
cert = fs.readFileSync(config.certPath);
key = fs.readFileSync(config.keyPath);
}
catch (error) {
throw new Error(`Failed to load HTTPS certificates: ${error instanceof Error ? error.message : String(error)}`);
}
const port = config.port || 3443;
const host = config.host || "localhost";
https.createServer({ cert, key }, app).listen(port, host, () => {
console.error(`FileMaker Data API MCP Server running on https://${host}:${port}`);
console.error(`MCP endpoint: https://${host}:${port}/mcp`);
console.error(`Health check: https://${host}:${port}/health`);
});
}
//# sourceMappingURL=transport.js.map