actual-mcp
Version:
Actual Budget MCP server exposing API functionality
66 lines • 2.59 kB
JavaScript
// ----------------------------
// TOOLS
// ----------------------------
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
import { initActualApi, shutdownActualApi } from '../actual-api.js';
import { schema as getTransactionsSchema, handler as getTransactionsHandler } from './get-transactions/index.js';
import { schema as spendingByCategorySchema, handler as spendingByCategoryHandler, } from './spending-by-category/index.js';
import { schema as monthlySummarySchema, handler as monthlySummaryHandler } from './monthly-summary/index.js';
import { schema as balanceHistorySchema, handler as balanceHistoryHandler } from './balance-history/index.js';
import { error, errorFromCatch } from '../utils/response.js';
import { schema as getAccountsSchema, handler as getAccountsHandler } from './get-accounts/index.js';
export const setupTools = (server) => {
/**
* Handler for listing available tools
*/
server.setRequestHandler(ListToolsRequestSchema, toolsSchema);
/**
* Handler for calling tools
*/
server.setRequestHandler(CallToolRequestSchema, async (request) => {
try {
await initActualApi();
const { name, arguments: args } = request.params;
// Execute the requested tool
switch (name) {
case 'get-transactions': {
// TODO: Validate against schema
return getTransactionsHandler(args);
}
case 'spending-by-category': {
return spendingByCategoryHandler(args);
}
case 'monthly-summary': {
return monthlySummaryHandler(args);
}
case 'balance-history': {
return balanceHistoryHandler(args);
}
case 'get-accounts': {
return getAccountsHandler();
}
default:
return error(`Unknown tool ${name}`);
}
}
catch (error) {
console.error(`Error executing tool ${request.params.name}:`, error);
return errorFromCatch(error);
}
finally {
await shutdownActualApi();
}
});
};
function toolsSchema() {
return {
tools: [
getTransactionsSchema,
spendingByCategorySchema,
monthlySummarySchema,
balanceHistorySchema,
getAccountsSchema,
],
};
}
//# sourceMappingURL=index.js.map