Skip to content

Commit 97bf213

Browse files
authored
Merge pull request #14 from sulthonuladib/feature/patch-http-method
feat: add patch http method
2 parents 9c81e5a + 9d35a05 commit 97bf213

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ The `test_request` tool enables testing, debugging, and interacting with REST AP
4747

4848
## Key Features
4949

50-
- Supports GET, POST, PUT, DELETE methods
50+
- Supports GET, POST, PUT, DELETE, PATCH methods
5151
- Handles authentication (Basic, Bearer, API Key)
5252
- Normalizes endpoints automatically
5353
- Provides detailed response information
@@ -152,7 +152,7 @@ Note: Replace the environment variables with your actual values. Only configure
152152
## Features
153153

154154
- Test REST API endpoints with different HTTP methods
155-
- Support for GET, POST, PUT, and DELETE requests
155+
- Support for GET, POST, PUT, DELETE, and PATCH requests
156156
- Detailed response information including status, headers, and body
157157
- Custom Headers:
158158
- Global headers via HEADER_* environment variables

src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const AUTH_APIKEY_VALUE = process.env.AUTH_APIKEY_VALUE;
3232
const REST_ENABLE_SSL_VERIFY = process.env.REST_ENABLE_SSL_VERIFY !== 'false';
3333

3434
interface EndpointArgs {
35-
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
35+
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
3636
endpoint: string;
3737
body?: any;
3838
headers?: Record<string, string>;
@@ -120,7 +120,7 @@ const normalizeBaseUrl = (url: string): string => url.replace(/\/+$/, '');
120120

121121
const isValidEndpointArgs = (args: any): args is EndpointArgs => {
122122
if (typeof args !== 'object' || args === null) return false;
123-
if (!['GET', 'POST', 'PUT', 'DELETE'].includes(args.method)) return false;
123+
if (!['GET', 'POST', 'PUT', 'DELETE', 'PATCH'].includes(args.method)) return false;
124124
if (typeof args.endpoint !== 'string') return false;
125125
if (args.headers !== undefined && (typeof args.headers !== 'object' || args.headers === null)) return false;
126126

@@ -329,7 +329,7 @@ class RestTester {
329329
properties: {
330330
method: {
331331
type: 'string',
332-
enum: ['GET', 'POST', 'PUT', 'DELETE'],
332+
enum: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
333333
description: 'HTTP method to use',
334334
},
335335
endpoint: {
@@ -380,8 +380,8 @@ class RestTester {
380380
headers: {},
381381
};
382382

383-
// Add request body for POST/PUT
384-
if (['POST', 'PUT'].includes(request.params.arguments.method) && request.params.arguments.body) {
383+
// Add request body for POST/PUT/PATCH
384+
if (['POST', 'PUT', 'PATCH'].includes(request.params.arguments.method) && request.params.arguments.body) {
385385
config.data = request.params.arguments.body;
386386
}
387387

src/resources/examples.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ use_mcp_tool('rest-api', 'test_request', {
7171
});
7272
```
7373

74+
## PATCH Request Example
75+
```typescript
76+
use_mcp_tool('rest-api', 'test_request', {
77+
"method": "PATCH",
78+
"endpoint": "/users/123",
79+
"body": {
80+
"status": "active"
81+
}
82+
});
83+
```
84+
7485
## Using the Optional `host` Argument
7586
You can override the default base URL for a single request by providing a `host` argument. This must be a valid URL starting with `http://` or `https://`, and may include a path (trailing slashes will be removed).
7687

0 commit comments

Comments
 (0)