Skip to content

Commit 8c6100f

Browse files
committed
feat: add config documentation and improve URL resolution examples
- Add config.md resource documenting all configuration options - Update tool description to show actual URL resolution - Simplify instructions to reference config resource - Remove environment variable references from user-facing messages
1 parent dfd8e7e commit 8c6100f

File tree

4 files changed

+139
-23
lines changed

4 files changed

+139
-23
lines changed

CLINE-CUSTOM-INSTRUCTIONS.md

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,21 @@ The `test_request` tool enables testing, debugging, and interacting with REST AP
1919
- Handles authentication (Basic, Bearer, API Key)
2020
- Normalizes endpoints automatically
2121
- Provides detailed response information
22-
- Configurable SSL verification
23-
24-
## Getting Started
25-
26-
1. Check available examples:
27-
```typescript
28-
<access_mcp_resource>
29-
<server_name>rest-api</server_name>
30-
<uri>rest-api://examples</uri>
31-
</access_mcp_resource>
32-
```
33-
34-
2. Review response format:
35-
```typescript
36-
<access_mcp_resource>
37-
<server_name>rest-api</server_name>
38-
<uri>rest-api://response-format</uri>
39-
</access_mcp_resource>
40-
```
22+
- Configurable SSL verification and response limits
23+
24+
## Resources
25+
26+
The following resources provide detailed documentation:
27+
28+
- examples: Usage examples and common patterns
29+
- response-format: Response structure and fields
30+
- config: Configuration options and setup guide
31+
32+
Access these resources to understand usage, response formats, and configuration options.
4133

4234
## Important Notes
4335

4436
- Review API implementation for expected behavior
4537
- Handle sensitive data appropriately
4638
- Consider rate limits and API constraints
39+
- Restart server after configuration changes

src/index.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ const isValidEndpointArgs = (args: any): args is EndpointArgs => {
7272
if (!['GET', 'POST', 'PUT', 'DELETE'].includes(args.method)) return false;
7373
if (typeof args.endpoint !== 'string') return false;
7474
if (args.headers !== undefined && typeof args.headers !== 'object') return false;
75+
76+
// Check if endpoint contains a full URL
77+
const urlPattern = /^(https?:\/\/|www\.)/i;
78+
if (urlPattern.test(args.endpoint)) {
79+
throw new McpError(
80+
ErrorCode.InvalidParams,
81+
`Invalid endpoint format. Do not include full URLs. Instead of "${args.endpoint}", use just the path (e.g. "/api/users"). ` +
82+
`Your path will be resolved to: ${process.env.REST_BASE_URL}${args.endpoint.replace(/^\/+|\/+$/g, '')}. ` +
83+
`To test a different base URL, update the REST_BASE_URL environment variable.`
84+
);
85+
}
86+
7587
return true;
7688
};
7789

