Skip to content

Commit 4d0c9d4

Browse files
feat: Updated MCP server with latest generated code
1 parent 179a966 commit 4d0c9d4

29 files changed

+2797
-0
lines changed

MCP/go/README.md

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
# Api2Pdf - PDF Generation, Powered by AWS Lambda MCP Server
2+
3+
This MCP (Model Content Protocol) server provides access to Api2Pdf - PDF Generation, Powered by AWS Lambda API functionality through HTTP, HTTPS, and STDIO transport modes.
4+
5+
## Features
6+
7+
- transport mode support (HTTP and STDIO)
8+
- Dynamic configuration through HTTP headers
9+
- Automatic tool generation from API documentation
10+
11+
## Building the Project
12+
13+
1. Ensure you have Go 1.24.6 or later installed
14+
2. Clone the repository
15+
3. Build the project:
16+
17+
```bash
18+
go build -o mcp-server
19+
```
20+
21+
## Running the Server
22+
23+
The server can run in three modes based on the **TRANSPORT** environment variable:
24+
25+
### HTTP Mode
26+
27+
To run in HTTP mode, set the transport environment variable to "http" or "HTTP":
28+
29+
```bash
30+
export TRANSPORT="http" # or "HTTP" or "HTTPS"
31+
export PORT="8181" # required
32+
```
33+
34+
Run the server:
35+
```bash
36+
./mcp-server
37+
```
38+
39+
#### Required Environment Variables for HTTP Mode:
40+
- `TRANSPORT`: Set to "HTTP" **(Required)**
41+
- `PORT`: Server port **(Required)**
42+
43+
#### Configuration through HTTP Headers:
44+
In HTTP mode, API configuration is provided via HTTP headers for each request:
45+
- `API_BASE_URL`: **(Required)** Base URL for the API
46+
- `BEARER_TOKEN`: Bearer token for authentication
47+
- `API_KEY`: API key for authentication
48+
- `BASIC_AUTH`: Basic authentication credentials
49+
50+
Cursor mcp.json settings:
51+
52+
{
53+
"mcpServers": {
54+
"your-mcp-server-http": {
55+
"url": "http://<host>:<port>/mcp",
56+
"headers": {
57+
"API_BASE_URL": "https://your-api-base-url",
58+
"BEARER_TOKEN": "your-bearer-token"
59+
}
60+
}
61+
}
62+
}
63+
64+
The server will start on the configured port with the following endpoints:
65+
- `/mcp`: HTTP endpoint for MCP communication (requires API_BASE_URL header)
66+
- `/`: Health check endpoint
67+
68+
**Note**: At least one authentication header (BEARER_TOKEN, API_KEY, or BASIC_AUTH) should be provided unless the API explicitly doesn't require authentication.
69+
70+
### HTTPS Mode
71+
72+
To run in HTTPS mode, set the transport environment variable to "https" or "HTTPS":
73+
74+
```bash
75+
export TRANSPORT="https" # or "HTTPS"
76+
export PORT="8443" # required
77+
export CERT_FILE="./certs/cert.pem" # required
78+
export KEY_FILE="./certs/key.pem" # required
79+
```
80+
81+
Run the server:
82+
```bash
83+
./mcp-server
84+
```
85+
86+
#### Required Environment Variables for HTTPS Mode:
87+
- `TRANSPORT`: Set to "HTTPS" **(Required)**
88+
- `PORT`: Server port **(Required)**
89+
- `CERT_FILE`: Path to SSL certificate file **(Required)**
90+
- `KEY_FILE`: Path to SSL private key file **(Required)**
91+
92+
#### Configuration through HTTP Headers:
93+
In HTTPS mode, API configuration is provided via HTTP headers for each request:
94+
- `API_BASE_URL`: **(Required)** Base URL for the API
95+
- `BEARER_TOKEN`: Bearer token for authentication
96+
- `API_KEY`: API key for authentication
97+
- `BASIC_AUTH`: Basic authentication credentials
98+
99+
Cursor mcp.json settings:
100+
101+
{
102+
"mcpServers": {
103+
"your-mcp-server-https": {
104+
"url": "https://<host>:<port>/mcp",
105+
"headers": {
106+
"API_BASE_URL": "https://your-api-base-url",
107+
"BEARER_TOKEN": "your-bearer-token"
108+
}
109+
}
110+
}
111+
}
112+
113+
The server will start on the configured port with the following endpoints:
114+
- `/mcp`: HTTPS endpoint for MCP communication (requires API_BASE_URL header)
115+
- `/`: Health check endpoint
116+
117+
**Note**: At least one authentication header (BEARER_TOKEN, API_KEY, or BASIC_AUTH) should be provided unless the API explicitly doesn't require authentication.
118+
119+
```
120+
121+
### STDIO Mode
122+
123+
To run in STDIO mode, either set the transport environment variable to "stdio" or leave it unset (default):
124+
125+
```bash
126+
export TRANSPORT="stdio" # or leave unset for default
127+
export API_BASE_URL="https://your-api-base-url"
128+
export BEARER_TOKEN="your-bearer-token"
129+
```
130+
131+
Run the server:
132+
```bash
133+
./mcp-server
134+
```
135+
136+
#### Required Environment Variables for STDIO Mode:
137+
- `TRANSPORT`: Set to "stdio" or leave unset (default)
138+
- `API_BASE_URL`: Base URL for the API **(Required)**
139+
- `BEARER_TOKEN`: Bearer token for authentication
140+
- `API_KEY`: API key for authentication
141+
- `BASIC_AUTH`: Basic authentication credentials
142+
143+
**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.
144+
145+
Cursor mcp.json settings:
146+
147+
{
148+
"mcpServers": {
149+
"your-mcp-server-stdio": {
150+
"command": "<path-to-binary>/<mcpserver-binary-name>",
151+
"env": {
152+
"API_BASE_URL": "<api-base-url>",
153+
"BEARER_TOKEN": "<token>"
154+
}
155+
}
156+
}
157+
}
158+
159+
## Environment Variable Case Sensitivity
160+
161+
The server supports both uppercase and lowercase transport environment variables:
162+
- `TRANSPORT` (uppercase) - checked first
163+
- `transport` (lowercase) - fallback if uppercase not set
164+
165+
Valid values: "http", "HTTP", "https", "HTTPS", "stdio", or unset (defaults to STDIO)
166+
167+
## Authentication
168+
169+
### HTTP Mode
170+
Authentication is provided through HTTP headers on each request:
171+
- `BEARER_TOKEN`: Bearer token
172+
- `API_KEY`: API key
173+
- `BASIC_AUTH`: Basic authentication
174+
175+
### STDIO Mode
176+
Authentication is provided through environment variables:
177+
- `BEARER_TOKEN`: Bearer token
178+
- `API_KEY`: API key
179+
- `BASIC_AUTH`: Basic authentication
180+
181+
## Health Check
182+
183+
When running in HTTP mode, you can check server health at the root endpoint (`/`).
184+
Expected response: `{"status":"ok"}`
185+
186+
## Transport Modes Summary
187+
188+
### HTTP Mode (TRANSPORT=http or TRANSPORT=HTTP)
189+
- Uses streamable HTTP server
190+
- Configuration provided via HTTP headers for each request
191+
- Requires API_BASE_URL header for each request
192+
- Endpoint: `/mcp`
193+
- Port configured via PORT environment variable (defaults to 8080)
194+
195+
### HTTPS Mode (TRANSPORT=https or TRANSPORT=HTTPS)
196+
- Uses streamable HTTPS server with SSL/TLS encryption
197+
- Configuration provided via HTTP headers for each request
198+
- Requires API_BASE_URL header for each request
199+
- Endpoint: `/mcp`
200+
- Port configured via PORT environment variable (defaults to 8443)
201+
- **Requires SSL certificate and private key files (CERT_FILE and KEY_FILE)**
202+
203+
### STDIO Mode (TRANSPORT=stdio or unset)
204+
- Uses standard input/output for communication
205+
- Configuration through environment variables only
206+
- Requires API_BASE_URL environment variable
207+
- Suitable for command-line usage
208+

MCP/go/config/config.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package config
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
type APIConfig struct {
9+
BaseURL string
10+
BearerToken string // For OAuth2/Bearer authentication
11+
APIKey string // For API key authentication
12+
BasicAuth string // For basic authentication
13+
Port string // For server port configuration
14+
}
15+
16+
func LoadAPIConfig() (*APIConfig, error) {
17+
// Check port environment variable (both uppercase and lowercase)
18+
port := os.Getenv("PORT")
19+
if port == "" {
20+
port = os.Getenv("port")
21+
}
22+
23+
baseURL := os.Getenv("API_BASE_URL")
24+
25+
// Check transport environment variable (both uppercase and lowercase)
26+
transport := os.Getenv("TRANSPORT")
27+
if transport == "" {
28+
transport = os.Getenv("transport")
29+
}
30+
31+
// For STDIO mode (transport is not "http"/"HTTP"/"https"/"HTTPS"), API_BASE_URL is required from environment
32+
if transport != "http" && transport != "HTTP" && transport != "https" && transport != "HTTPS" && baseURL == "" {
33+
return nil, fmt.Errorf("API_BASE_URL environment variable not set")
34+
}
35+
36+
// For HTTP/HTTPS mode (transport is "http"/"HTTP"/"https"/"HTTPS"), API_BASE_URL comes from headers
37+
// so we don't require it from environment variables
38+
39+
return &APIConfig{
40+
BaseURL: baseURL,
41+
BearerToken: os.Getenv("BEARER_TOKEN"),
42+
APIKey: os.Getenv("API_KEY"),
43+
BasicAuth: os.Getenv("BASIC_AUTH"),
44+
Port: port,
45+
}, nil
46+
}
47+
48+

MCP/go/go.mod

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module github.com/api2pdf-pdf-generation-powered-by-aws-lambda/mcp-server
2+
3+
go 1.24.4
4+
5+
require github.com/mark3labs/mcp-go v0.38.0
6+
7+
require (
8+
github.com/bahlo/generic-list-go v0.2.0 // indirect
9+
github.com/buger/jsonparser v1.1.1 // indirect
10+
github.com/google/uuid v1.6.0 // indirect
11+
github.com/invopop/jsonschema v0.13.0 // indirect
12+
github.com/mailru/easyjson v0.7.7 // indirect
13+
github.com/spf13/cast v1.7.1 // indirect
14+
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
15+
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
16+
gopkg.in/yaml.v3 v3.0.1 // indirect
17+
)

MCP/go/go.sum

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

0 commit comments

Comments
 (0)