Skip to main content
Glama
martin-1103
by martin-1103

create_endpoint

Create new API endpoints by defining HTTP methods, URLs, headers, and documentation to organize and manage your API catalog within designated folders.

Instructions

Create a new endpoint in a folder

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesEndpoint name (required)
methodYesHTTP method (required)
urlYesEndpoint URL (required)
folder_idYesFolder ID to create endpoint in (required)
descriptionNoEndpoint description (optional)
headersNoRequest headers as key-value pairs
bodyNoRequest body (JSON string)
purposeNoBusiness purpose - what this endpoint does (optional)
request_paramsNoParameter documentation: {param_name: "description"}
response_schemaNoResponse field documentation: {field_name: "description"}
header_docsNoHeader documentation: {header_name: "description"}

Implementation Reference

  • Main handler function that executes the create_endpoint tool: extracts args, validates data (with folder suggestions), formats request, makes POST API call to backend, handles timeouts/errors with user-friendly messages, returns formatted response.
    export async function handleCreateEndpoint(args: Record<string, any>): Promise<McpToolResponse> {
      try {
        const { configManager, backendClient } = await getEndpointDependencies();
    
        const name = args.name as string;
        const method = args.method as HttpMethod;
        const url = args.url as string;
        const folderId = args.folder_id as string;
        const description = args.description as string | undefined;
        const purpose = args.purpose as string | undefined;
        const headers = args.headers as Record<string, string> | undefined;
        const body = args.body as string | undefined;
        const requestParams = args.request_params as Record<string, string> | undefined;
        const responseSchema = args.response_schema as Record<string, string> | undefined;
        const headerDocs = args.header_docs as Record<string, string> | undefined;
    
        // Validate input
        const validationErrors = validateEndpointData({ name, method, url, folder_id: folderId });
        if (validationErrors.length > 0) {
          // Check if folder_id is the only error and provide helpful suggestions
          if (validationErrors.length === 1 && validationErrors[0] === 'Folder ID is required') {
            const foldersMessage = await getFolderSuggestions(configManager, backendClient);
            throw new Error(`Folder ID is required\n\n${foldersMessage}`);
          }
          throw new Error(validationErrors.join('\n'));
        }
    
        // Create endpoint
        const apiEndpoints = getApiEndpoints();
        const endpoint = apiEndpoints.getEndpoint('endpointCreate', { id: folderId });
    
        const requestBody = JSON.stringify({
          name: name.trim(),
          method,
          url: url.trim(),
          description: description?.trim() || null,
          purpose: purpose?.trim() || null,
          headers: formatHeaders(headers || {}),
          body: formatBody(body) || null,
          request_params: requestParams || null,
          response_schema: responseSchema || null,
          header_docs: headerDocs || null
        });
    
        console.error(`[EndpointTools] Creating endpoint at: ${endpoint}`);
        console.error(`[EndpointTools] Folder ID: ${folderId}`);
        console.error(`[EndpointTools] Base URL: ${backendClient.getBaseUrl()}`);
        console.error(`[EndpointTools] Token: ${backendClient.getToken().substring(0, 20)}...`);
        console.error(`[EndpointTools] Request Body: ${requestBody}`);
    
        // Create AbortController for timeout
        const controller = new AbortController();
        const timeoutId = setTimeout(() => controller.abort(), 30000); // 30 second timeout
    
        let apiResponse;
        try {
          const result = await fetch(`${backendClient.getBaseUrl()}${endpoint}`, {
            method: 'POST',
            headers: {
              'Authorization': `Bearer ${backendClient.getToken()}`,
              'Content-Type': 'application/json'
            },
            body: requestBody,
            signal: controller.signal
          });
    
          clearTimeout(timeoutId);
    
          if (!result.ok) {
            throw new Error(`HTTP ${result.status}: ${result.statusText}`);
          }
    
          const data = await result.json() as EndpointCreateResponse;
    
          apiResponse = {
            success: data.success,
            data: data.data,
            message: data.message,
            status: result.status
          };
        } catch (networkError) {
          clearTimeout(timeoutId);
          throw networkError;
        }
    
        if (!apiResponse.success) {
          let errorMessage = `Failed to create endpoint: ${apiResponse.message || 'Unknown error'}`;
    
          // Provide helpful error messages for common scenarios
          if (apiResponse.status === 404) {
            errorMessage = `Folder with ID '${folderId}' not found. Cannot create endpoint.\n\n`;
            errorMessage += `Please check:\n`;
            errorMessage += `• Folder ID '${folderId}' is correct\n`;
            errorMessage += `• You have access to this folder\n`;
            errorMessage += `• Folder exists in the project\n\n`;
            errorMessage += `Use get_folders to see available folders, or create a new folder first.`;
          } else if (apiResponse.status === 403) {
            errorMessage = `Access denied. You don't have permission to create endpoints in this folder.\n\n`;
            errorMessage += `Please check:\n`;
            errorMessage += `• You are a member of the project\n`;
            errorMessage += `• Your account has write permissions for this folder`;
          } else if (apiResponse.status === 400) {
            errorMessage = `Invalid endpoint data. Please check:\n`;
            errorMessage += `• Endpoint name is not empty\n`;
            errorMessage += `• URL is valid and properly formatted\n`;
            errorMessage += `• HTTP method is valid (GET, POST, PUT, DELETE, PATCH)\n`;
            errorMessage += `• Headers are valid JSON if provided`;
          }
    
          throw new Error(errorMessage);
        }
    
        if (apiResponse.success && apiResponse.data) {
          const createText = formatEndpointCreateText(apiResponse.data);
    
          return {
            content: [
              {
                type: 'text',
                text: createText
              }
            ]
          };
        } else {
          return {
            content: [
              {
                type: 'text',
                text: `❌ Failed to create endpoint: ${apiResponse.message || 'Unknown error'}`
              }
            ],
            isError: true
          };
        }
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `❌ Endpoint creation error: ${error instanceof Error ? error.message : 'Unknown error'}`
            }
          ],
          isError: true
        };
      }
    }
  • Defines the tool schema: name 'create_endpoint', description, and detailed inputSchema with required/optional properties for endpoint creation.
    // Tool: create_endpoint
    export const createEndpointTool: McpTool = {
      name: 'create_endpoint',
      description: 'Create a new endpoint in a folder',
      inputSchema: {
        type: 'object',
        properties: {
          name: {
            type: 'string',
            description: 'Endpoint name (required)'
          },
          method: {
            type: 'string',
            description: 'HTTP method (required)',
            enum: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS']
          },
          url: {
            type: 'string',
            description: 'Endpoint URL (required)'
          },
          folder_id: {
            type: 'string',
            description: 'Folder ID to create endpoint in (required)'
          },
          description: {
            type: 'string',
            description: 'Endpoint description (optional)'
          },
          headers: {
            type: 'object',
            description: 'Request headers as key-value pairs',
            additionalProperties: {
              type: 'string',
              description: 'Header value'
            }
          },
          body: {
            type: 'string',
            description: 'Request body (JSON string)'
          },
          purpose: {
            type: 'string',
            description: 'Business purpose - what this endpoint does (optional)'
          },
          request_params: {
            type: 'object',
            description: 'Parameter documentation: {param_name: "description"}',
            additionalProperties: {
              type: 'string',
              description: 'Parameter description'
            }
          },
          response_schema: {
            type: 'object',
            description: 'Response field documentation: {field_name: "description"}',
            additionalProperties: {
              type: 'string',
              description: 'Response field description'
            }
          },
          header_docs: {
            type: 'object',
            description: 'Header documentation: {header_name: "description"}',
            additionalProperties: {
              type: 'string',
              description: 'Header description'
            }
          }
        },
        required: ['name', 'method', 'url', 'folder_id']
      }
    };
  • Registers 'create_endpoint' by mapping createEndpointTool.name to handleCreateEndpoint in the handlers object.
    export function createEndpointToolHandlers(): Record<string, EndpointToolHandler> {
      return {
        [listEndpointsTool.name]: handleListEndpoints,
        [getEndpointDetailsTool.name]: handleGetEndpointDetails,
        [createEndpointTool.name]: handleCreateEndpoint,
        [updateEndpointTool.name]: handleUpdateEndpoint,
        [deleteEndpointTool.name]: handleDeleteEndpoint
      };
    }
  • Top-level registration that includes endpoint handlers (including create_endpoint) in the complete tool handlers map.
    export function createAllToolHandlers(): Record<string, (args: any) => Promise<McpToolResponse>> {
      return {
        ...createCoreToolHandlers(),
        ...createAuthToolHandlers(),
        ...createEnvironmentToolHandlers(),
        ...createFolderToolHandlers(),
        ...createEndpointToolHandlers(),
        ...createTestingToolHandlers(),
        ...createFlowToolHandlers()
      };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden for behavioral disclosure. 'Create a new endpoint' implies a write/mutation operation, but the description doesn't mention permissions required, whether creation is idempotent, what happens on duplicate names, or what the response contains (success/failure indicators, created endpoint ID). For a mutation tool with 11 parameters and no annotation coverage, this is a significant gap in behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that states the core functionality without unnecessary words. It's appropriately sized and front-loaded with the essential information. Every word earns its place, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (11 parameters, mutation operation, no annotations, no output schema), the description is insufficiently complete. It doesn't explain what an 'endpoint' represents in this system, what happens after creation, error conditions, or relationship to other tools. For a creation tool with many parameters and no structured output documentation, the description should provide more contextual guidance about the operation's scope and outcomes.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 11 parameters thoroughly with descriptions, enums, and required/optional status. The description adds no parameter-specific information beyond what's in the schema. According to scoring rules, when schema coverage is high (>80%), the baseline is 3 even with no param info in the description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Create') and resource ('new endpoint in a folder'), making the purpose immediately understandable. However, it doesn't differentiate this tool from similar creation tools like create_environment or create_flow, which would require mentioning what specifically makes an endpoint distinct from those other resources.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With sibling tools like create_folder, update_endpoint, and list_endpoints available, there's no indication of prerequisites (e.g., folder must exist), sequencing (create folder first), or when to choose create_endpoint over other endpoint-related tools. The description is purely functional without contextual guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/martin-1103/mcp2'

If you have feedback or need assistance with the MCP directory API, please join our Discord server