unifi-mcp-server / rules
Cursor rule294 starsChanged 18 days agoApache-2.0View on GitHub
MCP tool implementation pattern and structure
We split this mcp-tools.mdc into the rules it gives an agent
4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 9
Every MCP tool should follow this structure:
- Very specific: line 89
Use @mcp.tool() decorator for tool definitions
- Very specific: line 90
Use @mcp.resource() decorator for resource endpoints
- Very specific: line 91
Always include site_id for multi-site support
≈ “Common” is an estimate: at least 1 in 5 of the 6,350 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.
Files
---
description: MCP tool implementation pattern and structure
globs: ["src/tools/**/*.py"]
alwaysApply: true
---
# MCP Tool Implementation Pattern
Every MCP tool should follow this structure:
```python
from typing import Optional, Literal
from pydantic import BaseModel, Field
from fastmcp import FastMCP
mcp = FastMCP("UniFi MCP Server")
@mcp.tool()
async def tool_name(
# Required parameters first
site_id: str,
resource_id: str,
# Optional parameters with defaults
optional_param: Optional[str] = None,
# Safety parameters for mutating operations
confirm: bool = False,
dry_run: bool = False
) -> dict:
"""
Clear, concise description of what the tool does.
Args:
site_id: Always include site_id for multi-site support
resource_id: Specific resource identifier
optional_param: Description of optional parameter
confirm: REQUIRED True for mutating operations (safety)
dry_run: Preview changes without applying them
Returns:
Dictionary with operation results. Specify structure.
Raises:
MCPError: For all MCP-specific errors
ValueError: For invalid inputs
UniFiConnectionError: For API connection issues
"""
# 1. Input validation
if not site_id:
raise ValueError("site_id is required")
# 2. Safety checks for mutating operations
if not confirm and not dry_run:
raise MCPError("This operation requires confirm=True")
# 3. Audit logging
logger.info(
f"tool_name: site={site_id}, id={resource_id}, dry_run={dry_run}",
extra={"operation": "tool_name", "site_id": site_id}
)
# 4. Dry-run mode
if dry_run:
preview = await generate_preview(site_id, resource_id)
return {"status": "preview", "changes": preview}
# 5. Execute operation
try:
result = await execute_operation(site_id, resource_id)
except UniFiAPIError as e:
logger.error(f"Operation failed: {e}")
raise MCPError(f"Failed to execute operation: {str(e)}")
# 6. Cache invalidation (if applicable)
if result.get("success"):
await cache.invalidate(f"resource:{site_id}")
# 7. Return structured result
return {
"status": "success",
"resource_id": resource_id,
"data": result
}
```
## MCP-Specific Guidelines
- Use `@mcp.tool()` decorator for tool definitions
- Use `@mcp.resource()` decorator for resource endpoints
- Always include `site_id` for multi-site support
- Implement proper error handling with custom exceptions
- Return structured dictionaries for consistency
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 3,978 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository52 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .agents/skills/fastmcp/CLAUDE.mdCLAUDE.md
- CLAUDE.mdCLAUDE.md
- .claude/skills/fastmcp/CLAUDE.mdCLAUDE.md
- .cursor/rules/common-mistakes.mdcCursor rule
- .cursor/rules/core-principles.mdcCursor rule
- .cursor/rules/environment-setup.mdcCursor rule
- .cursor/rules/project-context.mdcCursor rule
- .cursor/rules/README.mdCursor rule
- .cursor/rules/unifi-api.mdcCursor rule
- .cursor/rules/workflow.mdcCursor rule
- FastMCP DevelopmentSkill
- mcp-builderSkill
- source-command-build-dockerSkill
- source-command-check-depsSkill
- source-command-cleanSkill
- source-command-docsSkill
- source-command-formatSkill
- source-command-lintSkill
- source-command-prSkill
- source-command-securitySkill
- source-command-setupSkill
- source-command-testSkill
- source-command-unifi-api-docs-update-2Skill
- source-command-unifi-api-docs-updateSkill
- source-command-unifi-mcp-add-toolSkill
- source-command-unifi-mcp-release-prepSkill
- source-command-unifi-mcp-test-coverageSkill
- source-command-unifi-mcp-update-docsSkill
- unifi-cloud-fleet-toolsSkill
- unifi-mcp-tool-builderSkill
- unifi-network-config-toolsSkill
- unifi-protect-toolsSkill
- unifi-security-toolsSkill
- FastMCP DevelopmentSkill
- mcp-builderSkill
- unifi-cloud-fleet-toolsSkill
- unifi-mcp-tool-builderSkill
- unifi-network-config-toolsSkill
- unifi-protect-toolsSkill
- unifi-security-toolsSkill
- unifiSkill
- unifi-channel-planningSkill
- unifi-cloud-fleet-toolsSkill
- unifi-devicesSkill
- unifi-mcp-tool-builderSkill
- unifi-network-config-toolsSkill
- unifi-networkSkill
- unifi-protect-toolsSkill
- unifi-securitySkill
- unifi-security-toolsSkill
- unifi-systemSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
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.

