-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy path.windsurfrules
More file actions
229 lines (163 loc) · 5.6 KB
/
.windsurfrules
File metadata and controls
229 lines (163 loc) · 5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# Cursor Rules for MCP Tool Generation
## Tool Definition Guidelines
1. **Use the @mcp.tool() decorator**
- All tools must be defined using the `@mcp.tool()` decorator
- This properly registers the function as an MCP tool
- Include proper type hints for parameters and return values
2. **Methods must be async**
- All tool methods should be defined as async functions
- Use `async def` for all tool definitions
- Use appropriate async libraries and patterns (e.g., httpx.AsyncClient instead of requests)
3. **Include descriptive docstrings**
- Each tool must have a clear, descriptive docstring
- Docstrings should explain what the tool does and describe parameters
## Examples of correct tool implementations:
```python
@mcp.tool()
async def calculate_bmi(weight_kg: float, height_m: float) -> float:
"""Calculate BMI given weight in kg and height in meters"""
return weight_kg / (height_m**2)
@mcp.tool()
async def fetch_weather(city: str) -> str:
"""Fetch current weather for a city"""
async with httpx.AsyncClient() as client:
response = await client.get(f"https://api.weather.com/{city}")
return response.text
```
## Common Mistakes to Avoid
1. **Don't use synchronous functions**
- Incorrect: `def my_tool():`
- Correct: `async def my_tool():`
2. **Don't forget the decorator**
- Incorrect: `async def my_tool():`
- Correct: `@mcp.tool()\nasync def my_tool():`
3. **Don't use blocking HTTP libraries**
- Incorrect: `requests.get(...)`
- Correct: `async with httpx.AsyncClient() as client: await client.get(...)`
---
title: "Don't use uvicorn or fastapi with MCP"
description: "MCP has native server capabilities, external web servers are not needed"
severity: warning
---
# Don't use uvicorn or fastapi with MCP/FastMCP
## Rule Details
MCP and FastMCP have their own server implementations that can run directly without external web servers like uvicorn or fastapi.
### ❌ Incorrect
```python
# Incorrect: Using uvicorn with MCP
import uvicorn
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("MyServer")
if __name__ == "__main__":
uvicorn.run(mcp.app, host="0.0.0.0", port=8000) # Wrong
```
### ✅ Correct
```python
# Correct: Using MCP's native run method
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("MyServer")
if __name__ == "__main__":
mcp.run() # Correct
```
## Implementation Details
This rule enforces:
- Not using uvicorn or fastapi with MCP servers
- Using the native `mcp.run()` method instead
- Not adding unnecessary web server dependencies
## Dependencies
When working with MCP and Python 3.13, avoid unnecessary dependencies:
- For basic MCP implementation, only `mcp` or `fastmcp` and possibly `requests` are needed
- Do not include web server packages unnecessarily
- Take advantage of Python 3.13's built-in typing features (using `list[str]` instead of `List[str]`)
## Configuration in pyproject.toml
```toml
[project]
requires-python = ">=3.13"
dependencies = [
"mcp>=0.2.0",
"requests>=2.28.0",
# No uvicorn or fastapi
]
```
## Import fastmcp from mcp
**FastMCP imports must use the correct package path**
- All imports concerning FastMCP must be done under `mcp.server.fastmcp`
- Example: `from mcp.server.fastmcp import FastMCP` instead of direct imports
---
title: "Use pyproject.toml with uv instead of requirements.txt"
description: "Modern Python projects should use pyproject.toml with uv for dependency management"
severity: warning
---
# Use pyproject.toml with uv instead of requirements.txt
## Rule Details
This project uses pyproject.toml for dependency management with uv, not requirements.txt.
### ❌ Incorrect
Using requirements.txt:
```
requests>=2.28.0
mcp>=0.2.0
fastapi>=0.68.0 # Unnecessary
uvicorn>=0.15.0 # Unnecessary
```
Or incorrect installation:
```bash
pip install -r requirements.txt
```
### ✅ Correct
Using pyproject.toml:
```toml
[project]
name = "my-mcp-server"
version = "0.1.0"
description = "My MCP server"
requires-python = ">=3.13"
dependencies = [
"mcp>=0.2.0",
"requests>=2.28.0",
]
[project.optional-dependencies]
dev = [
"pytest>=7.0.0",
"ruff>=0.0.272",
]
```
With correct installation:
```bash
uv sync
# or with dev dependencies
uv sync --with dev
```
## Implementation Details
This rule enforces:
- Using pyproject.toml for dependency management
- Using uv for package installation
- Properly specifying dependencies with version constraints
- Not creating or using requirements.txt
- Specifying Python 3.13 as the minimum required version
## Python 3.13 Features
Take advantage of Python 3.13's modern features:
- Use built-in type annotations (`dict[str, Any]` instead of importing `Dict` from typing)
- Use the pipe operator for union types (`str | None` instead of `Optional[str]`)
- Remove unnecessary typing imports as many are now in the standard builtins
## Benefits
- Faster dependency resolution with uv
- Better project metadata with pyproject.toml
- Cleaner separation of development dependencies
- More standardized approach to modern Python packaging
- Ability to leverage the latest Python 3.13 features
## Base directory
- Ensure all code is placed within the `src/gg_api_mcp_server` directory
- Handle imports accordingly by using the appropriate package path
- the main file is `src/gg_api_mcp_server/server.py`
## HTTP request client
Use httpx to make all HTTP requests
## Typing
- use python typing for python > 3.12
- use direct python type instead of importing from typing.
### ❌ Incorrect
from typing import Dict, List
def my_func(my_dict: Dict, my_list: List):
...
### ✅ Correct
def my_func(my_dict: dict, my_list: list):
...