UNPKG

xero-mcp

Version:

A Model Context Protocol server allows Clients to interact with Xero

24 lines (23 loc) 804 B
import { XeroClientSession } from "../XeroApiClient.js"; import { AuthenticateTool } from "../Tools/Authenticate.js"; export const XeroAuthMiddleware = async (request, next) => { const { name } = request.params; if (name === AuthenticateTool.requestSchema.name) { return await AuthenticateTool.requestHandler(request); } if (!XeroClientSession.isAuthenticated()) { return Promise.resolve({ content: [ { type: "text", text: "You must authenticate with Xero first", }, ], }); } const tenantId = XeroClientSession.activeTenantId(); if (!tenantId) { throw new Error("No tenant selected. Please authenticate again."); } return next(request); };