@atlas-kitchen/atlas-mcp
Version:
Model Context Protocol server for Atlas restaurant management system - enables Claude to interact with restaurant orders, menus, and reports
155 lines • 6.09 kB
JavaScript
import { z } from 'zod';
const LoginSchema = z.object({
email: z.string().email(),
password: z.string(),
});
const RefreshTokenSchema = z.object({
refreshToken: z.string().optional(),
});
const SwitchMerchantSchema = z.object({
merchantId: z.string(),
outletId: z.string().optional(),
brandId: z.string().optional(),
});
export function createAuthTools(client, authManager) {
return [
{
name: 'atlas_login',
description: 'Login to Atlas with email and password',
inputSchema: {
type: 'object',
properties: {
email: { type: 'string', description: 'User email address' },
password: { type: 'string', description: 'User password' },
},
required: ['email', 'password'],
},
handler: async (input) => {
const { email, password } = LoginSchema.parse(input);
try {
const response = await client.login(email, password);
// Store tokens
authManager.setTokens({
accessToken: response.accessToken,
refreshToken: response.refreshToken,
});
// Set first merchant as default if available
if (response.merchants && response.merchants.length > 0) {
authManager.setMerchantContext(response.merchants[0].id);
}
return {
success: true,
account: response.account,
merchants: response.merchants,
message: `Successfully logged in as ${response.account.email}`,
};
}
catch (error) {
return {
success: false,
error: error.message || 'Login failed',
};
}
},
},
{
name: 'atlas_logout',
description: 'Logout from Atlas and clear authentication',
inputSchema: {
type: 'object',
properties: {},
},
handler: async () => {
try {
if (authManager.isAuthenticated()) {
await client.logout();
}
authManager.clear();
return {
success: true,
message: 'Successfully logged out',
};
}
catch (error) {
// Even if logout fails, clear local auth
authManager.clear();
return {
success: true,
message: 'Logged out locally',
};
}
},
},
{
name: 'atlas_refresh_token',
description: 'Refresh the access token using refresh token',
inputSchema: {
type: 'object',
properties: {
refreshToken: { type: 'string', description: 'Refresh token (uses stored token if not provided)' },
},
},
handler: async (input) => {
const { refreshToken } = RefreshTokenSchema.parse(input);
try {
const tokenToUse = refreshToken || authManager.getTokens()?.refreshToken;
if (!tokenToUse) {
return {
success: false,
error: 'No refresh token available',
};
}
const response = await client.refreshToken(tokenToUse);
// Update tokens
authManager.setTokens({
accessToken: response.accessToken,
refreshToken: response.refreshToken,
});
return {
success: true,
message: 'Token refreshed successfully',
};
}
catch (error) {
return {
success: false,
error: error.message || 'Token refresh failed',
};
}
},
},
{
name: 'atlas_switch_merchant',
description: 'Switch active merchant context. IMPORTANT: Most POS operations require an outletId to be set!',
inputSchema: {
type: 'object',
properties: {
merchantId: { type: 'string', description: 'Merchant ID to switch to' },
outletId: { type: 'string', description: 'Outlet ID (REQUIRED for POS operations like atlas_get_pos_carts and atlas_get_product_insights)' },
brandId: { type: 'string', description: 'Brand ID (optional)' },
},
required: ['merchantId'],
},
handler: async (input) => {
const { merchantId, outletId, brandId } = SwitchMerchantSchema.parse(input);
if (!authManager.isAuthenticated()) {
return {
success: false,
error: 'Not authenticated. Please login first.',
};
}
authManager.setMerchantContext(merchantId, outletId, brandId);
return {
success: true,
message: 'Merchant context switched successfully',
context: {
merchantId,
outletId: outletId || null,
brandId: brandId || null,
},
};
},
},
];
}
//# sourceMappingURL=auth.js.map