import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { z } from 'zod';
import { client } from '../client.js';
export function registerReturnAddressesTools(server: McpServer): void {
server.tool(
'create_return_address',
'Create a return address that can be used on postcards. The address is validated against USPS records by default.',
{
label: z.string().max(100).optional().describe('Friendly label (e.g., "Main Office")'),
name: z.string().min(1).max(100).describe('Name to display on return address'),
address1: z.string().min(1).max(200).describe('Street address'),
address2: z.string().max(100).optional().describe('Suite, unit, etc.'),
city: z.string().min(1).max(100).describe('City'),
state: z.string().min(2).max(2).describe('2-letter state code'),
zip: z.string().min(5).max(10).describe('ZIP code (5 or 9 digit)'),
setAsDefault: z.boolean().default(false).describe('Set this as the default return address'),
skipValidation: z
.boolean()
.default(false)
.describe('Skip USPS address validation (not recommended)'),
},
async (params) => {
try {
const address = await client.post('/return-addresses', params);
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(address, null, 2),
},
],
};
} catch (error) {
return {
content: [
{
type: 'text' as const,
text: `Error: ${error instanceof Error ? error.message : 'Unknown error'}`,
},
],
isError: true,
};
}
}
);
server.tool(
'list_return_addresses',
'Get all return addresses for your organization. Default address is listed first.',
{},
async () => {
try {
const result = await client.get('/return-addresses');
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(result, null, 2),
},
],
};
} catch (error) {
return {
content: [
{
type: 'text' as const,
text: `Error: ${error instanceof Error ? error.message : 'Unknown error'}`,
},
],
isError: true,
};
}
}
);
server.tool(
'get_return_address',
'Get detailed information about a specific return address.',
{
returnAddressId: z.string().describe('Return address ID (e.g., addr_abc123)'),
},
async (params) => {
try {
const address = await client.get(`/return-addresses/${params.returnAddressId}`);
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(address, null, 2),
},
],
};
} catch (error) {
return {
content: [
{
type: 'text' as const,
text: `Error: ${error instanceof Error ? error.message : 'Unknown error'}`,
},
],
isError: true,
};
}
}
);
server.tool(
'update_return_address',
'Update return address information. If address fields change, the address will be re-validated.',
{
returnAddressId: z.string().describe('Return address ID to update'),
label: z.string().max(100).optional().describe('Friendly label'),
name: z.string().min(1).max(100).optional().describe('Display name'),
address1: z.string().min(1).max(200).optional().describe('Street address'),
address2: z.string().max(100).nullable().optional().describe('Suite, unit, etc.'),
city: z.string().min(1).max(100).optional().describe('City'),
state: z.string().min(2).max(2).optional().describe('State code'),
zip: z.string().min(5).max(10).optional().describe('ZIP code'),
},
async (params) => {
try {
const { returnAddressId, ...updateData } = params;
const address = await client.patch(`/return-addresses/${returnAddressId}`, updateData);
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(address, null, 2),
},
],
};
} catch (error) {
return {
content: [
{
type: 'text' as const,
text: `Error: ${error instanceof Error ? error.message : 'Unknown error'}`,
},
],
isError: true,
};
}
}
);
server.tool(
'set_default_return_address',
'Set a return address as the default for your organization.',
{
returnAddressId: z.string().describe('Return address ID to set as default'),
},
async (params) => {
try {
const address = await client.post(`/return-addresses/${params.returnAddressId}/default`);
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(address, null, 2),
},
],
};
} catch (error) {
return {
content: [
{
type: 'text' as const,
text: `Error: ${error instanceof Error ? error.message : 'Unknown error'}`,
},
],
isError: true,
};
}
}
);
}