@toriihq/torii-mcp
Version:
Model Context Protocol server for Torii API
37 lines • 1.76 kB
JavaScript
import { z } from "zod";
import { makeApiRequest } from "./api.js";
// API Functions for Contracts
export async function getContracts(params) {
const queryParams = params ? `?${new URLSearchParams(params).toString()}` : '';
return makeApiRequest(`/contracts${queryParams}`);
}
// Register Contracts tools with the MCP server
export function registerContractsTools(server) {
// List Contracts Tool
server.tool("list_contracts", "Get details of all contracts, any expense or cost is in cents not dollars. Use the get_contract_fields tool to see which fields can be used", {
fields: z.string().default('id,name,idApp,owner').describe("Comma-separated list of fields to return. List of fields to return for each contract. Allowed fields: id, idApp, name, owner, status, createdBy and all fields from get_contract_fields")
}, async ({ fields }) => {
const params = {};
if (fields)
params.fields = fields;
try {
const contracts = await getContracts(params);
return {
content: [{ type: "text", text: JSON.stringify(contracts, null, 2) }],
};
}
catch (error) {
return {
content: [{ type: "text", text: error.message + ' ' + `Use the get_contract_fields tool to see if you are using correct field.` }],
};
}
});
// Get Contract Fields Tool
server.tool("get_contract_fields", "Get the list of fields that can be used to query list_contracts", {}, async () => {
const fields = await makeApiRequest("/contracts/fields");
return {
content: [{ type: "text", text: JSON.stringify(fields, null, 2) }],
};
});
}
//# sourceMappingURL=contracts.js.map