@gabrielmaialva33/mcp-filesystem
Version:
MCP server for secure filesystem access
53 lines • 2.08 kB
JavaScript
import { z } from 'zod';
import { handleBashExecute } from '../../bash/tools/index.js';
import { logger } from '../../logger/index.js';
export const CurlRequestArgsSchema = z.object({
url: z.string().describe('Full URL to send the request to'),
method: z
.enum(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'])
.default('GET')
.describe('HTTP method'),
headers: z
.record(z.string(), z.string())
.optional()
.default({})
.describe('HTTP headers to include in the request'),
data: z.string().optional().describe('Data to send in the request body'),
timeout: z.number().positive().optional().default(30).describe('Request timeout in seconds'),
followRedirects: z.boolean().optional().default(true).describe('Whether to follow redirects'),
insecure: z
.boolean()
.optional()
.default(false)
.describe('Whether to skip SSL certificate verification (use with caution)'),
});
export async function handleCurlRequest(args, config) {
try {
const { url, method, headers, data, timeout, followRedirects, insecure } = args;
let command = `curl -X ${method} `;
Object.entries(headers).forEach(([key, value]) => {
command += `-H "${key}: ${value}" `;
});
if (data) {
command += `-d '${data}' `;
}
command += `-s `;
command += `--connect-timeout ${timeout} `;
if (followRedirects) {
command += `-L `;
}
if (insecure) {
command += `-k `;
}
command += `"${url}"`;
const logCommand = command.replace(/-H "Authorization: [^"]*"/, '-H "Authorization: [REDACTED]"');
await logger.debug(`Executing curl request: ${logCommand}`);
const result = await handleBashExecute({ command, timeout: timeout * 1000 }, config);
return result;
}
catch (error) {
await logger.error('Error executing curl request', { error });
throw error;
}
}
//# sourceMappingURL=index.js.map