@@ -134,6 +146,12 @@ class RestTester {
134146
name: 'Response Format Documentation',
135147
description: 'Documentation of the response format and structure',
136148
mimeType: 'text/markdown'
149+
},
150+
{
151+
uri: `${SERVER_NAME}://config`,
152+
name: 'Configuration Documentation',
153+
description: 'Documentation of all configuration options and how to use them',
154+
mimeType: 'text/markdown'
137155
}
138156
]
139157
}));
@@ -188,7 +206,7 @@ class RestTester {
188206
189207
Base URL: ${process.env.REST_BASE_URL}
190208
191-
SSL Verification: ${REST_ENABLE_SSL_VERIFY ? 'Enabled (default)' : 'Disabled (set REST_ENABLE_SSL_VERIFY=false to disable for self-signed certificates)'}
209+
SSL Verification: ${REST_ENABLE_SSL_VERIFY ? 'Enabled' : 'Disabled'} (see config resource for SSL settings)
192210
193211
Authentication: ${
194212
hasBasicAuth() ?
@@ -204,7 +222,7 @@ The tool automatically:
204222
- Normalizes endpoints (adds leading slash, removes trailing slashes)
205223
- Handles authentication header injection
206224
- Accepts any HTTP status code as valid
207-
- Limits response size to ${RESPONSE_SIZE_LIMIT} bytes (configurable via REST_RESPONSE_SIZE_LIMIT)
225+
- Limits response size to ${RESPONSE_SIZE_LIMIT} bytes (see config resource for size limit settings)
208226
- Returns detailed response information including:
209227
* Full URL called
210228
* Status code and text
@@ -218,6 +236,8 @@ Error Handling:
218236
- Network errors are caught and returned with descriptive messages
219237
- Invalid status codes are still returned with full response details
220238
- Authentication errors include the attempted auth method
239+
240+
See the config resource for all configuration options.
221241
`,
222242
inputSchema: {
223243
type: 'object',
@@ -229,7 +249,7 @@ Error Handling:
229249
},
230250
endpoint: {
231251
type: 'string',
232-
description: 'Endpoint path (e.g. "/users"). Will be appended to base URL.',
252+
description: `Endpoint path (e.g. "/users"). Do not include full URLs - only the path. Example: "/api/users" will resolve to "${process.env.REST_BASE_URL}/api/users"`,
233253
},
234254
body: {
235255
type: 'object',

src/resources/config.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# REST API Tester Configuration
2+
3+
This document describes all available configuration options for the REST API testing tool.
4+
5+
## Core Configuration
6+
7+
### REST_BASE_URL (Required)
8+
- Description: The base URL that all endpoint paths will be resolved against
9+
- Example: `http://localhost:3000` or `https://api.example.com`
10+
- Usage: All endpoint paths will be appended to this URL. For example, if REST_BASE_URL is `http://localhost:3000` and you use the endpoint `/api/users`, the full URL will be `http://localhost:3000/api/users`
11+
12+
### REST_RESPONSE_SIZE_LIMIT (Optional)
13+
- Description: Maximum size in bytes for response data
14+
- Default: 10000 (10KB)
15+
- Example: `50000` for 50KB limit
16+
- Usage: Helps prevent memory issues with large responses. If a response exceeds this size, it will be truncated and a warning message will be included
17+
18+
### REST_ENABLE_SSL_VERIFY (Optional)
19+
- Description: Controls SSL certificate verification
20+
- Default: `true`
21+
- Values: Set to `false` to disable SSL verification for self-signed certificates
22+
- Usage: Disable when testing APIs with self-signed certificates in development environments
23+
24+
## Authentication Configuration
25+
26+
The tool supports three authentication methods. Configure one based on your API's requirements.
27+
28+
### Basic Authentication
29+
- REST_BASIC_USERNAME: Username for Basic Auth
30+
- REST_BASIC_PASSWORD: Password for Basic Auth
31+
- Usage: When both are set, requests will include Basic Auth header
32+
33+
### Bearer Token
34+
- REST_BEARER: Bearer token value
35+
- Usage: When set, requests will include `Authorization: Bearer <token>` header
36+
37+
### API Key
38+
- REST_APIKEY_HEADER_NAME: Name of the header for API key
39+
- REST_APIKEY_VALUE: Value of the API key
40+
- Example:
41+
```
42+
REST_APIKEY_HEADER_NAME=X-API-Key
43+
REST_APIKEY_VALUE=your-api-key-here
44+
```
45+
- Usage: When both are set, requests will include the specified header with the API key
46+
47+
## Configuration Examples
48+
49+
### Local Development
50+
```bash
51+
REST_BASE_URL=http://localhost:3000
52+
REST_ENABLE_SSL_VERIFY=false
53+
REST_RESPONSE_SIZE_LIMIT=50000
54+
```
55+
56+
### Production API with Bearer Token
57+
```bash
58+
REST_BASE_URL=https://api.example.com
59+
REST_BEARER=your-bearer-token
60+
```
61+
62+
### API with Basic Auth
63+
```bash
64+
REST_BASE_URL=https://api.example.com
65+
REST_BASIC_USERNAME=admin
66+
REST_BASIC_PASSWORD=secret
67+
```
68+
69+
### API with API Key
70+
```bash
71+
REST_BASE_URL=https://api.example.com
72+
REST_APIKEY_HEADER_NAME=X-API-Key
73+
REST_APIKEY_VALUE=your-api-key
74+
```
75+
76+
## Changing Configuration
77+
78+
Configuration can be updated by:
79+
1. Setting environment variables before starting the server
80+
2. Modifying the MCP server configuration file
81+
3. Using environment variable commands in your terminal
82+
83+
Remember to restart the server after changing configuration for the changes to take effect.

src/resources/examples.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
# REST API Testing Examples
22

3+
⚠️ IMPORTANT: Only provide the endpoint path - do not include full URLs. Your path will be automatically resolved to the full URL.
4+
5+
For example, if the base URL is `http://localhost:3000`:
6+
✅ Correct: `"/api/users"` → Resolves to: `http://localhost:3000/api/users`
7+
❌ Incorrect: `"http://localhost:3000/api/users"` or `"www.example.com/api/users"`
8+
39
## Basic GET Request
410
```typescript
511
use_mcp_tool('rest-api', 'test_request', {
612
"method": "GET",
7-
"endpoint": "/users"
13+
"endpoint": "/users" // Will be appended to REST_BASE_URL
814
});
915
```
1016

@@ -58,3 +64,17 @@ use_mcp_tool('rest-api', 'test_request', {
5864
"method": "DELETE",
5965
"endpoint": "/users/123"
6066
});
67+
```
68+
69+
## Changing Base URL
70+
If you need to test against a different base URL, update the base URL configuration rather than including the full URL in the endpoint parameter.
71+
72+
Example:
73+
```bash
74+
# Instead of this:
75+
"endpoint": "https://api.example.com/users" # Wrong - don't include the full URL
76+
77+
# Do this:
78+
# 1. Update the base URL configuration to: https://api.example.com
79+
# 2. Then use just the path:
80+
"endpoint": "/users" # This will resolve to: https://api.example.com/users

0 commit comments

Comments
 (0)