agentleFS
skywinderskywinder/osm-edit-mcp/.cursor/rules/osm-development-safety.mdc

osm-edit-mcp / rules

Cursor rule4 starsChanged 3 months agoMITView on GitHub

NEVER perform these operations without explicit user confirmation: The server.py OSMConfig class automatically selects the correct API based on OSM_USE_DEV_API setting.

  • Reads credentials

The file

Show its rules and text

We split this osm-development-safety.mdc into the rules it gives an agent

22 rules. About 0 are common, 16 are distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈16

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    Always use development API for testing: OSM_USE_DEV_API=true in .env

    line 20
  2. Distinctive:

    Never commit real OAuth credentials to version control

    line 22
  3. Very specific:

    Run test_comprehensive.py before any changes

    line 45
  4. Distinctive:

    Write operations will fail without OAuth (this is expected and safe)

    line 47
  5. Very specific:

    Follow TESTING_CHECKLIST.md systematically

    line 50
  6. Distinctive:

    Start with read operations (safe)

    line 51
  7. Distinctive:

    Test configuration switching (dev/prod)

    line 52
  8. Distinctive:

    Never test write operations on production without user consent

    line 54
  9. Very specific:

    All tools in server.py that only retrieve data:

    line 59
  10. Distinctive:

    All tools should return structured responses:

    line 71
  11. Distinctive:

    Always validate coordinates before API calls

    line 89
  12. Distinctive:

    Never log OAuth tokens or credentials

    line 103
  13. Very specific:

    Use system keyring when USE_KEYRING=true

    line 105
  14. Distinctive:

    Never commit credentials to version control

    line 114
  15. Distinctive:

    Read operations work without authentication

    line 117
  16. Distinctive:

    Write operations will return 401 Unauthorized (expected)

    line 118
  17. Very specific:

    Use test_comprehensive.py to validate this behavior

    line 119
  18. Distinctive:

    Always validate before API calls

    line 126
  19. Distinctive:

    Check required tags for element types

    line 129
  20. Distinctive:

    Follow OSM tagging conventions

    line 131
  21. Distinctive:

    Always include meaningful changeset comments

    line 134
  22. Distinctive:

    Add source and created_by tags

    line 135

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
osm-development-safety.mdc
---
description:
globs:
alwaysApply: true
---
# OSM Development Safety and Best Practices

## ⚠️ CRITICAL: Always Ask Before Irreversible Operations

**NEVER perform these operations without explicit user confirmation:**

### OpenStreetMap Write Operations
- Creating or closing changesets via OSM API
- Uploading nodes, ways, or relations to OSM
- Modifying existing OSM map data
- Deleting OSM elements
- Any calls to production `api.openstreetmap.org` endpoints

### Configuration Safety
- Always use development API for testing: `OSM_USE_DEV_API=true` in [.env](mdc:.env)
- Production API requires extreme caution: `OSM_USE_DEV_API=false`
- Never commit real OAuth credentials to version control

## Development API Configuration

### Safe Development Setup
```bash
# In .env file - ALWAYS use for development
OSM_USE_DEV_API=true
OSM_DEV_API_BASE=https://api06.dev.openstreetmap.org/api/0.6
```

### Production API (Use with Extreme Caution)
```bash
# Only for production deployments
OSM_USE_DEV_API=false
OSM_API_BASE=https://api.openstreetmap.org/api/0.6
```

The [server.py](mdc:src/osm_edit_mcp/server.py) `OSMConfig` class automatically selects the correct API based on `OSM_USE_DEV_API` setting.

## Testing Guidelines

### Automated Testing
- Run [test_comprehensive.py](mdc:test_comprehensive.py) before any changes
- Expected results documented in [TEST_RESULTS_SUMMARY.md](mdc:TEST_RESULTS_SUMMARY.md)
- Write operations will fail without OAuth (this is expected and safe)

### Manual Testing Process
1. Follow [TESTING_CHECKLIST.md](mdc:TESTING_CHECKLIST.md) systematically
2. Start with read operations (safe)
3. Test configuration switching (dev/prod)
4. Validate error handling
5. Never test write operations on production without user consent

## MCP Tool Implementation Patterns

### Read Operations (Safe)
All tools in [server.py](mdc:src/osm_edit_mcp/server.py) that only retrieve data:
- `get_osm_node`, `get_osm_way`, `get_osm_relation`
- `find_nearby_amenities`, `validate_coordinates`
- `get_place_info`, `search_osm_elements`

### Write Operations (Require OAuth + Confirmation)
Tools that modify OSM data:
- `create_osm_node`, `update_osm_node`, `delete_osm_node`
- `create_osm_way`, `update_osm_way`, `delete_osm_way`
- `create_changeset`, `close_changeset`

### Error Handling Pattern
All tools should return structured responses:
```python
{
    "success": True/False,
    "data": {...},          # On success
    "error": "...",         # On failure
    "message": "..."        # Human-readable message
}
```

## Rate Limiting and API Etiquette

### OSM API Limits
- Maximum 10,000 API calls per hour per IP
- Configured in [.env](mdc:.env): `RATE_LIMIT_PER_MINUTE=60`
- Respect changeset size limits: `MAX_CHANGESET_SIZE=50`

### Best Practices
- Always validate coordinates before API calls
- Cache read responses when appropriate
- Handle 429 rate limit responses gracefully
- Log all API operations (excluding auth tokens)

## Logging and Debugging

### Log Levels (configured in [.env](mdc:.env))
- `LOG_LEVEL=DEBUG` - Full debugging for development
- `LOG_LEVEL=INFO` - Standard operation
- `LOG_LEVEL=WARNING` - Important events only
- `LOG_LEVEL=ERROR` - Errors only

### Security Considerations
- Never log OAuth tokens or credentials
- Store credentials in [.env](mdc:.env) only (not committed)
- Use system keyring when `USE_KEYRING=true`
- Validate all input data before processing

## Authentication Flow

### OAuth 2.0 Setup
1. Register application at https://www.openstreetmap.org/oauth2/applications
2. Configure scopes: `read_prefs`, `write_prefs`, `write_api`, `write_changeset_comments`
3. Store credentials in [.env](mdc:.env)
4. Never commit credentials to version control

### Development Without OAuth
- Read operations work without authentication
- Write operations will return 401 Unauthorized (expected)
- Use [test_comprehensive.py](mdc:test_comprehensive.py) to validate this behavior

## Data Validation Requirements

### Coordinate Validation
- Latitude: -90 to 90 degrees
- Longitude: -180 to 180 degrees
- Always validate before API calls

### Tag Validation
- Check required tags for element types
- Validate tag key/value formats
- Follow OSM tagging conventions

### Changeset Management
- Always include meaningful changeset comments
- Add source and created_by tags
- Close changesets when editing is complete

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.