Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 208 additions & 0 deletions MCP/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
# Input API MCP Server

This MCP (Model Content Protocol) server provides access to Input API API functionality through HTTP, HTTPS, and STDIO transport modes.

## Features

- transport mode support (HTTP and STDIO)
- Dynamic configuration through HTTP headers
- Automatic tool generation from API documentation

## Building the Project

1. Ensure you have Go 1.24.6 or later installed
2. Clone the repository
3. Build the project:

```bash
go build -o mcp-server
```

## Running the Server

The server can run in three modes based on the **TRANSPORT** environment variable:

### HTTP Mode

To run in HTTP mode, set the transport environment variable to "http" or "HTTP":

```bash
export TRANSPORT="http" # or "HTTP" or "HTTPS"
export PORT="8181" # required
```

Run the server:
```bash
./mcp-server
```

#### Required Environment Variables for HTTP Mode:
- `TRANSPORT`: Set to "HTTP" **(Required)**
- `PORT`: Server port **(Required)**

#### Configuration through HTTP Headers:
In HTTP mode, API configuration is provided via HTTP headers for each request:
- `API_BASE_URL`: **(Required)** Base URL for the API
- `BEARER_TOKEN`: Bearer token for authentication
- `API_KEY`: API key for authentication
- `BASIC_AUTH`: Basic authentication credentials

Cursor mcp.json settings:

{
"mcpServers": {
"your-mcp-server-http": {
"url": "http://<host>:<port>/mcp",
"headers": {
"API_BASE_URL": "https://your-api-base-url",
"BEARER_TOKEN": "your-bearer-token"
}
}
}
}

The server will start on the configured port with the following endpoints:
- `/mcp`: HTTP endpoint for MCP communication (requires API_BASE_URL header)
- `/`: Health check endpoint

**Note**: At least one authentication header (BEARER_TOKEN, API_KEY, or BASIC_AUTH) should be provided unless the API explicitly doesn't require authentication.

### HTTPS Mode

To run in HTTPS mode, set the transport environment variable to "https" or "HTTPS":

```bash
export TRANSPORT="https" # or "HTTPS"
export PORT="8443" # required
export CERT_FILE="./certs/cert.pem" # required
export KEY_FILE="./certs/key.pem" # required
```

Run the server:
```bash
./mcp-server
```

#### Required Environment Variables for HTTPS Mode:
- `TRANSPORT`: Set to "HTTPS" **(Required)**
- `PORT`: Server port **(Required)**
- `CERT_FILE`: Path to SSL certificate file **(Required)**
- `KEY_FILE`: Path to SSL private key file **(Required)**

#### Configuration through HTTP Headers:
In HTTPS mode, API configuration is provided via HTTP headers for each request:
- `API_BASE_URL`: **(Required)** Base URL for the API
- `BEARER_TOKEN`: Bearer token for authentication
- `API_KEY`: API key for authentication
- `BASIC_AUTH`: Basic authentication credentials

Cursor mcp.json settings:

{
"mcpServers": {
"your-mcp-server-https": {
"url": "https://<host>:<port>/mcp",
"headers": {
"API_BASE_URL": "https://your-api-base-url",
"BEARER_TOKEN": "your-bearer-token"
}
}
}
}

The server will start on the configured port with the following endpoints:
- `/mcp`: HTTPS endpoint for MCP communication (requires API_BASE_URL header)
- `/`: Health check endpoint

**Note**: At least one authentication header (BEARER_TOKEN, API_KEY, or BASIC_AUTH) should be provided unless the API explicitly doesn't require authentication.

