Labsco
gyuco logo

MCP REST Server

from gyuco

A server for interacting with REST APIs, featuring authentication and Swagger documentation support.

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedAccount requiredNeeds API keys

MCP REST Server

A Model Context Protocol (MCP) server that provides REST API client functionality with authentication support and Swagger documentation integration.

Features

  • Multiple Authentication Methods: Support for both token-based and login-based authentication
  • Swagger Integration: Automatic endpoint discovery and documentation from OpenAPI/Swagger specs
  • Automatic Token Management: Handles token refresh and re-authentication
  • Comprehensive HTTP Methods: Support for GET, POST, PUT, DELETE, and PATCH requests
  • Error Handling: Robust error handling with retry logic
  • MCP Compatible: Fully compatible with the Model Context Protocol

Development

npm run dev

Available Tools

1. configure_rest_client

Configure the REST client with authentication and API details.

Parameters:

  • baseUrl (required): Base URL for the REST API
  • auth (required): Authentication configuration (token or login)
  • swaggerUrl (optional): URL to Swagger/OpenAPI documentation
  • timeout (optional): Request timeout in milliseconds (default: 30000)
  • retries (optional): Number of retries for failed requests (default: 3)

2. http_request

Make HTTP requests to the configured API.

Parameters:

  • method (required): HTTP method (GET, POST, PUT, DELETE, PATCH)
  • path (required): API endpoint path
  • params (optional): Query parameters or request body parameters
  • body (optional): Request body for POST, PUT, PATCH requests
  • headers (optional): Additional headers

3. get_swagger_documentation

Get the complete list of available endpoints from Swagger documentation.

4. search_endpoints

Search for endpoints in the Swagger documentation.

Parameters:

  • query (required): Search query to find matching endpoints

5. get_endpoint_info

Get detailed information about a specific endpoint.

Parameters:

  • path (required): Endpoint path
  • method (required): HTTP method

6. check_authentication

Check if the client is currently authenticated.

7. logout

Logout and clear authentication state.

Authentication Flow

Token Authentication

  1. Token is stored and used immediately
  2. Added to requests as Authorization: Bearer <token>
  3. If 401 received, no automatic retry (token assumed invalid)

Login Authentication

  1. Makes login request to specified endpoint
  2. Extracts token from response using tokenField
  3. Stores token in memory
  4. Adds token to subsequent requests
  5. If 401 received, automatically re-authenticates and retries

Error Handling

  • Network errors: Automatic retry with exponential backoff
  • Authentication errors: Automatic re-authentication for login-based auth
  • Validation errors: Clear error messages with details
  • API errors: HTTP status and error message forwarding

Development

Project Structure

src/
β”œβ”€β”€ types.ts          # TypeScript type definitions
β”œβ”€β”€ auth.ts           # Authentication manager
β”œβ”€β”€ swagger.ts        # Swagger documentation parser
β”œβ”€β”€ rest-client.ts    # REST client implementation
└── index.ts          # MCP server implementation

Building

npm run build

Running

npm start