Skip to content

Commit 2fcde75

Browse files
docs: cursor rules for tool generation from docs (#8)
* docs: README.md for tools * docs: fix tools docs * docs: updated README.md for tool UTs * docs: tool generator cursor rule * docs: shortening the cursor rule * docs: cursor rule to perform lint checks * docs: prompt changes * docs: prompt changes * docs: prompt changes * docs: common issues to rules * docs: rules * docs: rules * docs: rules * docs: cursor rule change * docs: cursor rule change * docs: cursor rule change * docs: cursor rule, adding package finder * docs: cursor rule changes * docs: cursor rule changes * docs: cursor rule changes * docs: cursor rule changes after review * docs: typo fix
1 parent 2e52d62 commit 2fcde75

File tree

5 files changed

+667
-11
lines changed

5 files changed

+667
-11
lines changed

.cursor/rules/new-tool-from-docs.mdc

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
7+
# Razorpay Tool Generator
8+
9+
This rule generates tool implementations for the Razorpay MCP server based on API documentation.
10+
11+
## Required Format
12+
13+
This rule requires:
14+
15+
1. A Razorpay API documentation URL starting with `https://razorpay.com/docs/api/`
16+
2. The SDK function signature that the tool will call
17+
18+
Example of valid invocation:
19+
```
20+
@new-tool-from-docs.mdc DOC_LINK: @https://razorpay.com/docs/api/payment-links/create-standard/
21+
SDK_FUNCTION:
22+
func (pl *PaymentLink) Create(data map[string]interface{}, extraHeaders map[string]string) (map[string]interface{}, error) {
23+
url := fmt.Sprintf("/%s%s", constants.VERSION_V1, constants.PaymentLink_URL)
24+
return pl.Request.Post(url, data, extraHeaders)
25+
}
26+
```
27+
28+
IMPORTANT: If the DOC_LINK or SDK_FUNCTION are missing or in an incorrect format, REFUSE to proceed further.
29+
30+
## Implementation Checklist
31+
32+
This checklist **MUST** be included in the final response to verify all implementation steps are complete.
33+
IMPORTANT: Include this unchecked checklist at the END of the implementation, NOT at the beginning.
34+
35+
- [ ] Implement tool function based on API docs
36+
- [ ] Register tool in tools.go
37+
- [ ] Create unit tests with full coverage (positive case, all negative cases, edge cases)
38+
- [ ] Update the "Available Tools" section in the main README.md. Make sure the new additions are correctly formatted.
39+
- [ ] Double check that we are not repeating any of the Common Issues mentioned below.
40+
- [ ] Run linter and fix errors if any (REQUIRED)
41+
- [ ] Run tests and fix errors if any (REQUIRED)
42+
43+
COMPLETION CRITERIA:
44+
1. The task is considered accomplished only if the checklist and summary are posted.
45+
2. Once the task is completed you should stop and give control to the user. You SHOULD NOT infer additional tools to implement.
46+
47+
## ⚠️ IMMEDIATE ACTION REQUIRED ⚠️
48+
49+
Upon receiving this rule invocation:
50+
51+
1. **DO NOT** ask for user input or confirmation before implementing code
52+
2. **DO** use the `edit_file` tool to create/modify the following files:
53+
- Primary implementation: `pkg/razorpay/{resource_type}.go`
54+
- Test implementation: `pkg/razorpay/{resource_type}_test.go`
55+
- Update toolset registration: `pkg/razorpay/tools.go`
56+
- Update the README.md
57+
58+
## Implementation
59+
60+
Before the implementation use the documentation URL provided to figure out the request contract, required parameters, descriptions of the parameters, and the response contract.
61+
62+
Now follow the detailed implementation guide in [pkg/razorpay/README.md](../pkg/razorpay/README.md) for creating tools and start making code changes.
63+
64+
Other guidelines:
65+
1. [Razorpay Go SDK Constants](https://github.com/razorpay/razorpay-go/blob/master/constants/url.go) - Use these constants for specifying the api endpoints while writing the tests.
66+
2. Use the payload and response from the docs provided to write the positive test case for the tool.
67+
68+
STYLE:
69+
Look at the linters and linter settings in the .golangci.yaml file and make sure to follow the same style while coding.
70+
71+
IMPORTANT: You **MUST** ALWAYS go through the Post Implementation steps once the code changes are done.
72+
73+
## Implementation References
74+
75+
For detailed code patterns and examples, refer to the following sections in the [pkg/razorpay/README.md](../pkg/razorpay/README.md):
76+
77+
- **Tool Structure**: See the "Tool Structure" section for the function template
78+
- **Parameter Definition**: See the "Parameter Definition" section for defining parameters
79+
- **Parameter Validation**: See the "Parameter Validation" section for validation examples
80+
- **Example GET/POST Endpoints**: See the example sections for complete implementation patterns
81+
- **Unit Testing**: See the "Writing Unit Tests" section for test patterns and best practices
82+
83+
## ⚠️ Common Issues & Troubleshooting ⚠️
84+
85+
### 1. Query Parameters in Mock Tests
86+
87+
The `mock.Endpoint` struct does NOT have a queryParams field:
88+
89+
```go
90+
type Endpoint struct {
91+
Path string
92+
Method string
93+
Response interface{}
94+
}
95+
```
96+
97+
### 1. Query Parameter Limitations in Mock Tests
98+
99+
The mock server doesn't validate query parameters. When testing endpoints with query parameters:
100+
101+
```go
102+
// DOESN'T WORK - Gorilla Mux treats this as a literal path ❌
103+
mock.Endpoint{
104+
Path: apiPath + "?count=2&from=123&skip=1",
105+
Method: "GET",
106+
Response: successResponse,
107+
}
108+
109+
// WORKS - Use only the base path ✅
110+
mock.Endpoint{
111+
Path: apiPath, // Only the base path without query parameters
112+
Method: "GET",
113+
Response: successResponse,
114+
}
115+
```
116+
117+
### 2. Line Length Linter Errors
118+
119+
When encountering line length errors ("The line is X characters long, which exceeds the maximum of Y characters"):
120+
121+
1. Option 1: Add `//nolint:lll` comment at the end of the line:
122+
```go
123+
return mcpgo.NewTool(
124+
"tool_name",
125+
"This is a very long description that exceeds the line length limit", //nolint:lll
126+
parameters,
127+
handler,
128+
)
129+
```
130+
131+
2. Option 2: Break the string into multiple concatenated lines:
132+
```go
133+
return mcpgo.NewTool(
134+
"tool_name",
135+
"This is a very long description " +
136+
"that exceeds the line length limit",
137+
parameters,
138+
handler,
139+
)
140+
```
141+
142+
3. Option 3: For comments, split into multiple comment lines:
143+
```go
144+
// This is a very long comment that would exceed the line length limit
145+
// so it's split into multiple lines.
146+
func ToolName() {}
147+
```
148+
149+
### 3. Missing Steps in the Implementation Checklist
150+
151+
IMPORTANT: The Implementation Checklist MUST be complete before submitting. Pay particular attention to these required steps:
152+
153+
- [ ] Run linter and fix errors if any (REQUIRED)
154+
- [ ] Run tests and fix errors if any (REQUIRED)
155+
156+
If any checklist items remain unchecked, complete them before proceeding. The implementation is considered incomplete until all required steps are addressed.
157+
158+
## Test Coverage Requirements
159+
160+
Your tests MUST include:
161+
- Positive test case with all parameters
162+
- Negative test case for EACH required parameter
163+
- Negative test case for validation failures (e.g., wrong types)
164+
- Any edge cases specific to this tool
165+
166+
## ⚠️ Required Verification Steps ⚠️
167+
168+
After implementing code changes, ALWAYS perform these verification steps:
169+
170+
1. You **MUST** run the linter to ensure code quality:
171+
```
172+
run_terminal_cmd golangci-lint run
173+
```
174+
Fix any issues reported by the linter. Try at least two iterations of fixes for the errors before giving up.
175+
176+
2. You **MUST** run tests to verify functionality:
177+
```
178+
run_terminal_cmd go test ./...
179+
```
180+
Ensure all tests pass. If any tests fail, investigate the failures and fix the issues. Try at least two iterations of fixes for the errors before giving up.
181+
182+
## Key Packages and Functionality
183+
184+
Use this section as a reference for the key packages incase you get lost.
185+
186+
### `pkg/razorpay` - Main Implementation Package
187+
188+
**Path:** `pkg/razorpay/`
189+
190+
Contains all Razorpay API tool implementations, including:
191+
- Tool function definitions (by resource type)
192+
- Parameter validation functions
193+
- Request/response handling
194+
195+
### `pkg/razorpay/server.go` - Core Utilities
196+
197+
**Path:** `pkg/razorpay/server.go`
198+
199+
Contains essential utility functions used by all tools:
200+
- `RequiredParam[T]` - Type-safe required parameter extraction
201+
- `OptionalParam[T]` - Type-safe optional parameter extraction
202+
- `RequiredInt` - Integer parameter extraction
203+
- `OptionalInt` - Optional integer parameter extraction
204+
- `HandleValidationError` - Common validation error handling
205+
206+
### `pkg/razorpay/test_helpers.go` - Testing Utilities
207+
208+
**Path:** `pkg/razorpay/test_helpers.go`
209+
210+
Contains testing utilities used for unit tests:
211+
- `RazorpayToolTestCase` - Test case structure
212+
- `runToolTest` - Test execution function
213+
- Mock client setup functions
214+
215+
### `pkg/razorpay/tools.go` - Tool Registration
216+
217+
**Path:** `pkg/razorpay/tools.go`
218+
219+
Contains the toolset registration system:
220+
- `NewToolSets` function
221+
- Toolset definitions and organization
222+
- Tool grouping by resource type
223+
224+
### `pkg/razorpay/mock` - HTTP Mocking
225+
226+
**Path:** `pkg/razorpay/mock/`
227+
228+
Contains HTTP mocking utilities for testing:
229+
- `NewHTTPClient` - Creates mock HTTP clients
230+
- `Endpoint` - Mock endpoint definition
231+
232+
### `pkg/mcpgo` - MCP Protocol Package
233+
234+
**Path:** `pkg/mcpgo/`
235+
236+
Contains the Model Context Protocol implementation:
237+
- `Tool` interface definition
238+
- `ToolParameter` types
239+
- Response handling utilities (`NewToolResultJSON`, etc.)
240+
241+
### `github.com/razorpay/razorpay-go` - Razorpay Go SDK
242+
243+
**Imported as:** `rzpsdk "github.com/razorpay/razorpay-go"`
244+
245+
Official Razorpay client library providing:
246+
- `Client` struct with resource-specific clients (Payment, Order, PaymentLink, etc.)
247+
- API methods that map to Razorpay REST endpoints
248+
- Constants for API URLs (`constants` package)
249+
- Request/response handling

CONTRIBUTING.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,18 @@ When adding new features or modifying existing ones, please update the documenta
149149

150150
When adding a new tool to the Razorpay MCP Server:
151151

152-
1. Create a new file in the appropriate package under `pkg/razorpay`.
153-
2. Implement the tool functionality.
154-
3. Register the tool in the server.
155-
4. Add appropriate tests.
156-
5. Update documentation to include the new tool.
152+
1. Review the detailed developer guide at [pkg/razorpay/README.md](pkg/razorpay/README.md) for complete instructions and examples.
153+
2. Create a new function in the appropriate resource file under `pkg/razorpay` (or create a new file if needed).
154+
3. Implement the tool following the patterns in the developer guide.
155+
4. Register the tool in `server.go`.
156+
5. Add appropriate tests.
157+
6. Update the main README.md to document the new tool.
158+
159+
The developer guide for tools includes:
160+
- Tool structure and patterns
161+
- Parameter definition and validation
162+
- Examples for both GET and POST endpoints
163+
- Best practices for naming and organization
157164

158165
## Releasing
159166

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Currently, the Razorpay MCP Server provides the following tools:
88

99
| Tool | Description |
1010
|-----------------------|---------------------------------------|
11-
| `payment.fetch` | Fetch payment details |
12-
| `payment_link.create` | Creates a new payment link |
13-
| `payment_link.fetch` | Fetch details of a payment link |
14-
| `order.create` | Creates an order |
15-
| `order.fetch` | Fetch order details |
11+
| `fetch_payment` | Fetch payment details |
12+
| `create_payment_link` | Creates a new payment link |
13+
| `fetch_payment_link` | Fetch details of a payment link |
14+
| `create_order` | Creates an order |
15+
| `fetch_order` | Fetch order details |
1616

1717

1818
## Use Cases

0 commit comments

Comments
 (0)