```

### STDIO Mode

To run in STDIO mode, either set the transport environment variable to "stdio" or leave it unset (default):

```bash
export TRANSPORT="stdio" # or leave unset for default
export API_BASE_URL="https://your-api-base-url"
export BEARER_TOKEN="your-bearer-token"
```

Run the server:
```bash
./mcp-server
```

#### Required Environment Variables for STDIO Mode:
- `TRANSPORT`: Set to "stdio" or leave unset (default)
- `API_BASE_URL`: Base URL for the API **(Required)**
- `BEARER_TOKEN`: Bearer token for authentication
- `API_KEY`: API key for authentication
- `BASIC_AUTH`: Basic authentication credentials

**Note**: At least one authentication environment variable (BEARER_TOKEN, API_KEY, or BASIC_AUTH) should be provided unless the API explicitly doesn't require authentication.

Cursor mcp.json settings:

{
"mcpServers": {
"your-mcp-server-stdio": {
"command": "<path-to-binary>/<mcpserver-binary-name>",
"env": {
"API_BASE_URL": "<api-base-url>",
"BEARER_TOKEN": "<token>"
}
}
}
}

## Environment Variable Case Sensitivity

The server supports both uppercase and lowercase transport environment variables:
- `TRANSPORT` (uppercase) - checked first
- `transport` (lowercase) - fallback if uppercase not set

Valid values: "http", "HTTP", "https", "HTTPS", "stdio", or unset (defaults to STDIO)

## Authentication

### HTTP Mode
Authentication is provided through HTTP headers on each request:
- `BEARER_TOKEN`: Bearer token
- `API_KEY`: API key
- `BASIC_AUTH`: Basic authentication

### STDIO Mode
Authentication is provided through environment variables:
- `BEARER_TOKEN`: Bearer token
- `API_KEY`: API key
- `BASIC_AUTH`: Basic authentication

## Health Check

When running in HTTP mode, you can check server health at the root endpoint (`/`).
Expected response: `{"status":"ok"}`

## Transport Modes Summary

### HTTP Mode (TRANSPORT=http or TRANSPORT=HTTP)
- Uses streamable HTTP server
- Configuration provided via HTTP headers for each request
- Requires API_BASE_URL header for each request
- Endpoint: `/mcp`
- Port configured via PORT environment variable (defaults to 8080)

### HTTPS Mode (TRANSPORT=https or TRANSPORT=HTTPS)
- Uses streamable HTTPS server with SSL/TLS encryption
- Configuration provided via HTTP headers for each request
- Requires API_BASE_URL header for each request
- Endpoint: `/mcp`
- Port configured via PORT environment variable (defaults to 8443)
- **Requires SSL certificate and private key files (CERT_FILE and KEY_FILE)**

### STDIO Mode (TRANSPORT=stdio or unset)
- Uses standard input/output for communication
- Configuration through environment variables only
- Requires API_BASE_URL environment variable
- Suitable for command-line usage

48 changes: 48 additions & 0 deletions MCP/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package config

import (
"fmt"
"os"
)

type APIConfig struct {
BaseURL string
BearerToken string // For OAuth2/Bearer authentication
APIKey string // For API key authentication
BasicAuth string // For basic authentication
Port string // For server port configuration
}

func LoadAPIConfig() (*APIConfig, error) {
// Check port environment variable (both uppercase and lowercase)
port := os.Getenv("PORT")
if port == "" {
port = os.Getenv("port")
}

baseURL := os.Getenv("API_BASE_URL")

// Check transport environment variable (both uppercase and lowercase)
transport := os.Getenv("TRANSPORT")
if transport == "" {
transport = os.Getenv("transport")
}

// For STDIO mode (transport is not "http"/"HTTP"/"https"/"HTTPS"), API_BASE_URL is required from environment
if transport != "http" && transport != "HTTP" && transport != "https" && transport != "HTTPS" && baseURL == "" {
return nil, fmt.Errorf("API_BASE_URL environment variable not set")
}

// For HTTP/HTTPS mode (transport is "http"/"HTTP"/"https"/"HTTPS"), API_BASE_URL comes from headers
// so we don't require it from environment variables

return &APIConfig{
BaseURL: baseURL,
BearerToken: os.Getenv("BEARER_TOKEN"),
APIKey: os.Getenv("API_KEY"),
BasicAuth: os.Getenv("BASIC_AUTH"),
Port: port,
}, nil
}


17 changes: 17 additions & 0 deletions MCP/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module github.com/input-api/mcp-server

go 1.24.4

require github.com/mark3labs/mcp-go v0.38.0

require (
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/invopop/jsonschema v0.13.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/spf13/cast v1.7.1 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
39 changes: 39 additions & 0 deletions MCP/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcIi21E=
github.com/invopop/jsonschema v0.13.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mark3labs/mcp-go v0.38.0 h1:E5tmJiIXkhwlV0pLAwAT0O5ZjUZSISE/2Jxg+6vpq4I=
github.com/mark3labs/mcp-go v0.38.0/go.mod h1:T7tUa2jO6MavG+3P25Oy/jR7iCeJPHImCZHRymCn39g=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading