UNPKG

@toriihq/torii-mcp

Version:

Model Context Protocol server for Torii API

82 lines 3.99 kB
import { z } from "zod"; import { makeApiRequest } from "./api.js"; // API Functions for Apps export async function getApps(params, headers) { const queryParams = params ? `?${new URLSearchParams(params).toString()}` : ''; return makeApiRequest(`/apps${queryParams}`, 'GET', undefined, headers); } export async function getAppById(idApp, params, headers) { const queryParams = params ? `?${new URLSearchParams(params).toString()}` : ''; return makeApiRequest(`/apps/${idApp}${queryParams}`, 'GET', undefined, headers); } export async function getAppFields() { return makeApiRequest('/apps/fields'); } // Register Apps tools with the MCP server export function registerAppsTools(server) { // List Apps Tool server.tool("list_apps", ` Use this to list more than one app and get its details, any expense or cost is in cents not dollars. You can search for it using the q parameter. Use the get_app_fields tool to see which fields can be used. The app supports fields such as creationTime, primaryOwner, state, name, id, description, url, category, tags. `.trim(), { q: z.string().optional().describe("Search for apps by name or other fields"), fields: z.string().default('id,name,state,primaryOwner').describe("Comma-separated list of fields to return for each application"), primaryOwner: z.number().optional().describe("idUser of the primary owner"), state: z.string().optional().describe("App states such as: discovered, sandctioned, closed"), sort: z.string().optional().describe("Sort order as fieldName:asc or fieldName:desc"), size: z.number().min(1).max(100).default(10).optional().describe("Max results to return (default: 10) it is better to search/sort instead of getting a lot of results"), cursor: z.string().optional().describe("Pagination cursor taken from the previous response nextCursor") }, async (args) => { const queryParams = {}; // Add standard query parameters if (args.fields) queryParams.fields = args.fields; if (args.sort) queryParams.sort = args.sort; if (args.size) queryParams.size = args.size.toString(); if (args.cursor) queryParams.cursor = args.cursor; // Add any additional filter parameters Object.entries(args).forEach(([key, value]) => { if (!['fields', 'sort', 'size', 'cursor'].includes(key) && value !== undefined) { queryParams[key] = value.toString(); } }); try { const apps = await getApps(queryParams, { 'x-api-version': '1.1' }); return { content: [{ type: "text", text: JSON.stringify(apps, null, 2) }], }; } catch (error) { return { content: [{ type: "text", text: error.message + ' ' + `Use the get_app_fields tool to see if you are using correct field.` }], }; } }); // Get App Tool server.tool("get_app", "Get details of a specific app by its ID, any expense or cost is in cents not dollars", { id: z.number().describe("Unique app identifier"), fields: z.string().optional().describe("Comma-separated list of fields to return") }, async ({ id, fields }) => { const params = {}; if (fields) params.fields = fields; const headers = { 'x-api-version': '1.1' }; const app = await getAppById(id, params, headers); return { content: [{ type: "text", text: JSON.stringify(app, null, 2) }], }; }); // Get App Fields Tool server.tool("get_app_fields", "Get the list of fields that can be used to query list_apps", async () => { const fields = await getAppFields(); return { content: [{ type: "text", text: JSON.stringify(fields, null, 2) }], }; }); } //# sourceMappingURL=apps.js.map